[Nice-commit] Nice/src/mlsub/typing/lowlevel Kind.java,1.2,1.3 Engine.java,1.28,1.29 Element.java,1.
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-03-17 17:05:02
|
Update of /cvsroot/nice/Nice/src/mlsub/typing/lowlevel In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19931/src/mlsub/typing/lowlevel Modified Files: Kind.java Engine.java Element.java Log Message: Do type inference on local bindings with polymorphic values. Index: Element.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/Element.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Element.java 2 Aug 2000 16:55:52 -0000 1.2 --- Element.java 17 Mar 2004 16:55:33 -0000 1.3 *************** *** 35,37 **** --- 35,39 ---- */ boolean isConcrete(); + + boolean isExistential(); } Index: Kind.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/Kind.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Kind.java 2 Aug 2000 16:55:53 -0000 1.2 --- Kind.java 17 Mar 2004 16:55:33 -0000 1.3 *************** *** 1,49 **** ! /**************************************************************************/ ! /* B O S S A */ ! /* A simple imperative object-oriented research language */ ! /* (c) Daniel Bonniot 1999 */ ! /* */ ! /* This program is free software; you can redistribute it and/or modify */ ! /* it under the terms of the GNU General Public License as published by */ ! /* the Free Software Foundation; either version 2 of the License, or */ ! /* (at your option) any later version. */ ! /* */ ! /**************************************************************************/ ! ! // File : Kind.java ! // Created : Wed Jul 28 14:53:22 1999 by bonniot ! //$Modified: Wed Aug 02 16:51:36 2000 by Daniel Bonniot $ ! ! package mlsub.typing.lowlevel; ! ! /** Something that knows how to assert constraints on objects of this "Kind" ! * ! * (implemented by Variance, Low level constraints... ) ! * ! * @author bonniot ! */ ! public interface Kind ! { ! /** Asserts that two elements are in a certain order ! * ! * @exception Unsatisfiable ! * @param e1 The smaller element ! * @param e2 The greater element ! */ ! void leq(Element e1, Element e2) throws Unsatisfiable; ! void leq(Element e1, Element e2, boolean initial) throws Unsatisfiable; ! ! /** Introduce a new Element of this kind ! * ! * @param e ! */ ! void register(Element e); ! ! /** ! Return a fresh monotype of this kind, or null if that does not make sense. ! ! This makes a dependancy from mlsub.typing.lowlevel to mlsub.typing, ! but they are likely to be used together anyway. ! */ ! mlsub.typing.Monotype freshMonotype(); ! } --- 1,45 ---- ! /**************************************************************************/ ! /* N I C E */ ! /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2004 */ ! /* */ ! /* This program is free software; you can redistribute it and/or modify */ ! /* it under the terms of the GNU General Public License as published by */ ! /* the Free Software Foundation; either version 2 of the License, or */ ! /* (at your option) any later version. */ ! /* */ ! /**************************************************************************/ ! ! package mlsub.typing.lowlevel; ! ! /** Something that knows how to assert constraints on objects of this "Kind" ! * ! * (implemented by Variance, Low level constraints... ) ! * ! * @author Daniel Bonniot ! */ ! public interface Kind ! { ! /** Asserts that two elements are in a certain order ! * ! * @exception Unsatisfiable ! * @param e1 The smaller element ! * @param e2 The greater element ! */ ! void leq(Element e1, Element e2) throws Unsatisfiable; ! void leq(Element e1, Element e2, boolean initial) throws Unsatisfiable; ! ! /** Introduce a new Element of this kind ! * ! * @param e ! */ ! void register(Element e); ! ! /** ! Return a fresh monotype of this kind, or null if that does not make sense. ! ! This makes a dependancy from mlsub.typing.lowlevel to mlsub.typing, ! but they are likely to be used together anyway. ! */ ! mlsub.typing.Monotype freshMonotype(boolean existential); ! } Index: Engine.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/Engine.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** Engine.java 12 Dec 2003 19:24:53 -0000 1.28 --- Engine.java 17 Mar 2004 16:55:33 -0000 1.29 *************** *** 43,53 **** floating.mark(); soft.mark(); ! frozenLeqs.mark(); ! for(Iterator i = constraints.iterator(); ! i.hasNext();) ! { ! Engine.Constraint k = (Engine.Constraint)i.next(); ! k.mark(); ! //k.rigidify(); } } --- 43,59 ---- floating.mark(); soft.mark(); ! ! // Once we are in existential mode, we don't mark/backtrack. ! if (existentialLevel > 0) ! existentialLevel++; ! else ! { ! frozenLeqs.mark(); ! ! for(Iterator i = constraints.iterator(); i.hasNext();) ! { ! Engine.Constraint k = (Engine.Constraint)i.next(); ! k.mark(); ! } } } *************** *** 127,144 **** public static void backtrack() { ! for(Iterator i = constraints.iterator(); ! i.hasNext();) ! { ! Engine.Constraint k = (Engine.Constraint)i.next(); ! k.backtrack(); } floating.backtrack(); soft.backtrack(); ! for(Iterator i = floating.iterator();i.hasNext();) ! ((Element)i.next()).setKind(null); ! floating.endOfIteration(); ! frozenLeqs.backtrack(); } public static void startSimplify() { --- 133,160 ---- public static void backtrack() { ! if (existentialLevel <= 1) ! { ! for(Iterator i = constraints.iterator(); ! i.hasNext();) ! { ! Engine.Constraint k = (Engine.Constraint) i.next(); ! k.backtrack(); ! } ! ! frozenLeqs.backtrack(); } + floating.backtrack(); soft.backtrack(); ! ! if (existentialLevel > 0) ! existentialLevel--; } + /** Marker used to know how deep we are inside existential mode, so that + we know when to exit from it. + */ + public static int existentialLevel = 0; + public static void startSimplify() { *************** *** 277,281 **** { if(dbg) Debug.println("Registering "+e); ! if(e.getKind()!=null) e.getKind().register(e); --- 293,301 ---- { if(dbg) Debug.println("Registering "+e); ! ! if (e.isExistential()) ! if (existentialLevel == 0) ! existentialLevel = 1; ! if(e.getKind()!=null) e.getKind().register(e); *************** *** 311,316 **** { Kind kind = e.getKind(); ! if(kind==null) ! throw new InternalError("null kind for "+e); Engine.Constraint k = getConstraint(kind); if(k==null) --- 331,337 ---- { Kind kind = e.getKind(); ! if(kind==null) ! return; ! //throw new InternalError("null kind for "+e); Engine.Constraint k = getConstraint(kind); if(k==null) *************** *** 381,386 **** { Kind kind = e.getKind(); ! if(kind==null) ! throw new InternalError("null kind for "+e); Engine.Constraint k = getConstraint(kind); if(k==null) --- 402,407 ---- { Kind kind = e.getKind(); ! if(kind==null) return e; ! //throw new InternalError("null kind for "+e); Engine.Constraint k = getConstraint(kind); if(k==null) *************** *** 421,425 **** { Element e = (Element)s.pop(); ! if(e.getKind()!=null) if(e.getKind()==k) --- 442,446 ---- { Element e = (Element)s.pop(); ! if(e.getKind()!=null) if(e.getKind()==k) *************** *** 546,549 **** --- 567,589 ---- try { + for(Iterator i = frozenLeqs.iterator(); i.hasNext();) + { + Leq leq = (Leq) i.next(); + Element e1 = leq.e1; + Element e2 = leq.e2; + + // If at least one of the two is existential, then we must + // keep + if (e1.isExistential()) + ((mlsub.typing.MonotypeVar) e2).setExistential(); + else if (e2.isExistential()) + ((mlsub.typing.MonotypeVar) e1).setExistential(); + } + } + finally{ + frozenLeqs.endOfIteration(); + } + + try { for(Iterator i = floating.iterator(); i.hasNext();) *************** *** 552,556 **** // useful for nullness head on monotype vars ! if (e.getKind() != null) continue; --- 592,598 ---- // useful for nullness head on monotype vars ! // we don't set existential in stone either, because they ! // might be put into a kind later on. ! if (e.getKind() != null || e.isExistential()) continue; *************** *** 570,574 **** --- 612,625 ---- { Leq leq = (Leq) i.next(); + Element e1 = leq.e1; + Element e2 = leq.e2; + + // By the above code, if e2 is existential, e1 was marked as + // existential too, so we don't need to test e2. + if (e1.isExistential()) + continue; + variablesConstraint.leq(leq.e1, leq.e2, initialContext); + i.remove(); } } *************** *** 576,580 **** frozenLeqs.endOfIteration(); } - frozenLeqs.clear(); } --- 627,630 ---- *************** *** 692,696 **** // this is not too logical to have this... ! public mlsub.typing.Monotype freshMonotype() { return null; --- 742,746 ---- // this is not too logical to have this... ! public mlsub.typing.Monotype freshMonotype(boolean existential) { return null; |