Skip to content

Commit 97a6b09

Browse files
committed
More fold caches, cut rustc compile time by 60% again.
1 parent f1e2c37 commit 97a6b09

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/boot/me/semant.ml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ type ctxt =
188188
ctxt_curr_path: Ast.name_component Stack.t;
189189

190190
ctxt_rty_cache: (Ast.ty,Il.referent_ty) Hashtbl.t;
191+
192+
ctxt_type_effect_cache: (Ast.ty,Ast.effect) Hashtbl.t;
193+
ctxt_type_points_to_heap_cache: (Ast.ty,bool) Hashtbl.t;
194+
ctxt_type_is_structured_cache: (Ast.ty,bool) Hashtbl.t;
195+
ctxt_type_contains_chan_cache: (Ast.ty,bool) Hashtbl.t;
196+
ctxt_n_used_type_parameters_cache: (Ast.ty,int) Hashtbl.t;
191197
}
192198
;;
193199

@@ -277,7 +283,13 @@ let new_ctxt sess abi crate =
277283
ctxt_main_name = crate.Ast.crate_main;
278284

279285
ctxt_curr_path = Stack.create ();
280-
ctxt_rty_cache = Hashtbl.create 1024;
286+
287+
ctxt_rty_cache = Hashtbl.create 0;
288+
ctxt_type_effect_cache = Hashtbl.create 0;
289+
ctxt_type_points_to_heap_cache = Hashtbl.create 0;
290+
ctxt_type_is_structured_cache = Hashtbl.create 0;
291+
ctxt_type_contains_chan_cache = Hashtbl.create 0;
292+
ctxt_n_used_type_parameters_cache = Hashtbl.create 0;
281293
}
282294
;;
283295

@@ -1110,7 +1122,8 @@ let type_is_structured (cx:ctxt) (t:Ast.ty) : bool =
11101122
}
11111123

11121124
in
1113-
fold_ty cx fold t
1125+
htab_search_or_add cx.ctxt_type_is_structured_cache t
1126+
(fun _ -> fold_ty cx fold t)
11141127
;;
11151128

11161129

@@ -1128,7 +1141,8 @@ let type_points_to_heap (cx:ctxt) (t:Ast.ty) : bool =
11281141
ty_fold_task = (fun _ -> true);
11291142
}
11301143
in
1131-
fold_ty cx fold t
1144+
htab_search_or_add cx.ctxt_type_points_to_heap_cache t
1145+
(fun _ -> fold_ty cx fold t)
11321146
;;
11331147

11341148
(* Effect analysis. *)
@@ -1152,7 +1166,8 @@ let type_effect (cx:ctxt) (t:Ast.ty) : Ast.effect =
11521166
let fold_mutable _ = Ast.STATE in
11531167
let fold = associative_binary_op_ty_fold Ast.PURE lower_effect_of in
11541168
let fold = { fold with ty_fold_mutable = fold_mutable } in
1155-
fold_ty cx fold t
1169+
htab_search_or_add cx.ctxt_type_effect_cache t
1170+
(fun _ -> fold_ty cx fold t)
11561171
;;
11571172

11581173
let type_has_state (cx:ctxt) (t:Ast.ty) : bool =
@@ -1176,7 +1191,8 @@ let type_contains_chan (cx:ctxt) (t:Ast.ty) : bool =
11761191
let fold_chan _ = true in
11771192
let fold = ty_fold_bool_or false in
11781193
let fold = { fold with ty_fold_chan = fold_chan } in
1179-
fold_ty cx fold t
1194+
htab_search_or_add cx.ctxt_type_contains_chan_cache t
1195+
(fun _ -> fold_ty cx fold t)
11801196
;;
11811197

11821198

@@ -1214,7 +1230,8 @@ let n_used_type_params (cx:ctxt) t =
12141230
let fold_param (i,_) = i+1 in
12151231
let fold = ty_fold_int_max 0 in
12161232
let fold = { fold with ty_fold_param = fold_param } in
1217-
fold_ty cx fold t
1233+
htab_search_or_add cx.ctxt_n_used_type_parameters_cache t
1234+
(fun _ -> fold_ty cx fold t)
12181235
;;
12191236

12201237
let check_concrete params thing =

src/boot/me/trans.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,16 @@ let trans_visitor
595595
(ty, queue_to_arr q)
596596
in
597597

598+
let has_parametric_types_cache = Hashtbl.create 0 in
598599
let has_parametric_types (t:Ast.ty) : bool =
599600
let base = ty_fold_bool_or false in
600601
let ty_fold_param _ =
601602
true
602603
in
603604
let fold = { base with ty_fold_param = ty_fold_param } in
604-
fold_ty cx fold t
605+
htab_search_or_add
606+
has_parametric_types_cache t
607+
(fun _ -> fold_ty cx fold t)
605608
in
606609

607610
let rec calculate_sz (ty_params:Il.cell) (size:size) : Il.operand =

0 commit comments

Comments
 (0)