Skip to content

Commit 8d59607

Browse files
authored
feat: minor improvements for purity info (#728)
### Summary of Changes * Allow use of `@Pure` on parameters to indicate that the parameter only accepts pure functions. * Add another reason for impurity: A function calls another function, which may be impure, that is given by a parameter
1 parent 4b8196f commit 8d59607

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package safeds.lang
88
* call. `$this` is replaced by the receiver of the call. `$param` is replaced by the value of the parameter called
99
* `param`. Otherwise, the string is used as-is.
1010
*/
11+
@Experimental
1112
@Target([AnnotationTarget.Function])
1213
annotation PythonCall(
1314
callSpecification: String

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package safeds.lang
22

33
/**
4-
* Indicates that the function has no side effects and always returns the same results given the same arguments.
4+
* **If called on a function:** Indicates that the function has no side effects and always returns the same results
5+
* given the same arguments.
56
*
6-
* Calls to such a function may be eliminated, if the result is not used. Moreover, the function can be memoized, i.e.
7+
* Calls to such a function may be eliminated, if its results are not used. Moreover, the function can be memoized, i.e.
78
* we can remember its results for a set of arguments. Finally, a pure function can be called at any time, allowing
89
* reordering of calls or parallelization.
10+
*
11+
* **If called on a parameter:** Indicates that the parameter only accepts pure callables.
912
*/
1013
@Experimental
11-
@Target([AnnotationTarget.Function])
14+
@Target([AnnotationTarget.Function, AnnotationTarget.Parameter])
1215
annotation Pure
1316

1417
/**
@@ -55,6 +58,13 @@ enum ImpurityReason {
5558
*/
5659
FileWriteToParameterizedPath(parameterName: String)
5760

61+
/**
62+
* The function calls another, potentially impure function that gets passed as a parameter.
63+
*
64+
* @param parameterName The name of the parameter that accepts the function.
65+
*/
66+
PotentiallyImpureParameterCall(parameterName: String)
67+
5868
/**
5969
* The function is impure for some other reason. If possible, use a more specific reason.
6070
*/

0 commit comments

Comments
 (0)