(refs #7375) Fixed implementation of collectEffects 59/759/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 14:36:55 +0000 (17:36 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 24 Jul 2017 14:36:55 +0000 (17:36 +0300)
Change-Id: I25ebbb6b35e8d1828f36da5c55de8763364c8dd3

21 files changed:
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphPropertyRelation.java
bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRLiteral.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRQuery.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/CHRRuleset.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/CHRConstraint.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/ExternalCHRRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/SpecialCHRRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/relations/UnresolvedCHRRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/visitors/CollectEffectsVisitor.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/CheckRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/EqRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/ExecuteRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MemberRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/MinigraphModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/OptionalRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/ConcreteRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/LocalRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/SCLRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/relations/TransitiveClosureRelation.java

index 307a32cccb1c6664cc7cc4dbf3fd96ea70f9a639..a4c1c4b2ace8530a593531a3b094ce6590162cc6 100644 (file)
@@ -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;
+    }
 }
index 331cef2cb280b282260754cc0a0427747f606e21..f1c8a79f8b9fcc6c1d8a596d7f78b2ef9a55f65e 100644 (file)
@@ -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;
+    }
 }
index 3cbebd49d83e6038b4fb1a6e1ffad56134bfc3d4..eb0f48b20414aa35baa74b4bd0fe743f35a7ba8a 100644 (file)
@@ -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<Type> effects) {
-        // TODO
-    }
-
-    public void collectEnforceEffects(THashSet<Type> effects) {
-        // TODO
-    }
 }
index 5c0fdaea20f929f1a38ecfd93e29dab950ab1ea0..c7ac33d889f208dade23dee4d78daee3d500b963 100644 (file)
@@ -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<Type> effects) {
-        for(CHRLiteral literal : literals)
-            literal.collectQueryEffects(effects);
-    }
-    
-    public void collectEnforceEffects(THashSet<Type> effects) {
-        for(CHRLiteral literal : literals)
-            literal.collectEnforceEffects(effects);
-    }
 }
index 3daae67a94a348681d489f19915bf7ba36020e23..5436fae95a2204e884f9828e7beef2ec7d70200f 100644 (file)
@@ -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<Type> effects);
+    void collectQueryEffects(THashSet<Type> effects);
 }
index 2a405952219e15b92866fd073020eed2e91f93c1..55bbcfe34f9c245968083ab39e374b9814fc8908 100644 (file)
@@ -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<Type> 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;
index ee73477912e3d8ff385f83a29e33562eae8ce0a2..8b7c122a98458b1a8fa5fbac7e745ae36edb72cf 100644 (file)
@@ -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<Type> effects) {
+        effects.add(Types.PROC);
+    }
+
+    @Override
+    public void collectQueryEffects(THashSet<Type> effects) {
+        effects.add(Types.PROC);
+    }
 }
index 6f44bc2ab6852bd0211f6f508f5b629ff8fda4a2..fdfa195ac53158f9e4f94606ef676e102e296b16 100644 (file)
@@ -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<Type> effects) {
+        effects.add(relation.getEnforceEffect());
+    }
+
+    @Override
+    public void collectQueryEffects(THashSet<Type> effects) {
+        effects.add(relation.getQueryEffect());
+    }
 }
index 52da4cfe03fbe1fda90f445db6fb3d04b486bc68..8abf73b3eae2827c16efc30d17b302ccfcb243af 100644 (file)
@@ -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<Type> effects) {
+    }
+
+    @Override
+    public void collectQueryEffects(THashSet<Type> effects) {
+    }
 }
index c852062fb3e2b1b236f83a1656b853a04efb5929..6cf2930de5a7adb2c4f954195da6e76e0aa5abd3 100644 (file)
@@ -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<Type> effects) {
+        effects.add(Types.PROC);
+    }
+
+    @Override
+    public void collectQueryEffects(THashSet<Type> effects) {
+        effects.add(Types.PROC);
+    }
 }
index 118d4de1aea7bdd94bb3f95e06ad74d672e14e6f..10190d5a455ce271104fd2175a8135bebcf397f7 100644 (file)
@@ -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
index cf927825e176df8bbe2e4f4c87063e9d17adf5ee..8144a6c8b66a0f1e0b85f65bb37609c30e0d08dc 100644 (file)
@@ -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;
+    }
     
 }
index 7116ed9f1c757f7f8154f2bda97c1ae93e08872f..316506a5c94058de1e1856079e494f6731c3d026 100644 (file)
@@ -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;
+    }
 }
index 10f36193e9c27773b7a5cd0d46ddbb9dbaa4f37e..5537f71ab2645487c802c78dab8f5c1ff4e0b67b 100644 (file)
@@ -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;
+    }
 }
index a022d1b37e7488d58181b4aa0542081cc04ac328..f43b62b075240b78c9c771c270234290a45f5357 100644 (file)
@@ -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;
+    }
 }
index 434f2da6e13ff7b8249d6373aa7595c87eb7aca6..b68657a1cedd6c9a0cda0a883ee5fdf2ca94b417 100644 (file)
@@ -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
index ef30deb435ca36318350ccfb8c5fdceb06577f60..89568cb57fd5f2201f40484a77a3d1b07d5c27cd 100644 (file)
@@ -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;
+    }
 }
index 96ace3b6433f0b3be367b81dbe194cd39ff0a171..bcdcb4e351a237e7efbd0dcca11deccad63db0ea 100644 (file)
@@ -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; 
+    }
 }
index 3fbeef75525671c41daee45dbd80e8b9213015f2..0e0016df9f3f0a14daa79e5aef5eb1e8d334b1bb 100644 (file)
@@ -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;
+    }
 }
index e93ff6e8fe16a7b5eb1aeb5a45164a86302c0be2..58d69f4d9264a321de0597ec9b5b5c706780708d 100644 (file)
@@ -63,4 +63,6 @@ public interface SCLRelation {
             long location,
             Expression[] parameters,
             Expression[] typeConstraintEvidenceParameters);
+    Type getEnforceEffect();
+    Type getQueryEffect();
 }
index b404b1c53577741eb06ba69e40cc47ebedf0503f..03e3a7f27667e1fe915f28888e86ea62f531ff0b 100644 (file)
@@ -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();
+    }
+
 }