import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
import org.simantics.scl.compiler.environment.Environment;
import org.simantics.scl.compiler.internal.elaboration.constraints.Constraint;
import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintEnvironment;
import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintSolver;
import org.simantics.scl.compiler.internal.elaboration.constraints.Constraint;
import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintEnvironment;
import org.simantics.scl.compiler.internal.elaboration.constraints.ConstraintSolver;
final Environment environment;
final ConcreteModule module;
ConstraintEnvironment ce;
TypeCheckingScheduler scheduler;
final Environment environment;
final ConcreteModule module;
ConstraintEnvironment ce;
TypeCheckingScheduler scheduler;
- public TypeChecking(ErrorLog errorLog, Environment environment,
- ConcreteModule module) {
- this.errorLog = errorLog;
- this.environment = environment;
+ public TypeChecking(CompilationContext compilationContext, ConcreteModule module) {
+ this.compilationContext = compilationContext;
+ this.environment = compilationContext.environment;
expression = expression.checkType(context, value.getType());
context.popEffectUpperBound();
for(EAmbiguous overloaded : context.overloadedExpressions)
expression = expression.checkType(context, value.getType());
context.popEffectUpperBound();
for(EAmbiguous overloaded : context.overloadedExpressions)
value.setExpression(expression);
ArrayList<EVariable> constraintDemand = context.getConstraintDemand();
value.setExpression(expression);
ArrayList<EVariable> constraintDemand = context.getConstraintDemand();
ArrayList<Variable> fe = new ArrayList<Variable>(red.unsolvedConstraints.size());
for(Constraint c : red.unsolvedConstraints)
ArrayList<Variable> fe = new ArrayList<Variable>(red.unsolvedConstraints.size());
for(Constraint c : red.unsolvedConstraints)
try {
ArrayList<TVar> vars = new ArrayList<TVar>();
type = Types.removeForAll(type, vars);
ArrayList<TPred> givenConstraints = new ArrayList<TPred>();
type = Types.removePred(type, givenConstraints);
try {
ArrayList<TVar> vars = new ArrayList<TVar>();
type = Types.removeForAll(type, vars);
ArrayList<TPred> givenConstraints = new ArrayList<TPred>();
type = Types.removePred(type, givenConstraints);
context.pushEffectUpperBound(expression.location, Types.PROC);
expression = expression.checkType(context, type);
context.popEffectUpperBound();
for(EAmbiguous overloaded : context.overloadedExpressions)
context.pushEffectUpperBound(expression.location, Types.PROC);
expression = expression.checkType(context, type);
context.popEffectUpperBound();
for(EAmbiguous overloaded : context.overloadedExpressions)
expression.getType().addPolarity(Polarity.POSITIVE);
context.solveSubsumptions(expression.getLocation());
expression.getType().addPolarity(Polarity.POSITIVE);
context.solveSubsumptions(expression.getLocation());
+
+ if(compilationContext.errorLog.getErrorCount() != errorCountBeforeTypeChecking) {
+ int typeArity = Types.getArity(type);
+ if(typeArity != functionArity)
+ compilationContext.errorLog.logWarning(value.definitionLocation, "Possible problem: type declaration has " + typeArity + " parameter types, but function definition has " + functionArity + " parameters.");
+ }
+
ArrayList<EVariable> demands = context.getConstraintDemand();
if(!demands.isEmpty() || !givenConstraints.isEmpty()) {
ReducedConstraints red =
ConstraintSolver.solve(ce, givenConstraints, demands, true);
givenConstraints.clear();
for(Constraint c : red.unsolvedConstraints) {
ArrayList<EVariable> demands = context.getConstraintDemand();
if(!demands.isEmpty() || !givenConstraints.isEmpty()) {
ReducedConstraints red =
ConstraintSolver.solve(ce, givenConstraints, demands, true);
givenConstraints.clear();
for(Constraint c : red.unsolvedConstraints) {
expression = expression.decomposeMatching();
}
expression = expression.closure(vars.toArray(new TVar[vars.size()]));
value.setExpression(expression);
} catch(Exception e) {
expression = expression.decomposeMatching();
}
expression = expression.closure(vars.toArray(new TVar[vars.size()]));
value.setExpression(expression);
} catch(Exception e) {
- ce = new ConstraintEnvironment(environment);
- scheduler = new TypeCheckingScheduler(errorLog, environment);
+ ce = new ConstraintEnvironment(compilationContext);
+ scheduler = new TypeCheckingScheduler(compilationContext);
for(TransformationRule rule : module.getRules())
for(Query[] queries : rule.sections.values())
for(Query query : queries)
for(TransformationRule rule : module.getRules())
for(Query[] queries : rule.sections.values())
for(Query query : queries)
for(MappingRelation mappingRelation : module.getMappingRelations())
for(Type parameterType : mappingRelation.parameterTypes)
if(!parameterType.isGround()) {
for(MappingRelation mappingRelation : module.getMappingRelations())
for(Type parameterType : mappingRelation.parameterTypes)
if(!parameterType.isGround()) {