-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…789) Closes #15 ### Summary of Changes Evaluate `and`, `or`, and `?:` if the RHS has no side effects and the LHS determines the result.
- Loading branch information
1 parent
98acdde
commit 9d9f4b7
Showing
10 changed files
with
208 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/safe-ds-lang/tests/language/partialEvaluation/safe-ds-partial-evalutator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...esources/partial evaluation/recursive cases/infix operations/and/short circuiting.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tests.partialValidation.recursiveCases.infixOperations.`and` | ||
|
||
@Pure | ||
fun pureFunction() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileReadFromConstantPath("test.txt")]) | ||
fun functionWithoutSideEffects() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileWriteToConstantPath("test.txt")]) | ||
fun functionWithSideEffects() -> result: Boolean | ||
|
||
pipeline test { | ||
// $TEST$ serialization false | ||
»false and pureFunction()«; | ||
|
||
// $TEST$ serialization false | ||
»false and functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»false and functionWithSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»true and pureFunction()«; | ||
|
||
// $TEST$ serialization ? | ||
»true and functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»true and functionWithSideEffects()«; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ources/partial evaluation/recursive cases/infix operations/elvis/short circuiting.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tests.partialValidation.recursiveCases.infixOperations.elvis | ||
|
||
@Pure | ||
fun pureFunction() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileReadFromConstantPath("test.txt")]) | ||
fun functionWithoutSideEffects() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileWriteToConstantPath("test.txt")]) | ||
fun functionWithSideEffects() -> result: Boolean | ||
|
||
pipeline test { | ||
// $TEST$ serialization 1 | ||
»1 ?: pureFunction()«; | ||
|
||
// $TEST$ serialization 1 | ||
»1 ?: functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»1 ?: functionWithSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»null ?: pureFunction()«; | ||
|
||
// $TEST$ serialization ? | ||
»null ?: functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»null ?: functionWithSideEffects()«; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...resources/partial evaluation/recursive cases/infix operations/or/short circuiting.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tests.partialValidation.recursiveCases.infixOperations.`or` | ||
|
||
@Pure | ||
fun pureFunction() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileReadFromConstantPath("test.txt")]) | ||
fun functionWithoutSideEffects() -> result: Boolean | ||
|
||
@Impure([ImpurityReason.FileWriteToConstantPath("test.txt")]) | ||
fun functionWithSideEffects() -> result: Boolean | ||
|
||
pipeline test { | ||
// $TEST$ serialization true | ||
»true or pureFunction()«; | ||
|
||
// $TEST$ serialization true | ||
»true or functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»true or functionWithSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»false or pureFunction()«; | ||
|
||
// $TEST$ serialization ? | ||
»false or functionWithoutSideEffects()«; | ||
|
||
// $TEST$ serialization ? | ||
»false or functionWithSideEffects()«; | ||
} |
30 changes: 22 additions & 8 deletions
30
...ang/tests/resources/typing/expressions/operations/elvis/non nullable left operand.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
package tests.typing.operations.elvis | ||
package tests.typing.operations.elvis.nonNullableLeftOperand | ||
|
||
fun intOrNull() -> a: Int? | ||
@Pure fun int() -> a: Int | ||
@Pure fun intOrNull() -> a: Int? | ||
|
||
pipeline elvisWithNonNullableLeftOperand { | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1«; | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1 ?: intOrNull()«; | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1 ?: 1«; | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1 ?: 1.0«; | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1 ?: ""«; | ||
// $TEST$ equivalence_class leftOperand | ||
// $TEST$ equivalence_class leftOperand1 | ||
»1 ?: null«; | ||
|
||
// $TEST$ equivalence_class leftOperand2 | ||
»int()«; | ||
// $TEST$ equivalence_class leftOperand2 | ||
»int() ?: intOrNull()«; | ||
// $TEST$ equivalence_class leftOperand2 | ||
»int() ?: 1«; | ||
// $TEST$ equivalence_class leftOperand2 | ||
»int() ?: 1.0«; | ||
// $TEST$ equivalence_class leftOperand2 | ||
»int() ?: ""«; | ||
// $TEST$ equivalence_class leftOperand2 | ||
»int() ?: null«; | ||
} |
6 changes: 3 additions & 3 deletions
6
...ds-lang/tests/resources/typing/expressions/operations/elvis/nullable left operand.sdstest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters