Skip to content

Commit f1e2c37

Browse files
committed
Cache referent-type calculations in rustboot; cut rustc compile time by 60%.
1 parent 5f24591 commit f1e2c37

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/boot/me/semant.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ type ctxt =
186186

187187
(* Dynamically changes while walking. See path_managing_visitor. *)
188188
ctxt_curr_path: Ast.name_component Stack.t;
189+
190+
ctxt_rty_cache: (Ast.ty,Il.referent_ty) Hashtbl.t;
189191
}
190192
;;
191193

@@ -275,6 +277,7 @@ let new_ctxt sess abi crate =
275277
ctxt_main_name = crate.Ast.crate_main;
276278

277279
ctxt_curr_path = Stack.create ();
280+
ctxt_rty_cache = Hashtbl.create 1024;
278281
}
279282
;;
280283

@@ -2222,7 +2225,7 @@ and referent_type
22222225
let discriminant = word in
22232226
Il.StructTy [| discriminant; union |]
22242227
in
2225-
2228+
let calculate _ =
22262229
match t with
22272230
Ast.TY_any -> Il.StructTy [| word; ptr |]
22282231
| Ast.TY_nil -> Il.NilTy
@@ -2284,6 +2287,9 @@ and referent_type
22842287

22852288
| Ast.TY_named _ -> bug () "named type in referent_type"
22862289
| Ast.TY_constrained (t, _) -> recur t
2290+
in
2291+
htab_search_or_add cx.ctxt_rty_cache t calculate
2292+
22872293

22882294
and slot_referent_type (cx:ctxt) (sl:Ast.slot) : Il.referent_ty =
22892295
let s t = Il.ScalarTy t in

0 commit comments

Comments
 (0)