Skip to content

Commit

Permalink
feat: annotations for the purity of functions (#709)
Browse files Browse the repository at this point in the history
Closes #559

### Summary of Changes

Add annotations to denote the purity of functions to the builtin
library.
  • Loading branch information
lars-reimann authored Oct 30, 2023
1 parent 3762c36 commit 9d342e4
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,53 @@ package safeds.lang
@Experimental
@Target([AnnotationTarget.Function])
annotation Pure

/**
* Indicates that the function has side effects and/or does not always return the same results given the same arguments.
*
* @param allReasons
* A list of **all** reasons why the function is impure. If no specific {@link ImpurityReason} applies, include
* `ImpurityReason.Other`.
*/
@Experimental
@Target([AnnotationTarget.Function])
annotation Impure(allReasons: List<ImpurityReason>)

/**
* A reason why a function is impure.
*/
enum ImpurityReason {

/**
* The function reads from a file and the file path is a constant.
*
* @param path The path of the file.
*/
FileReadFromConstantPath(path: String)

/**
* The function reads from a file and the file path is given by a parameter.
*
* @param parameterName The name of the parameter that specifies the file path.
*/
FileReadFromParameterizedPath(parameterName: String)

/**
* The function writes to a file and the file path is a constant.
*
* @param path The path of the file.
*/
FileWriteToConstantPath(path: String)

/**
* The function writes to a file and the file path is given by a parameter.
*
* @param parameterName The name of the parameter that specifies the file path.
*/
FileWriteToParameterizedPath(parameterName: String)

/**
* The function is impure for some other reason. If possible, use a more specific reason.
*/
Other
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { clearDocuments } from 'langium/test';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { NodeFileSystem } from 'langium/node';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { AssertionError } from 'assert';
import { NodeFileSystem } from 'langium/node';
import { createGrammarTests } from './creator.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { EmptyFileSystem } from 'langium';
import { getNodeOfType } from '../../helpers/nodeFinder.js';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../../src/language/index.js';
import { clearDocuments, expectFormatting } from 'langium/test';
import { afterEach, describe, it } from 'vitest';
import { EmptyFileSystem } from 'langium';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { LangiumDocument, Reference, URI } from 'langium';
import { NodeFileSystem } from 'langium/node';
import { clearDocuments, isRangeEqual } from 'langium/test';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../../src/language/index.js';
import { NodeFileSystem } from 'langium/node';
import { clearDocuments } from 'langium/test';
import { AssertionError } from 'assert';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, it } from 'vitest';
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
import { createSafeDsServices } from '../../../src/language/index.js';
import { NodeFileSystem } from 'langium/node';
import { createValidationTests, ExpectedIssue } from './creator.js';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver';
Expand Down

0 comments on commit 9d342e4

Please sign in to comment.