diff options
author | 2024-03-05 22:01:10 +0100 | |
---|---|---|
committer | 2024-04-07 14:55:46 +0200 | |
commit | c14d8efd509f834b80573bc0339bb990698b265c (patch) | |
tree | dc3ca21785ea17bc75a861f373ee69ec64d6e97f /subprojects/language-semantics/src/main/java | |
parent | feat(language): validate assignment expressions (diff) | |
download | refinery-c14d8efd509f834b80573bc0339bb990698b265c.tar.gz refinery-c14d8efd509f834b80573bc0339bb990698b265c.tar.zst refinery-c14d8efd509f834b80573bc0339bb990698b265c.zip |
feat(language): type inference
* Customizable operator overloads.
* Customizable aggregation operators.
* Simplify ProblemQualifiedNameProvider.
Diffstat (limited to 'subprojects/language-semantics/src/main/java')
3 files changed, 18 insertions, 22 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java index 203baad6..2a623cf1 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -8,10 +8,10 @@ package tools.refinery.language.semantics; | |||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import tools.refinery.language.library.BuiltinLibrary; | 9 | import tools.refinery.language.library.BuiltinLibrary; |
10 | import tools.refinery.language.model.problem.*; | 10 | import tools.refinery.language.model.problem.*; |
11 | import tools.refinery.language.scoping.imports.ImportAdapterProvider; | ||
11 | import tools.refinery.language.scoping.imports.ImportCollector; | 12 | import tools.refinery.language.scoping.imports.ImportCollector; |
12 | import tools.refinery.language.semantics.internal.MutableSeed; | 13 | import tools.refinery.language.semantics.internal.MutableSeed; |
13 | import tools.refinery.language.utils.BuiltinSymbols; | 14 | import tools.refinery.language.utils.BuiltinSymbols; |
14 | import tools.refinery.language.utils.ProblemDesugarer; | ||
15 | import tools.refinery.language.utils.ProblemUtil; | 15 | import tools.refinery.language.utils.ProblemUtil; |
16 | import tools.refinery.store.dse.propagation.PropagationBuilder; | 16 | import tools.refinery.store.dse.propagation.PropagationBuilder; |
17 | import tools.refinery.store.model.ModelStoreBuilder; | 17 | import tools.refinery.store.model.ModelStoreBuilder; |
@@ -48,9 +48,6 @@ import java.util.*; | |||
48 | 48 | ||
49 | public class ModelInitializer { | 49 | public class ModelInitializer { |
50 | @Inject | 50 | @Inject |
51 | private ProblemDesugarer desugarer; | ||
52 | |||
53 | @Inject | ||
54 | private SemanticsUtils semanticsUtils; | 51 | private SemanticsUtils semanticsUtils; |
55 | 52 | ||
56 | @Inject | 53 | @Inject |
@@ -59,6 +56,9 @@ public class ModelInitializer { | |||
59 | @Inject | 56 | @Inject |
60 | private ImportCollector importCollector; | 57 | private ImportCollector importCollector; |
61 | 58 | ||
59 | @Inject | ||
60 | private ImportAdapterProvider importAdapterProvider; | ||
61 | |||
62 | private Problem problem; | 62 | private Problem problem; |
63 | 63 | ||
64 | private final Set<Problem> importedProblems = new HashSet<>(); | 64 | private final Set<Problem> importedProblems = new HashSet<>(); |
@@ -96,8 +96,7 @@ public class ModelInitializer { | |||
96 | importedProblems.add(problem); | 96 | importedProblems.add(problem); |
97 | problemTrace.setProblem(problem); | 97 | problemTrace.setProblem(problem); |
98 | try { | 98 | try { |
99 | builtinSymbols = desugarer.getBuiltinSymbols(problem).orElseThrow(() -> new IllegalArgumentException( | 99 | builtinSymbols = importAdapterProvider.getBuiltinSymbols(problem); |
100 | "Problem has no builtin library")); | ||
101 | var nodeInfo = collectPartialRelation(builtinSymbols.node(), 1, TruthValue.TRUE, TruthValue.TRUE); | 100 | var nodeInfo = collectPartialRelation(builtinSymbols.node(), 1, TruthValue.TRUE, TruthValue.TRUE); |
102 | nodeRelation = nodeInfo.partialRelation(); | 101 | nodeRelation = nodeInfo.partialRelation(); |
103 | metamodelBuilder.type(nodeRelation); | 102 | metamodelBuilder.type(nodeRelation); |
@@ -681,8 +680,8 @@ public class ModelInitializer { | |||
681 | var argumentList = toArgumentList(List.of(comparisonExpr.getLeft(), comparisonExpr.getRight()), | 680 | var argumentList = toArgumentList(List.of(comparisonExpr.getLeft(), comparisonExpr.getRight()), |
682 | localScope, literals); | 681 | localScope, literals); |
683 | boolean positive = switch (comparisonExpr.getOp()) { | 682 | boolean positive = switch (comparisonExpr.getOp()) { |
684 | case EQ -> true; | 683 | case NODE_EQ -> true; |
685 | case NOT_EQ -> false; | 684 | case NODE_NOT_EQ -> false; |
686 | default -> throw new TracedException( | 685 | default -> throw new TracedException( |
687 | comparisonExpr, "Unsupported operator"); | 686 | comparisonExpr, "Unsupported operator"); |
688 | }; | 687 | }; |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SemanticsUtils.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SemanticsUtils.java index 9c40e6df..5e0526bc 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SemanticsUtils.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SemanticsUtils.java | |||
@@ -7,7 +7,6 @@ package tools.refinery.language.semantics; | |||
7 | 7 | ||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import com.google.inject.Singleton; | 9 | import com.google.inject.Singleton; |
10 | import com.google.inject.name.Named; | ||
11 | import org.eclipse.emf.ecore.EClass; | 10 | import org.eclipse.emf.ecore.EClass; |
12 | import org.eclipse.emf.ecore.EObject; | 11 | import org.eclipse.emf.ecore.EObject; |
13 | import org.eclipse.emf.ecore.util.EcoreUtil; | 12 | import org.eclipse.emf.ecore.util.EcoreUtil; |
@@ -20,7 +19,6 @@ import org.eclipse.xtext.scoping.IScope; | |||
20 | import org.jetbrains.annotations.NotNull; | 19 | import org.jetbrains.annotations.NotNull; |
21 | import org.jetbrains.annotations.Nullable; | 20 | import org.jetbrains.annotations.Nullable; |
22 | import tools.refinery.language.model.problem.Problem; | 21 | import tools.refinery.language.model.problem.Problem; |
23 | import tools.refinery.language.naming.ProblemQualifiedNameProvider; | ||
24 | 22 | ||
25 | import java.util.Optional; | 23 | import java.util.Optional; |
26 | 24 | ||
@@ -30,17 +28,13 @@ public class SemanticsUtils { | |||
30 | private IQualifiedNameProvider qualifiedNameProvider; | 28 | private IQualifiedNameProvider qualifiedNameProvider; |
31 | 29 | ||
32 | @Inject | 30 | @Inject |
33 | @Named(ProblemQualifiedNameProvider.NAMED_DELEGATE) | ||
34 | private IQualifiedNameProvider delegateQualifiedNameProvider; | ||
35 | |||
36 | @Inject | ||
37 | private IQualifiedNameConverter qualifiedNameConverter; | 31 | private IQualifiedNameConverter qualifiedNameConverter; |
38 | 32 | ||
39 | @Inject | 33 | @Inject |
40 | private IResourceDescriptionsProvider resourceDescriptionsProvider; | 34 | private IResourceDescriptionsProvider resourceDescriptionsProvider; |
41 | 35 | ||
42 | public Optional<String> getNameWithoutRootPrefix(EObject eObject) { | 36 | public Optional<String> getNameWithoutRootPrefix(EObject eObject) { |
43 | var qualifiedName = delegateQualifiedNameProvider.getFullyQualifiedName(eObject); | 37 | var qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject); |
44 | if (qualifiedName == null) { | 38 | if (qualifiedName == null) { |
45 | return Optional.empty(); | 39 | return Optional.empty(); |
46 | } | 40 | } |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SolutionSerializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SolutionSerializer.java index 377a66f3..61e70bcd 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SolutionSerializer.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/SolutionSerializer.java | |||
@@ -21,7 +21,8 @@ import org.eclipse.xtext.resource.XtextResourceSet; | |||
21 | import org.eclipse.xtext.scoping.IScopeProvider; | 21 | import org.eclipse.xtext.scoping.IScopeProvider; |
22 | import tools.refinery.language.model.problem.*; | 22 | import tools.refinery.language.model.problem.*; |
23 | import tools.refinery.language.naming.NamingUtil; | 23 | import tools.refinery.language.naming.NamingUtil; |
24 | import tools.refinery.language.utils.ProblemDesugarer; | 24 | import tools.refinery.language.scoping.imports.ImportAdapterProvider; |
25 | import tools.refinery.language.typesystem.SignatureProvider; | ||
25 | import tools.refinery.language.utils.ProblemUtil; | 26 | import tools.refinery.language.utils.ProblemUtil; |
26 | import tools.refinery.store.model.Model; | 27 | import tools.refinery.store.model.Model; |
27 | import tools.refinery.store.reasoning.ReasoningAdapter; | 28 | import tools.refinery.store.reasoning.ReasoningAdapter; |
@@ -57,10 +58,13 @@ public class SolutionSerializer { | |||
57 | private IScopeProvider scopeProvider; | 58 | private IScopeProvider scopeProvider; |
58 | 59 | ||
59 | @Inject | 60 | @Inject |
60 | private ProblemDesugarer desugarer; | 61 | private NodeNameProvider nameProvider; |
61 | 62 | ||
62 | @Inject | 63 | @Inject |
63 | private NodeNameProvider nameProvider; | 64 | private ImportAdapterProvider importAdapterProvider; |
65 | |||
66 | @Inject | ||
67 | private SignatureProvider signatureProvider; | ||
64 | 68 | ||
65 | private ProblemTrace trace; | 69 | private ProblemTrace trace; |
66 | private Model model; | 70 | private Model model; |
@@ -223,8 +227,7 @@ public class SolutionSerializer { | |||
223 | } | 227 | } |
224 | 228 | ||
225 | private void addExistsAssertions() { | 229 | private void addExistsAssertions() { |
226 | var builtinSymbols = desugarer.getBuiltinSymbols(problem).orElseThrow(() -> new IllegalStateException("No " + | 230 | var builtinSymbols = importAdapterProvider.getBuiltinSymbols(problem); |
227 | "builtin library in copied problem")); | ||
228 | // Make sure to output exists assertions in a deterministic order. | 231 | // Make sure to output exists assertions in a deterministic order. |
229 | var sortedNewNodes = new TreeMap<Integer, Node>(); | 232 | var sortedNewNodes = new TreeMap<Integer, Node>(); |
230 | for (var pair : trace.getNodeTrace().keyValuesView()) { | 233 | for (var pair : trace.getNodeTrace().keyValuesView()) { |
@@ -336,7 +339,7 @@ public class SolutionSerializer { | |||
336 | var assertion = ProblemFactory.eINSTANCE.createAssertion(); | 339 | var assertion = ProblemFactory.eINSTANCE.createAssertion(); |
337 | assertion.setDefault(true); | 340 | assertion.setDefault(true); |
338 | assertion.setRelation(relation); | 341 | assertion.setRelation(relation); |
339 | int arity = ProblemUtil.getArity(relation); | 342 | int arity = signatureProvider.getArity(relation); |
340 | for (int i = 0; i < arity; i++) { | 343 | for (int i = 0; i < arity; i++) { |
341 | var argument = ProblemFactory.eINSTANCE.createWildcardAssertionArgument(); | 344 | var argument = ProblemFactory.eINSTANCE.createWildcardAssertionArgument(); |
342 | assertion.getArguments().add(argument); | 345 | assertion.getArguments().add(argument); |