[MLton-devel] hash-type.fun

Matthew Fluet fluet@cs.cornell.edu
Fri, 9 May 2003 09:17:08 -0400 (EDT)


I checked in this change to hash-type.fun:

Index: hash-type.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/mlton/atoms/hash-type.fun,v
retrieving revision 1.4
retrieving revision 1.5
diff -U10 -r1.4 -r1.5
--- hash-type.fun	25 Feb 2003 02:45:26 -0000	1.4
+++ hash-type.fun	8 May 2003 20:59:42 -0000	1.5
@@ -111,21 +111,22 @@
 	 val same: tree * tree -> bool =
 	    fn (Var a, Var a') => Tyvar.equals (a, a')
 	     | (Con (c, ts), Con (c', ts')) =>
 		  Tycon.equals (c, c')
 		  andalso if Tycon.equals (c, Tycon.tuple)
 			     then Vector.equals (ts, ts', equals)
-			  else Vector.forall2 (ts, ts', equals)
+			  else (Vector.length ts = Vector.length ts'
+				andalso Vector.forall2 (ts, ts', equals))
 	     | _ => false


I observed some compilations raise "Vector.forall2"; what seems to have
happened was that XML's simplifyTypes removes phantom-type arguments from
type-constructors.  When a type is later constructed, the hash-consing
checks to see if it already exists.  Usually, changing the arity of a type
constructor changed it's hash value, so we looked in a different bucket.
But, occasionally it hashed to the same value and the Vector.forall2
failed because of the different lengths of type arguments.

Anyways, reflecting on the change I made, it now seems to be equivalent
to:

         val same: tree * tree -> bool =
            fn (Var a, Var a') => Tyvar.equals (a, a')
             | (Con (c, ts), Con (c', ts')) =>
                  Tycon.equals (c, c')
                  andalso Vector.equals (ts, ts', equals)
             | _ => false

and the only reason I can think that this wasn't the original code is that
something was relying on the fact that type constructor arities wouldn't
change.  (Now, that "something" might be the (minor) optimization of using
Vector.forall2 and avoiding the length equality test.)  Everything seems
to be working o.k., but if anyone knows this might break some subtle
invariant, speak up.




-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com

_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel