about summary refs log tree commit diff
path: root/src/boot/util
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2010-06-28 19:24:04 -0700
committerGraydon Hoare <graydon@mozilla.com>2010-06-28 19:24:04 -0700
commit329a65530fecdb59bbf06c6830cd766778b155b4 (patch)
tree10a90eb2e441f6558cb375ea2c8c449f387bc1b6 /src/boot/util
parentbd059a354d74983cc8f5aea2abb9f09db670b86c (diff)
downloadrust-329a65530fecdb59bbf06c6830cd766778b155b4.tar.gz
rust-329a65530fecdb59bbf06c6830cd766778b155b4.zip
Canonicalize hashtables after running them through htab_map. Closes #77.
Diffstat (limited to 'src/boot/util')
-rw-r--r--src/boot/util/common.ml18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/boot/util/common.ml b/src/boot/util/common.ml
index f33a6ea1649..5c381b81206 100644
--- a/src/boot/util/common.ml
+++ b/src/boot/util/common.ml
@@ -220,6 +220,21 @@ let htab_put (htab:('a,'b) Hashtbl.t) (a:'a) (b:'b) : unit =
   Hashtbl.add htab a b
 ;;
 
+(* This is completely ridiculous, but it turns out that ocaml hashtables are
+ * order-of-element-addition sensitive when it comes to the built-in
+ * polymorphic comparison operator. So you have to canonicalize them after
+ * you've stopped adding things to them if you ever want to use them in a
+ * term that requires structural comparison to work. Sigh.
+ *)
+
+let htab_canonicalize (htab:('a,'b) Hashtbl.t) : ('a,'b) Hashtbl.t =
+  let n = Hashtbl.create (Hashtbl.length htab) in
+    Array.iter
+      (fun k -> Hashtbl.add n k (Hashtbl.find htab k))
+      (sorted_htab_keys htab);
+    n
+;;
+
 let htab_map
     (htab:('a,'b) Hashtbl.t)
     (f:'a -> 'b -> ('c * 'd))
@@ -230,10 +245,9 @@ let htab_map
       htab_put ntab c d
   in
     Hashtbl.iter g htab;
-    ntab
+    htab_canonicalize (ntab)
 ;;
 
-
 let htab_fold
     (fn:'a -> 'b -> 'c -> 'c)
     (init:'c)