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: basic implementation of partial evaluator service #649

Merged
merged 20 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4cb916c
refactor: introduce partial evaluator service
lars-reimann Oct 18, 2023
63e40cd
refactor: further improvements to the partial evaluation model
lars-reimann Oct 18, 2023
61ef35c
test: adjust tests to new model
lars-reimann Oct 18, 2023
de589e0
test: partial evaluation of prefix operations
lars-reimann Oct 18, 2023
34a6c2d
test: partial evaluation of parenthesized expressions
lars-reimann Oct 18, 2023
b3cee87
feat: partial evaluation of arguments and lists
lars-reimann Oct 19, 2023
b29cfeb
feat: partial evaluation of enum variants
lars-reimann Oct 19, 2023
c224f97
test: prefix operation with unresolved operand
lars-reimann Oct 19, 2023
19b8f2f
feat: partial evaluation of maps
lars-reimann Oct 19, 2023
39ac765
feat: file icons
lars-reimann Oct 19, 2023
15129c4
feat: partial evaluation of and/or operations
lars-reimann Oct 19, 2023
7af8844
feat: partial evaluation of comparisons
lars-reimann Oct 19, 2023
27d28e8
feat: partial evaluation of arithmetic operations
lars-reimann Oct 19, 2023
c81dd1a
feat: partial evaluation of elvis operations
lars-reimann Oct 19, 2023
842af61
feat: partial evaluation of equality checks
lars-reimann Oct 19, 2023
73d16f1
feat: syntax highlighting for template strings
lars-reimann Oct 19, 2023
b29f08b
feat: partial evaluation for indexed access
lars-reimann Oct 19, 2023
50bd8e5
test: ignore missing line coverage for model (will be fixed later)
lars-reimann Oct 19, 2023
2576d18
style: fix linter errors
lars-reimann Oct 19, 2023
00768d6
style: apply automated linter fixes
megalinter-bot Oct 19, 2023
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
2 changes: 1 addition & 1 deletion docs/development/partial-evaluation-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ partial evaluation test.
test marker, the second test comment corresponds to the second test marker, etc.
* `// $TEST$ constant equivalence_class <id>`: Assert that all nodes with the same `<id>` get partially evaluated
successfully to the same constant expression.
* `// $TEST$ constant serialization <value>`: Assert that the node gets partially evaluated to a constant expression
* `// $TEST$ serialization <value>`: Assert that the node gets partially evaluated to a constant expression
that serializes to `<value>`.
* `// $TEST$ not constant`: Assert that the node cannot be evaluated to a constant expression.
6. Run the tests. The test runner will automatically pick up the new test.
32 changes: 32 additions & 0 deletions img/safe-ds_file_icon_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions img/safe-ds_file_icon_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/safe-ds_logo_rounded.png
Binary file not shown.
Binary file added img/safe-ds_logo_rounded_128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"galleryBanner": {
"color": "#e3e9e9"
},
"icon": "img/safe-ds_logo_rounded.png",
"icon": "img/safe-ds_logo_rounded_128x128.png",
"homepage": "https://dsl.safeds.com",
"qna": "https://github.com/orgs/Safe-DS/discussions",
"bugs": {
Expand Down Expand Up @@ -60,7 +60,11 @@
".sdsstub",
".sdstest"
],
"configuration": "./language-configuration.json"
"configuration": "./language-configuration.json",
"icon": {
"light": "img/safe-ds_file_icon_light.svg",
"dark": "img/safe-ds_file_icon_dark.svg"
}
}
],
"grammars": [
Expand Down
16 changes: 9 additions & 7 deletions src/language/builtins/safe-ds-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { resourceNameToUri } from '../../helpers/resources.js';
import { URI } from 'langium';
import { SafeDsServices } from '../safe-ds-module.js';
import { SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js';
import { toConstantExpression } from '../partialEvaluation/toConstantExpression.js';
import { ConstantExpression, ConstantString } from '../partialEvaluation/model.js';
import { EvaluatedNode, StringConstant } from '../partialEvaluation/model.js';
import { SafeDsPartialEvaluator } from '../partialEvaluation/safe-ds-partial-evaluator.js';

const ANNOTATION_USAGE_URI = resourceNameToUri('builtins/safeds/lang/annotationUsage.sdsstub');
const CODE_GENERATION_URI = resourceNameToUri('builtins/safeds/lang/codeGeneration.sdsstub');
Expand All @@ -15,11 +15,13 @@ const MATURITY_URI = resourceNameToUri('builtins/safeds/lang/maturity.sdsstub');

export class SafeDsAnnotations extends SafeDsModuleMembers<SdsAnnotation> {
private readonly nodeMapper: SafeDsNodeMapper;
private readonly partialEvaluator: SafeDsPartialEvaluator;

constructor(services: SafeDsServices) {
super(services);

this.nodeMapper = services.helpers.NodeMapper;
this.partialEvaluator = services.evaluation.PartialEvaluator;
}

isDeprecated(node: SdsAnnotatedObject | undefined): boolean {
Expand Down Expand Up @@ -48,7 +50,7 @@ export class SafeDsAnnotations extends SafeDsModuleMembers<SdsAnnotation> {

getPythonModule(node: SdsModule | undefined): string | undefined {
const value = this.getArgumentValue(node, this.PythonModule, 'qualifiedName');
if (value instanceof ConstantString) {
if (value instanceof StringConstant) {
return value.value;
} else {
return undefined;
Expand All @@ -61,7 +63,7 @@ export class SafeDsAnnotations extends SafeDsModuleMembers<SdsAnnotation> {

getPythonName(node: SdsAnnotatedObject | undefined): string | undefined {
const value = this.getArgumentValue(node, this.PythonName, 'name');
if (value instanceof ConstantString) {
if (value instanceof StringConstant) {
return value.value;
} else {
return undefined;
Expand Down Expand Up @@ -92,11 +94,11 @@ export class SafeDsAnnotations extends SafeDsModuleMembers<SdsAnnotation> {
node: SdsAnnotatedObject | undefined,
annotation: SdsAnnotation | undefined,
parameterName: string,
): ConstantExpression | undefined {
): EvaluatedNode {
const annotationCall = findFirstAnnotationCallOf(node, annotation);
const expression = argumentsOrEmpty(annotationCall).find(
const argumentValue = argumentsOrEmpty(annotationCall).find(
(it) => this.nodeMapper.argumentToParameterOrUndefined(it)?.name === parameterName,
)?.value;
return toConstantExpression(expression);
return this.partialEvaluator.evaluate(argumentValue);
}
}
Loading