From 3e457239db8dd214a3a10c74c2ecefa0f0f8dd1a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Mon, 24 Jul 2017 17:36:55 +0300 Subject: [PATCH] (refs #7375) Fixed implementation of collectEffects Change-Id: I25ebbb6b35e8d1828f36da5c55de8763364c8dd3 --- .../modeling/scl/GraphPropertyRelation.java | 10 +++++++++ .../simantics/modeling/scl/GraphRelation.java | 10 +++++++++ .../compiler/elaboration/chr/CHRLiteral.java | 9 -------- .../compiler/elaboration/chr/CHRQuery.java | 12 ---------- .../compiler/elaboration/chr/CHRRelation.java | 4 ++++ .../compiler/elaboration/chr/CHRRuleset.java | 10 --------- .../chr/relations/CHRConstraint.java | 11 ++++++++++ .../chr/relations/ExternalCHRRelation.java | 12 ++++++++++ .../chr/relations/SpecialCHRRelation.java | 10 +++++++++ .../chr/relations/UnresolvedCHRRelation.java | 13 +++++++++++ .../visitors/CollectEffectsVisitor.java | 22 ++++++++++++++----- .../elaboration/java/CheckRelation.java | 10 +++++++++ .../compiler/elaboration/java/EqRelation.java | 11 +++++++++- .../elaboration/java/ExecuteRelation.java | 11 +++++++++- .../elaboration/java/MemberRelation.java | 10 +++++++++ .../elaboration/java/MinigraphModule.java | 10 +++++++++ .../elaboration/java/OptionalRelation.java | 10 +++++++++ .../relations/ConcreteRelation.java | 10 +++++++++ .../elaboration/relations/LocalRelation.java | 10 +++++++++ .../elaboration/relations/SCLRelation.java | 2 ++ .../relations/TransitiveClosureRelation.java | 10 +++++++++ 21 files changed, 178 insertions(+), 39 deletions(-) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java index 307a32ccc..a4c1c4b2a 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java @@ -153,4 +153,14 @@ public class GraphPropertyRelation implements SCLRelation { w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE), parameters[1].toVal(compilationContext, w)); } + + @Override + public Type getEnforceEffect() { + return Types.WRITE_GRAPH; + } + + @Override + public Type getQueryEffect() { + return Types.READ_GRAPH; + } } diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java index 331cef2cb..f1c8a79f8 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java @@ -183,4 +183,14 @@ public class GraphRelation implements SCLRelation { w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE), parameters[1].toVal(compilationContext, w)); } + + @Override + public Type getEnforceEffect() { + return Types.WRITE_GRAPH; + } + + @Override + public Type getQueryEffect() { + return Types.READ_GRAPH; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java index 3cbebd49d..eb0f48b20 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java @@ -23,7 +23,6 @@ import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class CHRLiteral extends Symbol { @@ -170,12 +169,4 @@ public class CHRLiteral extends Symbol { visitor.visit(this); return b.toString(); } - - public void collectQueryEffects(THashSet effects) { - // TODO - } - - public void collectEnforceEffects(THashSet effects) { - // TODO - } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java index 5c0fdaea2..c7ac33d88 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java @@ -12,10 +12,8 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor; import org.simantics.scl.compiler.errors.Locations; import org.simantics.scl.compiler.internal.parsing.Symbol; -import org.simantics.scl.compiler.types.Type; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class CHRQuery extends Symbol { @@ -80,14 +78,4 @@ public class CHRQuery extends Symbol { visitor.visit(this); return b.toString(); } - - public void collectQueryEffects(THashSet effects) { - for(CHRLiteral literal : literals) - literal.collectQueryEffects(effects); - } - - public void collectEnforceEffects(THashSet effects) { - for(CHRLiteral literal : literals) - literal.collectEnforceEffects(effects); - } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRelation.java index 3daae67a9..5436fae95 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRelation.java @@ -6,6 +6,8 @@ import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import org.simantics.scl.compiler.types.kinds.Kinds; +import gnu.trove.set.hash.THashSet; + public interface CHRRelation { public static final TVar A = Types.var(Kinds.STAR); @@ -15,4 +17,6 @@ public interface CHRRelation { default String[] getFieldNames() { return null; } + void collectEnforceEffects(THashSet effects); + void collectQueryEffects(THashSet effects); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java index 2a4059522..55bbcfe34 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java @@ -42,7 +42,6 @@ import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TObjectIntHashMap; -import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.TIntHashSet; public class CHRRuleset extends Symbol { @@ -310,15 +309,6 @@ public class CHRRuleset extends Symbol { return runtimeRulesetVariable; } - public void collectEffects(THashSet effects) { - for(CHRRule rule : rules) { - for(CHRLiteral literal : rule.head.literals) - literal.collectQueryEffects(effects); - for(CHRLiteral literal : rule.head.literals) - literal.collectEnforceEffects(effects); - } - } - public void addRule(CHRRule rule) { rules.add(rule); rule.parentRuleset = this; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java index ee7347791..8b7c122a9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java @@ -30,6 +30,7 @@ import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.set.hash.THashSet; public class CHRConstraint extends Symbol implements CHRRelation { public final String name; @@ -235,4 +236,14 @@ public class CHRConstraint extends Symbol implements CHRRelation { public String[] getFieldNames() { return fieldNames; } + + @Override + public void collectEnforceEffects(THashSet effects) { + effects.add(Types.PROC); + } + + @Override + public void collectQueryEffects(THashSet effects) { + effects.add(Types.PROC); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/ExternalCHRRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/ExternalCHRRelation.java index 6f44bc2ab..fdfa195ac 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/ExternalCHRRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/ExternalCHRRelation.java @@ -6,6 +6,8 @@ import org.simantics.scl.compiler.types.TPred; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; +import gnu.trove.set.hash.THashSet; + public class ExternalCHRRelation implements CHRRelation { public final SCLRelation relation; @@ -37,4 +39,14 @@ public class ExternalCHRRelation implements CHRRelation { public String[] getFieldNames() { return relation.getFieldNames(); } + + @Override + public void collectEnforceEffects(THashSet effects) { + effects.add(relation.getEnforceEffect()); + } + + @Override + public void collectQueryEffects(THashSet effects) { + effects.add(relation.getQueryEffect()); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/SpecialCHRRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/SpecialCHRRelation.java index 52da4cfe0..8abf73b3e 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/SpecialCHRRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/SpecialCHRRelation.java @@ -6,6 +6,8 @@ import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; +import gnu.trove.set.hash.THashSet; + public enum SpecialCHRRelation implements CHRRelation { EQUALS(A, A), // only in head ASSIGN(A, A), // only in body @@ -34,4 +36,12 @@ public enum SpecialCHRRelation implements CHRRelation { public TPred[] getTypeConstraints() { return TPred.EMPTY_ARRAY; } + + @Override + public void collectEnforceEffects(THashSet effects) { + } + + @Override + public void collectQueryEffects(THashSet effects) { + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/UnresolvedCHRRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/UnresolvedCHRRelation.java index c852062fb..6cf2930de 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/UnresolvedCHRRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/UnresolvedCHRRelation.java @@ -6,6 +6,9 @@ import org.simantics.scl.compiler.internal.parsing.Symbol; import org.simantics.scl.compiler.types.TPred; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.compiler.types.Types; + +import gnu.trove.set.hash.THashSet; public class UnresolvedCHRRelation extends Symbol implements CHRRelation { public String name; @@ -28,4 +31,14 @@ public class UnresolvedCHRRelation extends Symbol implements CHRRelation { public TPred[] getTypeConstraints() { throw new InternalCompilerError("Encountered unresolved CHRRelation during type checking."); } + + @Override + public void collectEnforceEffects(THashSet effects) { + effects.add(Types.PROC); + } + + @Override + public void collectQueryEffects(THashSet effects) { + effects.add(Types.PROC); + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java index 118d4de1a..10190d5a4 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java @@ -1,7 +1,8 @@ package org.simantics.scl.compiler.elaboration.expressions.visitors; +import org.simantics.scl.compiler.elaboration.chr.CHRLiteral; +import org.simantics.scl.compiler.elaboration.chr.CHRRule; import org.simantics.scl.compiler.elaboration.expressions.EApply; -import org.simantics.scl.compiler.elaboration.expressions.ECHRRuleset; import org.simantics.scl.compiler.elaboration.expressions.ECHRSelect; import org.simantics.scl.compiler.elaboration.expressions.EFieldAccess; import org.simantics.scl.compiler.elaboration.expressions.ELambda; @@ -22,15 +23,24 @@ public class CollectEffectsVisitor extends StandardExpressionVisitor { } @Override - public void visit(ECHRRuleset expression) { - effects.add(Types.PROC); - super.visit(expression); + public void visit(CHRRule rule) { + for(CHRLiteral literal : rule.head.literals) { + super.visit(literal); + literal.relation.collectQueryEffects(effects); + } + for(CHRLiteral literal : rule.body.literals) { + super.visit(literal); + literal.relation.collectEnforceEffects(effects); + } } @Override public void visit(ECHRSelect expression) { - effects.add(Types.PROC); - super.visit(expression); + for(CHRLiteral literal : expression.query.literals) { + super.visit(literal); + literal.relation.collectQueryEffects(effects); + } + expression.expression.accept(this); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/CheckRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/CheckRelation.java index cf927825e..8144a6c8b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/CheckRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/CheckRelation.java @@ -65,5 +65,15 @@ public class CheckRelation extends AbstractRelation { public String toString() { return "Check"; } + + @Override + public Type getEnforceEffect() { + return Types.NO_EFFECTS; + } + + @Override + public Type getQueryEffect() { + return Types.NO_EFFECTS; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EqRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EqRelation.java index 7116ed9f1..316506a5c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EqRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EqRelation.java @@ -75,5 +75,14 @@ public class EqRelation extends AbstractRelation { public String toString() { return "="; } - + + @Override + public Type getEnforceEffect() { + return Types.NO_EFFECTS; + } + + @Override + public Type getQueryEffect() { + return Types.NO_EFFECTS; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ExecuteRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ExecuteRelation.java index 10f36193e..5537f71ab 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ExecuteRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ExecuteRelation.java @@ -70,5 +70,14 @@ public class ExecuteRelation extends AbstractRelation { public String toString() { return "Execute"; } - + + @Override + public Type getEnforceEffect() { + return Types.NO_EFFECTS; + } + + @Override + public Type getQueryEffect() { + return Types.NO_EFFECTS; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MemberRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MemberRelation.java index a022d1b37..f43b62b07 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MemberRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MemberRelation.java @@ -80,4 +80,14 @@ public class MemberRelation extends AbstractRelation { public String toString() { return "<-"; } + + @Override + public Type getEnforceEffect() { + return Types.NO_EFFECTS; + } + + @Override + public Type getQueryEffect() { + return Types.NO_EFFECTS; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java index 434f2da6e..b68657a1c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java @@ -261,6 +261,16 @@ public class MinigraphModule extends ConcreteModule { public String toString() { return "Statement"; } + + @Override + public Type getEnforceEffect() { + return GRAPH; + } + + @Override + public Type getQueryEffect() { + return GRAPH; + } }); addEntityType("Resource", new SCLEntityType() { @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/OptionalRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/OptionalRelation.java index ef30deb43..89568cb57 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/OptionalRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/OptionalRelation.java @@ -80,4 +80,14 @@ public class OptionalRelation extends AbstractRelation { public String toString() { return "Optional"; } + + @Override + public Type getEnforceEffect() { + return Types.NO_EFFECTS; + } + + @Override + public Type getQueryEffect() { + return Types.NO_EFFECTS; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/ConcreteRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/ConcreteRelation.java index 96ace3b64..bcdcb4e35 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/ConcreteRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/ConcreteRelation.java @@ -160,4 +160,14 @@ public class ConcreteRelation extends Symbol implements SCLRelation { Expression[] expressions, Expression[] typeConstraintEvidenceParameters) { throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate."); } + + @Override + public Type getEnforceEffect() { + return writingEffect; + } + + @Override + public Type getQueryEffect() { + return sections.get(0).effect; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/LocalRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/LocalRelation.java index 3fbeef755..0e0016df9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/LocalRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/LocalRelation.java @@ -109,4 +109,14 @@ public class LocalRelation extends AbstractRelation { public String toString() { return name; } + + @Override + public Type getEnforceEffect() { + return Types.PROC; + } + + @Override + public Type getQueryEffect() { + return Types.PROC; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/SCLRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/SCLRelation.java index e93ff6e8f..58d69f4d9 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/SCLRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/SCLRelation.java @@ -63,4 +63,6 @@ public interface SCLRelation { long location, Expression[] parameters, Expression[] typeConstraintEvidenceParameters); + Type getEnforceEffect(); + Type getQueryEffect(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/TransitiveClosureRelation.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/TransitiveClosureRelation.java index b404b1c53..03e3a7f27 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/TransitiveClosureRelation.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/TransitiveClosureRelation.java @@ -139,4 +139,14 @@ public class TransitiveClosureRelation extends AbstractRelation implements Compo return new SCLRelation[] { baseRelation }; } + @Override + public Type getEnforceEffect() { + return baseRelation.getEnforceEffect(); + } + + @Override + public Type getQueryEffect() { + return baseRelation.getQueryEffect(); + } + } -- 2.47.1