From: Tuukka Lehtonen Date: Wed, 31 Jan 2018 14:58:34 +0000 (+0200) Subject: Fixed leftover problems in unification of *Array and Vector types X-Git-Tag: v1.43.0~136^2~610 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F13%2F1413%2F1;p=simantics%2Fplatform.git Fixed leftover problems in unification of *Array and Vector types 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 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java index 52b8692d8..373a9a333 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/TypeChecking.java @@ -343,7 +343,7 @@ public class TypeChecking { } public void typeCheck() { - ce = new ConstraintEnvironment(environment); + ce = new ConstraintEnvironment(compilationContext); scheduler = new TypeCheckingScheduler(compilationContext); typeCheckValues(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java index 410ec0213..f862d2128 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/contexts/TypingContext.java @@ -485,7 +485,7 @@ public class TypingContext { public Expression solveConstraints(Environment environment, Expression expression) { ArrayList constraintDemand = getConstraintDemand(); if(!constraintDemand.isEmpty()) { - ConstraintEnvironment ce = new ConstraintEnvironment(environment); + ConstraintEnvironment ce = new ConstraintEnvironment(compilationContext); ReducedConstraints red = ConstraintSolver.solve( ce, new ArrayList(0), constraintDemand, true); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/Constraint.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/Constraint.java index c49167508..d8c0dd1ae 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/Constraint.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/Constraint.java @@ -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; diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java index 5479371a6..866569cbb 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintEnvironment.java @@ -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; } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSet.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSet.java index 4b516a734..a18eae11f 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSet.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSet.java @@ -100,7 +100,7 @@ class ConstraintSet { unsolved = new THashSet(); 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) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java index 87f75a041..69b8e7e64 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ConstraintSolver.java @@ -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, diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index cce906409..7e558bdc4 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -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