]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Implemented GraphPropertyRelation with the new CHR implementation 75/275/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 19 Jan 2017 08:34:54 +0000 (10:34 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 19 Jan 2017 09:08:10 +0000 (11:08 +0200)
This change adds type constraints to SCLRelations, a feature that is
needed because GraphPropertyRelation requires Serializable type
constraint.

There are also minor improvement to the locations of the compilation
errors caused by exceptions the compiler throws.

refs #6984

Change-Id: I6c1070af3a7129ae21e2cc01a5675412b32b4960

18 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/compilation/CodeGeneration.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/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/plan/IterateRelationOp.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/plan/PlanContext.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/planning/items/GenericPrePlanItem.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/relations/AbstractRelation.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/SCLRelation.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/errors/ErrorLog.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java

index d9803aedde5ef8e5c2198ed5ea75d6ab75c5f6cf..a6009426f36d7422473128b5be520f90ae7eefbd 100644 (file)
@@ -15,6 +15,7 @@ import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
+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;
@@ -26,7 +27,7 @@ public class GraphPropertyRelation implements SCLRelation {
     Type[] parameterTypes;
 
     private static final Type RESOURCE = Types.con("Simantics/DB", "Resource");
-    
+
     public GraphPropertyRelation(Resource propertyRelation, Type valueType) {
         this.propertyRelation = propertyRelation;
         this.valueType = valueType;
@@ -37,7 +38,12 @@ public class GraphPropertyRelation implements SCLRelation {
     public TVar[] getTypeVariables() {
         return TVar.EMPTY_ARRAY;
     }
-    
+
+    @Override
+    public TPred[] getTypeConstraints() {
+        return new TPred[] {Types.pred(Types.SERIALIZABLE, valueType)};
+    }
+
     @Override
     public Type[] getParameterTypes() {
         return parameterTypes;
@@ -53,14 +59,14 @@ public class GraphPropertyRelation implements SCLRelation {
         default: throw new IllegalArgumentException();
         }
     }
-    
+
     @Override
     public int getRequiredVariablesMask() {
         return BF;
     }
-    
+
     private static final Name POSSIBLE_RELATED_VALUE = Name.create("Simantics/DB", "possibleRelatedValue");
-    
+
     @Override
     public void generate(long location, QueryCompilationContext context,
             Type[] typeParameters, Variable[] parameters, int boundVariables) {
@@ -78,8 +84,8 @@ public class GraphPropertyRelation implements SCLRelation {
             context.condition(new EApply(
                     context.getCompilationContext().getConstant(Names.Builtin_equals, valueType),
                     new Expression[] {
-                        new EVariable(temp),
-                        new EVariable(parameters[1])
+                            new EVariable(temp),
+                            new EVariable(parameters[1])
                     }
                     ));
             context.iterateMaybe(temp, possibleValue);
@@ -91,7 +97,7 @@ public class GraphPropertyRelation implements SCLRelation {
     }
 
     private static final Name CLAIM_RELATED_VALUE = Name.create("Simantics/DB", "claimRelatedValue");
-    
+
     @Override
     public Expression generateEnforce(long location, EnforcingContext context,
             Type[] typeParameters, Variable[] parameters) {
@@ -110,15 +116,40 @@ public class GraphPropertyRelation implements SCLRelation {
     public int getPhase() {
         return 0;
     }
-    
+
     @Override
-    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {
-        throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support enforce.");
+    public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
+            Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
+        Environment env = context.context.environment;
+        switch(boundMask) {
+        case BF:
+            context.iterateMaybe(location, w, variables[1],
+                    w.apply(location,
+                            env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType),
+                            typeConstraintEvidenceParameters[0].toVal(env, w),
+                            expressions[0].toVal(env, w),
+                            w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE)));
+            break;
+        case BB:
+            context.checkEqualsJust(location, w, expressions[1].toVal(env, w),
+                    w.apply(location,
+                            env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType),
+                            typeConstraintEvidenceParameters[0].toVal(env, w),
+                            expressions[0].toVal(env, w),
+                            w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE)));
+            break;
+        default: throw new IllegalArgumentException();
+        }
     }
-    
+
     @Override
-    public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
-            Expression[] expressions) {
-        throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate.");
+    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters, Expression[] typeConstraintEvidenceParameters) {
+        Environment env = context.context.environment;
+        w.apply(location,
+                env.getValue(CLAIM_RELATED_VALUE).getValue().createSpecialization(valueType),
+                typeConstraintEvidenceParameters[0].toVal(env, w),
+                parameters[0].toVal(env, w),
+                w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE),
+                parameters[1].toVal(env, w));
     }
 }
index 625a073845a0cdee11babdaf68d9c5ca46a085ae..da08a2a38d2087d7993eca98991bd1316f2ad730 100644 (file)
@@ -138,7 +138,7 @@ public class GraphRelation implements SCLRelation {
 
     @Override
     public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
-            Expression[] expressions) {
+            Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
         Environment env = context.context.environment;
         switch(boundMask) {
         case BF:
@@ -174,7 +174,8 @@ public class GraphRelation implements SCLRelation {
     }
 
     @Override
-    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {
+    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters,
+            Expression[] typeConstraintEvidenceParameters) {
         Environment env = context.context.environment;
         w.apply(location,
                 env.getValue(CLAIM).getValue(),
index 52abbc6d87b48542b60e26152d917d4b64eaa22a..9c7c77470c55b57a91c7dc768d49ff3408e2c9ff 100644 (file)
@@ -26,6 +26,7 @@ import org.simantics.scl.compiler.elaboration.modules.TypeClass;
 import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
 import org.simantics.scl.compiler.elaboration.modules.TypeClassMethod;
 import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
 import org.simantics.scl.compiler.internal.codegen.references.Val;
 import org.simantics.scl.compiler.internal.codegen.ssa.SSAModule;
@@ -167,7 +168,10 @@ public class CodeGeneration {
                     decomposed.parameters[i].setVal(parameterVals[i]);
                 w.return_(decomposed.body.toVal(compilationContext.environment, w));            
             } catch(RuntimeException e) {
-                errorLog.setExceptionPosition(value.getExpression().location);
+                long location = value.getExpression().location;
+                if(location == Locations.NO_LOCATION)
+                    location = value.definitionLocation;
+                errorLog.setExceptionPosition(location);
                 throw e;
             }
         }
index be34361c24ecdca939c654b9302257648655fd92..b34328a53ebb494d0586d331b712b9c361bcb6ab 100644 (file)
@@ -29,6 +29,7 @@ public class CHRLiteral extends Symbol {
     public CHRRelation relation;
     public Type[] typeParameters;
     public Expression[] parameters;
+    public Expression[] typeConstraintEvidenceParameters;
     public boolean killAfterMatch;
     public boolean negated;
     public boolean passive = true;
@@ -73,6 +74,9 @@ public class CHRLiteral extends Symbol {
     public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
         for(Expression parameter : parameters)
             parameter.collectRefs(allRefs, refs);
+        if(typeConstraintEvidenceParameters != null)
+            for(Expression parameter : typeConstraintEvidenceParameters)
+                parameter.collectRefs(allRefs, refs);
     }
 
     public void checkType(TypingContext context) {
@@ -80,6 +84,7 @@ public class CHRLiteral extends Symbol {
             if(parameters.length != 1)
                 throw new InternalCompilerError("Wrong number of parameters for EXECUTE constraint.");
             parameters[0] = parameters[0].checkIgnoredType(context);
+            typeConstraintEvidenceParameters = Expression.EMPTY_ARRAY;
         }
         else {
             TVar[] typeVariables = relation.getTypeVariables();
@@ -92,22 +97,33 @@ public class CHRLiteral extends Symbol {
             else
                 for(int i=0;i<parameters.length;++i)
                     parameters[i] = parameters[i].checkType(context, parameterTypes[i]);
+            
+            typeConstraintEvidenceParameters = context.addConstraints(Types.replace(relation.getTypeConstraints(), typeVariables, typeParameters));
         }
     }
 
     public void collectVars(TObjectIntHashMap<Variable> allVars, TIntHashSet vars) {
         for(Expression parameter : parameters)
             parameter.collectVars(allVars, vars);
+        if(typeConstraintEvidenceParameters != null)
+            for(Expression parameter : typeConstraintEvidenceParameters)
+                parameter.collectVars(allVars, vars);
     }
 
     public void forVariables(VariableProcedure procedure) {
         for(Expression parameter : parameters)
             parameter.forVariables(procedure);
+        if(typeConstraintEvidenceParameters != null)
+            for(Expression parameter : typeConstraintEvidenceParameters)
+                parameter.forVariables(procedure);
     }
 
     public void collectFreeVariables(THashSet<Variable> vars) {
         for(Expression parameter : parameters)
             parameter.collectFreeVariables(vars);
+        if(typeConstraintEvidenceParameters != null)
+            for(Expression parameter : typeConstraintEvidenceParameters)
+                parameter.collectFreeVariables(vars);
     }
 
     public void setLocationDeep(long loc) {
@@ -121,6 +137,9 @@ public class CHRLiteral extends Symbol {
     public void simplify(SimplificationContext context) {
         for(int i=0;i<parameters.length;++i)
             parameters[i] = parameters[i].simplify(context);
+        if(typeConstraintEvidenceParameters != null)
+            for(int i=0;i<typeConstraintEvidenceParameters.length;++i)
+                typeConstraintEvidenceParameters[i] = typeConstraintEvidenceParameters[i].simplify(context);
     }
     
     public String toString() {
index dc8235884c1ad33c617fc69577b07ca5d6dbad58..7369d496c95530b0726f2a3333a17bafb9c8ba54 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.scl.compiler.elaboration.chr;
 
+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;
@@ -10,4 +11,5 @@ public interface CHRRelation {
     
     TVar[] getTypeVariables();
     Type[] getParameterTypes();
+    TPred[] getTypeConstraints();
 }
index 3301512b310332a447c78661d1c41e74a8b9e060..bb5491ad17111c79aa7fc30ee2742cd2ef782149 100644 (file)
@@ -12,7 +12,6 @@ import org.simantics.scl.compiler.constants.generic.CallJava;
 import org.simantics.scl.compiler.constants.generic.MethodRef.FieldRef;
 import org.simantics.scl.compiler.constants.generic.MethodRef.SetFieldRef;
 import org.simantics.scl.compiler.elaboration.chr.analysis.UsageAnalysis;
-import org.simantics.scl.compiler.elaboration.chr.plan.PlanOp;
 import org.simantics.scl.compiler.elaboration.chr.plan.PlanRealizer;
 import org.simantics.scl.compiler.elaboration.chr.plan.PrioritizedPlan;
 import org.simantics.scl.compiler.elaboration.chr.relations.CHRConstraint;
index b26598927b9a9a2409e9ae5522822afba1948917..d4b21ad40848a10d27b6e51e002dec03373d9a15 100644 (file)
@@ -11,14 +11,16 @@ public class IterateRelationOp extends PlanOp {
     public SCLRelation relation;
     public Variable[] variables;
     public Expression[] expressions;
+    public Expression[] typeConstraintEvidenceParameters;
     public int boundMask;
     
     public IterateRelationOp(long location, SCLRelation relation, Variable[] variables, Expression[] expressions,
-            int boundMask) {
+            Expression[] typeConstraintEvidenceParameters, int boundMask) {
         super(location);
         this.relation = relation;
         this.variables = variables;
         this.expressions = expressions;
+        this.typeConstraintEvidenceParameters = typeConstraintEvidenceParameters;
         this.boundMask = boundMask;
         
     }
@@ -37,6 +39,6 @@ public class IterateRelationOp extends PlanOp {
 
     @Override
     public void generateCode(CompilationContext context, PlanContext planContext, CodeWriter w) {
-        relation.generateIterate(planContext, w, location, boundMask, variables, expressions);
+        relation.generateIterate(planContext, w, location, boundMask, variables, expressions, typeConstraintEvidenceParameters);
     }   
 }
index d8cf92332da0a035b4ce86d126a8230dabedea53..aea2cbfdcd47b0921222e4ccde6a50fd0c34db1c 100644 (file)
@@ -2,14 +2,19 @@ package org.simantics.scl.compiler.elaboration.chr.plan;
 
 import java.util.ArrayList;
 
+import javax.crypto.CipherInputStream;
+
 import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.IntegerConstant;
 import org.simantics.scl.compiler.constants.JavaComparisonOperation;
 import org.simantics.scl.compiler.constants.singletons.IncreaseByOne;
+import org.simantics.scl.compiler.constants.singletons.JustConstant;
 import org.simantics.scl.compiler.constants.singletons.ListElement;
 import org.simantics.scl.compiler.constants.singletons.ListLength;
 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
 import org.simantics.scl.compiler.elaboration.expressions.Variable;
+import org.simantics.scl.compiler.elaboration.java.EqualsFunction;
+import org.simantics.scl.compiler.internal.codegen.continuations.Branch;
 import org.simantics.scl.compiler.internal.codegen.continuations.ICont;
 import org.simantics.scl.compiler.internal.codegen.references.IVal;
 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
@@ -59,6 +64,24 @@ public abstract class PlanContext {
         
         w.continueAs(end);
     }
+    
+    public void iterateMaybe(long location, CodeWriter w, Variable variable, IVal maybeValue) {
+        Type componentType = variable.getType();
+
+        CodeWriter end = w.createBlock();
+        CodeWriter body = w.createBlock(componentType);
+        w.switch_(maybeValue, new Branch[] {
+                new Branch(JustConstant.INSTANCE, body.getContinuation()),
+                new Branch(null, end.getContinuation())
+        });
+        
+        variable.setVal(body.getParameters()[0]);
+        nextOp(body);
+        if(body.isUnfinished())
+            body.jump(end.getContinuation());
+        
+        w.continueAs(end);
+    }
 
     public void check(long location, CodeWriter w, IVal booleanValue) {
         CodeWriter end = w.createBlock();
@@ -68,4 +91,29 @@ public abstract class PlanContext {
             w.jump(end.getContinuation());
         w.continueAs(end);
     }
+
+    public void checkEquals(long location, CodeWriter w, IVal a, IVal b) {
+        check(location, w, w.apply(location,
+                EqualsFunction.INSTANCE.createSpecialization(a.getType()),
+                a, b));
+    }
+    
+    public void checkEqualsJust(long location, CodeWriter w, IVal value, IVal maybeValue) {
+        Type componentType = value.getType();
+
+        CodeWriter end = w.createBlock();
+        CodeWriter body = w.createBlock(componentType);
+        w.switch_(maybeValue, new Branch[] {
+                new Branch(JustConstant.INSTANCE, body.getContinuation()),
+                new Branch(null, end.getContinuation())
+        });
+        body.branchAwayUnless(body.apply(location,
+                EqualsFunction.INSTANCE.createSpecialization(componentType),
+                value, body.getParameters()[0]), end.getContinuation());
+        nextOp(body);
+        if(body.isUnfinished())
+            body.jump(end.getContinuation());
+        
+        w.continueAs(end);
+    }
 }
index cbd63c5e6c8e23657fca86f64560e0a0805d89b5..9dceb106ec2dee7d52e91056c255afe008cdaf8a 100644 (file)
@@ -103,7 +103,7 @@ public class GenericPrePlanItem extends PrePlanItem {
                     killAfterMatch(), literal.passive));
         else if(relation instanceof ExternalCHRRelation)
             context.addPlanOp(new IterateRelationOp(location, ((ExternalCHRRelation)relation).relation,
-                    freeVariables, boundExpressions, boundMask));
+                    freeVariables, boundExpressions, literal.typeConstraintEvidenceParameters, boundMask));
         else
             throw new InternalCompilerError();
         if(freeVariableCount > 1) {
index d3d6bdf90ee9f26da83142c76f91344dc66a8f13..7a0e27ba24b75735c2cc64a833a86d0106dd028e 100644 (file)
@@ -22,6 +22,7 @@ import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
 import org.simantics.scl.compiler.internal.codegen.types.StandardTypeConstructor;
 import org.simantics.scl.compiler.internal.parsing.Symbol;
 import org.simantics.scl.compiler.types.TCon;
+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;
@@ -205,4 +206,9 @@ public class CHRConstraint extends Symbol implements CHRRelation {
     public boolean isPassive() {
         return plans.isEmpty();
     }
+    
+    public TPred[] getTypeConstraints() {
+        return TPred.EMPTY_ARRAY;
+    }
+
 }
index 10f2317ab7fba7d8b4914f9811f185117322b745..5e4f5868c15bccec310e3dca43295a02a6299abb 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.scl.compiler.elaboration.chr.relations;
 
 import org.simantics.scl.compiler.elaboration.chr.CHRRelation;
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
+import org.simantics.scl.compiler.types.TPred;
 import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 
@@ -21,6 +22,11 @@ public class ExternalCHRRelation implements CHRRelation {
     public Type[] getParameterTypes() {
         return relation.getParameterTypes();
     }
+
+    @Override
+    public TPred[] getTypeConstraints() {
+        return relation.getTypeConstraints();
+    }
     
     @Override
     public String toString() {
index 2cb0d64fd072e10d32b89858c28d6623acd1908f..c5dbe3c4190b54cf7aff3c08101168a6b50626b5 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.scl.compiler.elaboration.chr.relations;
 
 import org.simantics.scl.compiler.elaboration.chr.CHRRelation;
+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;
@@ -28,4 +29,8 @@ public enum SpecialCHRRelation implements CHRRelation {
     public Type[] getParameterTypes() {
         return parameterTypes;
     }
+    
+    public TPred[] getTypeConstraints() {
+        return TPred.EMPTY_ARRAY;
+    }
 }
index 479d5d22ca4be36ee55c30c9b0eb19505d768718..c852062fb3e2b1b236f83a1656b853a04efb5929 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.scl.compiler.elaboration.chr.relations;
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.elaboration.chr.CHRRelation;
 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;
 
@@ -23,4 +24,8 @@ public class UnresolvedCHRRelation extends Symbol implements CHRRelation {
     public TVar[] getTypeVariables() {
         throw new InternalCompilerError("Encountered unresolved CHRRelation during type checking.");
     }
+    
+    public TPred[] getTypeConstraints() {
+        throw new InternalCompilerError("Encountered unresolved CHRRelation during type checking.");
+    }
 }
index 54acd32f3f923edc1ef41189d762735dbe77db0d..8dc266819d2f500837a87b11dc944b5313cacf8a 100644 (file)
@@ -20,13 +20,14 @@ public abstract class AbstractRelation implements SCLRelation {
     }
     
     @Override
-    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {
+    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters,
+            Expression[] typeConstraintEvidenceParameters) {
         throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support enforce.");
     }
     
     @Override
     public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
-            Expression[] expressions) {
+            Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
         throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate.");
     }
 }
index a38df0bcdeff22132f03868585d292319b9d9ef3..96ace3b6433f0b3be367b81dbe194cd39ff0a171 100644 (file)
@@ -150,13 +150,14 @@ public class ConcreteRelation extends Symbol implements SCLRelation {
     }
 
     @Override
-    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {
+    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters,
+            Expression[] typeConstraintEvidenceParameters) {
         throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support enforce.");
     }
     
     @Override
     public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
-            Expression[] expressions) {
+            Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
         throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate.");
     }
 }
index 9642762cb220cfa5a247ea7a2a3119e1aadb33aa..4ac37bbc1f733b4084f22a17d6bde77c141bf50d 100644 (file)
@@ -6,6 +6,7 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;
 import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;
 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
+import org.simantics.scl.compiler.types.TPred;
 import org.simantics.scl.compiler.types.TVar;
 import org.simantics.scl.compiler.types.Type;
 
@@ -30,6 +31,9 @@ public interface SCLRelation {
     
     TVar[] getTypeVariables();
     Type[] getParameterTypes();
+    default TPred[] getTypeConstraints() {
+        return TPred.EMPTY_ARRAY;
+    }
     int getPhase();
     
     double getSelectivity(int boundVariables);
@@ -48,10 +52,12 @@ public interface SCLRelation {
             long location,
             int boundMask,
             Variable[] variables,
-            Expression[] expressions);
+            Expression[] expressions,
+            Expression[] typeConstraintEvidenceParameters);
     void generateEnforce(
             PlanContext context,
             CodeWriter w,
             long location,
-            Expression[] parameters);
+            Expression[] parameters,
+            Expression[] typeConstraintEvidenceParameters);
 }
index 2287f919bbea59a99d55f123e46d107bff31e076..f2e648b0089ea022021c815f98cf5e52d5d4228c 100644 (file)
@@ -7,7 +7,7 @@ import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 
 public class ErrorLog {
     ArrayList<CompilationError> errors = new ArrayList<CompilationError>(); 
-    long exceptionPosition;
+    long exceptionPosition = Locations.NO_LOCATION;
     
     public void log(String message) {
         errors.add(new CompilationError(message));
@@ -22,10 +22,12 @@ public class ErrorLog {
     }
 
     public void log(Exception e) {
+        long location = Locations.NO_LOCATION;
         if(e instanceof InternalCompilerError)
-            log(((InternalCompilerError)e).location, e);
-        else
-            log(new CompilationError(e));
+            location = ((InternalCompilerError)e).location;
+        if(location == Locations.NO_LOCATION)
+            location = exceptionPosition;
+        log(new CompilationError(location, e));
     }
     
     public void log(long location, Exception e) {
@@ -45,10 +47,6 @@ public class ErrorLog {
         if(this.exceptionPosition == Locations.NO_LOCATION)
             this.exceptionPosition = exceptionPosition;
     }
-    
-    public long getExceptionPosition() {
-        return exceptionPosition;
-    }
 
     public String getErrorsAsString() {
         StringBuilder b = new StringBuilder();
index b20ee9f121ba4890be21b58e53540de72b4a1a6a..f793754eed215be13e6ead654b115dac722b5df2 100644 (file)
@@ -1015,6 +1015,15 @@ public class Types {
         return result;
     }
     
+    public static TPred[] replace(TPred[] types, TVar[] from, Type[] to) {
+        if(types.length == 0)
+            return TPred.EMPTY_ARRAY;
+        TPred[] result = new TPred[types.length];
+        for(int i=0;i<types.length;++i)
+            result[i] = (TPred)types[i].replace(from, to);
+        return result;
+    }
+    
     public static <T extends Type> Type[] replace(Type[] types, THashMap<TVar, T> map) {
         if(types.length == 0)
             return Type.EMPTY_ARRAY;