Skip to content

Commit 9d342e4

Browse files
authored
feat: annotations for the purity of functions (#709)
Closes #559 ### Summary of Changes Add annotations to denote the purity of functions to the builtin library.
1 parent 3762c36 commit 9d342e4

File tree

9 files changed

+57
-7
lines changed

9 files changed

+57
-7
lines changed

packages/safe-ds-lang/src/resources/builtins/safeds/lang/purity.sdsstub

+50
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,53 @@ package safeds.lang
1010
@Experimental
1111
@Target([AnnotationTarget.Function])
1212
annotation Pure
13+
14+
/**
15+
* Indicates that the function has side effects and/or does not always return the same results given the same arguments.
16+
*
17+
* @param allReasons
18+
* A list of **all** reasons why the function is impure. If no specific {@link ImpurityReason} applies, include
19+
* `ImpurityReason.Other`.
20+
*/
21+
@Experimental
22+
@Target([AnnotationTarget.Function])
23+
annotation Impure(allReasons: List<ImpurityReason>)
24+
25+
/**
26+
* A reason why a function is impure.
27+
*/
28+
enum ImpurityReason {
29+
30+
/**
31+
* The function reads from a file and the file path is a constant.
32+
*
33+
* @param path The path of the file.
34+
*/
35+
FileReadFromConstantPath(path: String)
36+
37+
/**
38+
* The function reads from a file and the file path is given by a parameter.
39+
*
40+
* @param parameterName The name of the parameter that specifies the file path.
41+
*/
42+
FileReadFromParameterizedPath(parameterName: String)
43+
44+
/**
45+
* The function writes to a file and the file path is a constant.
46+
*
47+
* @param path The path of the file.
48+
*/
49+
FileWriteToConstantPath(path: String)
50+
51+
/**
52+
* The function writes to a file and the file path is given by a parameter.
53+
*
54+
* @param parameterName The name of the parameter that specifies the file path.
55+
*/
56+
FileWriteToParameterizedPath(parameterName: String)
57+
58+
/**
59+
* The function is impure for some other reason. If possible, use a more specific reason.
60+
*/
61+
Other
62+
}

packages/safe-ds-lang/tests/language/generation/testGeneration.test.ts packages/safe-ds-lang/tests/language/generation/safe-ds-python-generator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
1+
import { createSafeDsServices } from '../../../src/language/index.js';
22
import { clearDocuments } from 'langium/test';
33
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
44
import { NodeFileSystem } from 'langium/node';

packages/safe-ds-lang/tests/language/grammar/testGrammar.test.ts packages/safe-ds-lang/tests/language/grammar/safe-ds-grammar.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, describe, it } from 'vitest';
2-
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
2+
import { createSafeDsServices } from '../../../src/language/index.js';
33
import { AssertionError } from 'assert';
44
import { NodeFileSystem } from 'langium/node';
55
import { createGrammarTests } from './creator.js';

packages/safe-ds-lang/tests/language/grammar/safe-ds-value-converter.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
2+
import { createSafeDsServices } from '../../../src/language/index.js';
33
import { EmptyFileSystem } from 'langium';
44
import { getNodeOfType } from '../../helpers/nodeFinder.js';
55
import {

packages/safe-ds-lang/tests/language/lsp/formatting/testFormatting.test.ts packages/safe-ds-lang/tests/language/lsp/formatting/safe-ds-formatter.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js';
1+
import { createSafeDsServices } from '../../../../src/language/index.js';
22
import { clearDocuments, expectFormatting } from 'langium/test';
33
import { afterEach, describe, it } from 'vitest';
44
import { EmptyFileSystem } from 'langium';

packages/safe-ds-lang/tests/language/scoping/testScoping.test.ts packages/safe-ds-lang/tests/language/scoping/scoping.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, it } from 'vitest';
2-
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
2+
import { createSafeDsServices } from '../../../src/language/index.js';
33
import { LangiumDocument, Reference, URI } from 'langium';
44
import { NodeFileSystem } from 'langium/node';
55
import { clearDocuments, isRangeEqual } from 'langium/test';

packages/safe-ds-lang/tests/language/typing/type computer/testTyping.test.ts packages/safe-ds-lang/tests/language/typing/type computer/safe-ds-type-computer.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, it } from 'vitest';
2-
import { createSafeDsServices } from '../../../../src/language/safe-ds-module.js';
2+
import { createSafeDsServices } from '../../../../src/language/index.js';
33
import { NodeFileSystem } from 'langium/node';
44
import { clearDocuments } from 'langium/test';
55
import { AssertionError } from 'assert';

packages/safe-ds-lang/tests/language/validation/testValidation.test.ts packages/safe-ds-lang/tests/language/validation/safe-ds-validator.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, it } from 'vitest';
2-
import { createSafeDsServices } from '../../../src/language/safe-ds-module.js';
2+
import { createSafeDsServices } from '../../../src/language/index.js';
33
import { NodeFileSystem } from 'langium/node';
44
import { createValidationTests, ExpectedIssue } from './creator.js';
55
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver';

0 commit comments

Comments
 (0)