[Nice-commit] Nice/src/mlsub/typing TypeConstructor.java,1.16,1.17 Enumeration.java,1.10,1.11
Brought to you by:
bonniot
From: <bo...@us...> - 2004-02-24 18:42:01
|
Update of /cvsroot/nice/Nice/src/mlsub/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19329/src/mlsub/typing Modified Files: TypeConstructor.java Enumeration.java Log Message: Optimization: really return only one solution for those positions that are not used for dispatch. Index: TypeConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/TypeConstructor.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** TypeConstructor.java 25 Apr 2003 17:21:25 -0000 1.16 --- TypeConstructor.java 24 Feb 2004 18:35:26 -0000 1.17 *************** *** 180,185 **** ****************************************************************/ - public int enumerateTagIndex = -1; // used in Typing.enumerate. ugly ! Subclass - public AtomicKind variance; private boolean concrete; --- 180,183 ---- Index: Enumeration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/Enumeration.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Enumeration.java 16 Dec 2003 11:39:10 -0000 1.10 --- Enumeration.java 24 Feb 2004 18:35:26 -0000 1.11 *************** *** 180,184 **** else { ! List solutions = enumerateTags(tags); res.addAll(solutions); if (solutions.size() > 0) --- 180,184 ---- else { ! List solutions = enumerateTags(tags, all); res.addAll(solutions); if (solutions.size() > 0) *************** *** 202,206 **** private static class SolutionFound extends RuntimeException {} ! private static List enumerateTags(Element[] tags) { TagsList tuples = new TagsList(tags.length); --- 202,206 ---- private static class SolutionFound extends RuntimeException {} ! private static List enumerateTags(Element[] tags, boolean[] all) { TagsList tuples = new TagsList(tags.length); *************** *** 209,212 **** --- 209,215 ---- List observers = new ArrayList(tags.length); // idem + // The variable TCs that will hold the solutions. + TypeConstructor[] vars = new TypeConstructor[tags.length]; + Engine.enter(); try{ *************** *** 243,250 **** TypeConstructor varTC = new TypeConstructor(constTC.variance); ! ! varTC.enumerateTagIndex = i; Typing.introduce(varTC); ! obs.set(varTC.getId()); try{ k.leq(varTC, constTC); --- 246,257 ---- TypeConstructor varTC = new TypeConstructor(constTC.variance); ! vars[i] = varTC; ! Typing.introduce(varTC); ! ! // We only observe those positions where all solutions are needed. ! if (all[i]) ! obs.set(varTC.getId()); ! try{ k.leq(varTC, constTC); *************** *** 261,266 **** BitVector[] pObs = (BitVector[]) observers.toArray(new BitVector[observers.size()]); ! ! if (enumerateInConstraints(pKinds, pObs, tuples, tags)) return emptyList; } --- 268,273 ---- BitVector[] pObs = (BitVector[]) observers.toArray(new BitVector[observers.size()]); ! ! if (enumerateInConstraints(pKinds, pObs, tuples, tags, vars, all)) return emptyList; } *************** *** 279,283 **** BitVector[] observers, final TagsList tuples, ! final Element[] tags) { for(int act = 0; act<kinds.length;act++) --- 286,292 ---- BitVector[] observers, final TagsList tuples, ! final Element[] tags, ! final TypeConstructor[] vars, ! final boolean[] all) { for(int act = 0; act<kinds.length;act++) *************** *** 296,308 **** // Check if this is really a solution, because of // class constraints. ! for (int x = obs.getLowestSetBit(); ! x != BitVector.UNDEFINED_INDEX; ! x = obs.getNextBit(x)) ! { ! TypeConstructor var,sol; ! var=(TypeConstructor) kind.getElement(x); ! sol=(TypeConstructor) kind.getElement(getSolutionOf(x)); ! int index = var.enumerateTagIndex; ! if (! checkClassConstraint(tags[index], sol)) return; } --- 305,330 ---- // Check if this is really a solution, because of // class constraints. ! for (int index = 0; index < vars.length; index++) ! { ! /* If this index does not need all solutions ! (i.e. all[index] is false), and the solution ! sol does not pass checkClassConstraint, ! it might have been that some other solution, which ! we don't generate, would pass. So in this case ! we should restart to try other solutions for this ! index to see if at least one passes or not. ! */ ! ! TypeConstructor var,solution; ! var = vars[index]; ! ! // We only deal with matchable tags, ! // and those that belong to this kind. ! if (var == null || var.getKind() != kind) ! continue; ! ! solution = (TypeConstructor) ! kind.getElement(getSolutionOf(var.getId())); ! if (! checkClassConstraint(tags[index], solution)) return; } *************** *** 310,321 **** // It is a solution, let's add it to the list. tuples.startEntry(); ! for (int x = obs.getLowestSetBit(); ! x != BitVector.UNDEFINED_INDEX; ! x = obs.getNextBit(x)) { ! TypeConstructor var,sol; ! var=(TypeConstructor) kind.getElement(x); ! sol=(TypeConstructor) kind.getElement(getSolutionOf(x)); ! tuples.set(var.enumerateTagIndex, sol); } } --- 332,348 ---- // It is a solution, let's add it to the list. tuples.startEntry(); ! for (int index = 0; index < vars.length; index++) { ! TypeConstructor var, solution; ! var = vars[index]; ! ! // We only deal with matchable tags, ! // and those that belong to this kind. ! if (var == null || var.getKind() != kind) ! continue; ! ! solution = (TypeConstructor) ! kind.getElement(getSolutionOf(var.getId())); ! tuples.set(index, solution); } } |