Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: annotations for the purity of functions #709

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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