Update of /cvsroot/nice/Nice/src/mlsub/typing/lowlevel
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22896/src/mlsub/typing/lowlevel
Modified Files:
Engine.java
Log Message:
Do not allow a soft type variable to become greater than Object if it is
already constrained to be smaller than another type, as that is obviously
unsafe.
Index: Engine.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/mlsub/typing/lowlevel/Engine.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** Engine.java 9 Jun 2005 11:56:59 -0000 1.37
--- Engine.java 17 Jun 2005 14:14:08 -0000 1.38
***************
*** 269,278 ****
rigid element, it will have its type.
it is still possible for it to be greater than Top
! (and therefore equal to Top). For this, we just need to
! forget its previous kind.
*/
if (k1 == mlsub.typing.TopMonotype.TopKind.instance &&
e2 instanceof mlsub.typing.MonotypeVar &&
! ! isRigid(e2))
{
((mlsub.typing.MonotypeVar) e2).resetKind(k1);
--- 269,279 ----
rigid element, it will have its type.
it is still possible for it to be greater than Top
! (and therefore equal to Top), provided it is "free upwards",
! that is, has no constraint to be smaller than another element.
! For this, we just need to forget its previous kind.
*/
if (k1 == mlsub.typing.TopMonotype.TopKind.instance &&
e2 instanceof mlsub.typing.MonotypeVar &&
! ! isRigid(e2) && isFreeUpwards(e2))
{
((mlsub.typing.MonotypeVar) e2).resetKind(k1);
***************
*** 341,344 ****
--- 342,346 ----
}
+ public static final int INVALID = -1;
private static final int FLOATING = -3;
private static final int RIGID = -4;
***************
*** 358,361 ****
--- 360,388 ----
}
+ static boolean isFreeUpwards(Element e)
+ {
+ if (e instanceof mlsub.typing.Monotype)
+ {
+ mlsub.typing.Monotype m = (mlsub.typing.Monotype) e;
+
+ // If there is a constructed equivalent, it is the one that
+ // has been getting the constraints (in particular its head).
+ m = m.equivalent();
+ if (m.head() != null)
+ e = m.head();
+ else
+ e = m;
+ }
+
+ if (e.getId() == FLOATING)
+ /// XXX check frozen leqs?
+ return true;
+
+ if (e.getId() < 0)
+ return false;
+
+ return getConstraint(e.getKind()).isFreeUpwards(e);
+ }
+
/****************************************************************
* Simplification
***************
*** 1001,1004 ****
--- 1028,1046 ----
}
+
+ boolean isFreeUpwards(Element e)
+ {
+ final int id = e.getId();
+
+ // If there is any i with a id <: i constraint, return false
+ // TODO: handle cases when id <: i where i is non rigid, but not free
+ // upwards
+ for (int i = 0; i < k0.firstNonRigid(); i++)
+ if (i != id && k0.wasEntered(id, i))
+ return false;
+
+ return true;
+ }
+
void mark()
{
|