-
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.
feat: add endless recursion as an impurity reason (#788)
### Summary of Changes Endless recursion is now included in the inferred impurity reasons of an expression/callable.
- Loading branch information
1 parent
6f45dc4
commit 98acdde
Showing
29 changed files
with
237 additions
and
305 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
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
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
45 changes: 3 additions & 42 deletions
45
packages/safe-ds-lang/src/language/validation/other/statements/statements.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,18 @@ | ||
import { | ||
isSdsAssignment, | ||
isSdsExpressionStatement, | ||
isSdsWildcard, | ||
SdsExpression, | ||
SdsStatement, | ||
} from '../../../generated/ast.js'; | ||
import { SdsStatement } from '../../../generated/ast.js'; | ||
import { ValidationAcceptor } from 'langium'; | ||
import { SafeDsServices } from '../../../safe-ds-module.js'; | ||
import { getAssignees } from '../../../helpers/nodeProperties.js'; | ||
|
||
export const CODE_STATEMENT_HAS_NO_EFFECT = 'statement/has-no-effect'; | ||
|
||
export const statementMustDoSomething = (services: SafeDsServices) => { | ||
const statementDoesSomething = statementDoesSomethingProvider(services); | ||
const purityComputer = services.purity.PurityComputer; | ||
|
||
return (node: SdsStatement, accept: ValidationAcceptor): void => { | ||
if (!statementDoesSomething(node)) { | ||
if (!purityComputer.statementDoesSomething(node)) { | ||
accept('warning', 'This statement does nothing.', { | ||
node, | ||
code: CODE_STATEMENT_HAS_NO_EFFECT, | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
const statementDoesSomethingProvider = (services: SafeDsServices) => { | ||
const statementExpressionDoesSomething = statementExpressionDoesSomethingProvider(services); | ||
|
||
return (node: SdsStatement): boolean => { | ||
if (isSdsAssignment(node)) { | ||
return !getAssignees(node).every(isSdsWildcard) || statementExpressionDoesSomething(node.expression); | ||
} else if (isSdsExpressionStatement(node)) { | ||
return statementExpressionDoesSomething(node.expression); | ||
} else { | ||
/* c8 ignore next 2 */ | ||
return false; | ||
} | ||
}; | ||
}; | ||
|
||
const statementExpressionDoesSomethingProvider = (services: SafeDsServices) => { | ||
const callGraphComputer = services.flow.CallGraphComputer; | ||
const purityComputer = services.purity.PurityComputer; | ||
|
||
return (node: SdsExpression | undefined): boolean => { | ||
if (!node) { | ||
/* c8 ignore next 2 */ | ||
return false; | ||
} | ||
|
||
return ( | ||
callGraphComputer.getAllContainedCalls(node).some((it) => callGraphComputer.isRecursive(it)) || | ||
!purityComputer.isPureExpression(node) | ||
); | ||
}; | ||
}; |
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
16 changes: 3 additions & 13 deletions
16
packages/safe-ds-lang/tests/language/generation/safe-ds-python-generator.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
7 changes: 1 addition & 6 deletions
7
packages/safe-ds-lang/tests/language/grammar/safe-ds-grammar.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
Oops, something went wrong.