Fixed leftover problems in unification of *Array and Vector types 13/1413/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 31 Jan 2018 14:58:34 +0000 (16:58 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 31 Jan 2018 14:58:34 +0000 (16:58 +0200)
The fix was to remove the leftover `Show DoubleArray` instance from
Prelude.

ConstraintEnvironment.reduce now produces better error output in cases
where reduction cannot be completed due to multiple remaining matches.

refs #7734

Change-Id: Id970c1090f5bf951c94e99e645664e86b1adb42d

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/Constraint.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSet.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java
bundles/org.simantics.scl.runtime/scl/Prelude.scl

index 52b8692d8f9fcc72394af1bbd0b059399367f077..373a9a333b4e05f2b6c9389325e657ece8a059cc 100644 (file)
@@ -343,7 +343,7 @@ public class TypeChecking {
     }
     
     public void typeCheck() {
-        ce = new ConstraintEnvironment(environment);
+        ce = new ConstraintEnvironment(compilationContext);
         scheduler = new TypeCheckingScheduler(compilationContext);
         
         typeCheckValues();
index 410ec0213fd5949720cc45dc13d924017bb86a19..f862d2128c358999edc0a79c188c008fe348c0b5 100644 (file)
@@ -485,7 +485,7 @@ public class TypingContext {
     public Expression solveConstraints(Environment environment, Expression expression) {
         ArrayList<EVariable> constraintDemand = getConstraintDemand();
         if(!constraintDemand.isEmpty()) {
-            ConstraintEnvironment ce = new ConstraintEnvironment(environment);
+            ConstraintEnvironment ce = new ConstraintEnvironment(compilationContext);
             ReducedConstraints red = ConstraintSolver.solve(
                     ce, new ArrayList<TPred>(0), constraintDemand,
                     true);                                        
index c49167508bb74a83cfa8298c8da70a3c1085a99f..d8c0dd1ae38cb51b7326039c46ba58d1a4c94f88 100644 (file)
@@ -85,7 +85,7 @@ public class Constraint implements Typed {
                 // Try to find constant evidence and prefer that
                 // to subclass
                 {
-                    Reduction reduction = environment.reduce(constraint);
+                    Reduction reduction = environment.reduce(demandLocation, constraint);
                     if(reduction != null && reduction.demands.length == 0) {
                         generator = reduction.generator;
                         generatorParameters = reduction.parameters;
index 5479371a64098dacd6da68aafb83f2a180431995..866569cbb12f8a6ddd7bcb256613624c8ab87549 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.scl.compiler.internal.elaboration.constraints;
 import java.util.ArrayList;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.ClassConstant;
 import org.simantics.scl.compiler.constants.StringConstant;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
@@ -25,10 +26,12 @@ import org.simantics.scl.compiler.types.Types;
 import gnu.trove.map.hash.THashMap;
 
 public class ConstraintEnvironment {
+    CompilationContext compilationContext;
     Environment environment;
     
-    public ConstraintEnvironment(Environment environment) {
-        this.environment = environment;
+    public ConstraintEnvironment(CompilationContext compilationContext) {
+        this.compilationContext = compilationContext;
+        this.environment = compilationContext.environment;
     }
 
     public Superconstraint[] getSuperconstraints(TPred constraint) {
@@ -48,7 +51,7 @@ public class ConstraintEnvironment {
         return result;
     }
        
-    public Reduction reduce(TPred constraint) {
+    public Reduction reduce(long location, TPred constraint) {
         // VecComp
         if(constraint.typeClass == Types.VEC_COMP) {
             Type parameter = Types.canonical(constraint.parameters[0]);
@@ -143,7 +146,17 @@ public class ConstraintEnvironment {
         if(reductions.size() == 1)
             return reductions.get(0);
         else if(reductions.size() > 1) {
-            throw new InternalCompilerError("Found more than one matching instances for " + constraint.typeClass + ".");
+            StringBuilder b = new StringBuilder();
+            b.append("Found more than one matching instances for ").append(constraint.typeClass).append(": ");
+            boolean first = true;
+            for(Reduction reduction : reductions) {
+                if(first)
+                    first = false;
+                else
+                    b.append(", ");
+                b.append(reduction.generator);
+            }
+            compilationContext.errorLog.log(location, b.toString());
         }
         return null;
     }
index 4b516a734d74b49a9c4c235d7eb84039ac1f8bec..a18eae11f3c2899738daf325c6884eed511a274f 100644 (file)
@@ -100,7 +100,7 @@ class ConstraintSet {
             unsolved = new THashSet<Constraint>();
             for(Constraint c : temp) {
                 if(c.state == Constraint.STATE_UNSOLVED) {
-                    Reduction reduction = environment.reduce(c.constraint);
+                    Reduction reduction = environment.reduce(c.demandLocation, c.constraint);
                     if(reduction != null) {
                         TPred[] demands = reduction.demands;
                         if(demands.length == 0)
index 87f75a0411629a859347245ea48af94649161697..69b8e7e647f2a393e988204d4092fa7306d4aa51 100644 (file)
@@ -153,7 +153,7 @@ public class ConstraintSolver {
                             throw new InternalCompilerError();
                         }
                         for(Constraint constraint : group) {
-                            Reduction reduction = environment.reduce(constraint.constraint);
+                            Reduction reduction = environment.reduce(constraint.demandLocation, constraint.constraint);
                             if(reduction.demands.length > 0)
                                 throw new InternalCompilerError();
                             constraint.setGenerator(Constraint.STATE_HAS_INSTANCE,
index cce9064090ca123545e387b711e7cab902e95680..7e558bdc4fd0c5d1216675919f5465b0042391b1 100644 (file)
@@ -48,10 +48,6 @@ type FloatArray = Vector Float
 type DoubleArray = Vector Double
 
 importJava "java.util.Arrays" where
-    @private
-    @JavaName toString
-    showDoubleArray :: DoubleArray -> String
-    
     "Converts an array to a list."
     @JavaName asList    
     arrayToList :: Array a -> [a]
@@ -61,9 +57,6 @@ importJava "java.util.List" where
     @JavaName toArray
     listToArray :: [a] -> Array a
 
-instance Show DoubleArray where
-    show = showDoubleArray
-
 importJava "org.simantics.scl.runtime.Coercion" where
     "Converts a list of doubles to a double array."
     toDoubleArray :: [Double] -> DoubleArray