@@ -40,7 +40,7 @@ let unknown_apply = function
4040 | Let (_ , Apply { f = _ ; args = _ ; exact = false } ) -> true
4141 | _ -> false
4242
43- let specialize_apply opt_count function_arity ((acc , free_pc , extra ), loc ) i =
43+ let specialize_apply opt_count function_arity update_def ((acc , free_pc , extra ), loc ) i =
4444 match i with
4545 | Let (x , Apply { f; args; exact = false } ) -> (
4646 let n' = List. length args in
@@ -74,13 +74,13 @@ let specialize_apply opt_count function_arity ((acc, free_pc, extra), loc) i =
7474 ; branch = Return return'
7575 }
7676 in
77- ( Let (x, Closure (missing, (free_pc, missing), None )) :: acc
78- , free_pc + 1
79- , (free_pc, block) :: extra )
77+ let expr = Closure (missing, (free_pc, missing), None ) in
78+ update_def x expr;
79+ Let (x, expr) :: acc, free_pc + 1 , (free_pc, block) :: extra
8080 | Some _ -> assert false )
8181 | _ -> i :: acc, free_pc, extra
8282
83- let specialize_instrs ~function_arity opt_count p =
83+ let specialize_instrs ~function_arity ~ update_def opt_count p =
8484 let blocks, free_pc =
8585 Addr.Map. fold
8686 (fun pc block (blocks , free_pc ) ->
@@ -95,7 +95,7 @@ let specialize_instrs ~function_arity opt_count p =
9595 | Event loc ->
9696 let (body, free_pc, extra), _ = acc in
9797 (i :: body, free_pc, extra), Some loc
98- | _ -> specialize_apply opt_count function_arity acc i, None )
98+ | _ -> specialize_apply opt_count function_arity update_def acc i, None )
9999 in
100100 let blocks =
101101 List. fold_left extra ~init: blocks ~f: (fun blocks (pc , b ) ->
@@ -108,13 +108,15 @@ let specialize_instrs ~function_arity opt_count p =
108108 in
109109 { p with blocks; free_pc }
110110
111- let f ~function_arity p =
111+ let f ~function_arity ~ update_def p =
112112 Code. invariant p;
113113 let previous_p = p in
114114 let t = Timer. make () in
115115 let opt_count = ref 0 in
116116 let p =
117- if Config.Flag. optcall () then specialize_instrs ~function_arity opt_count p else p
117+ if Config.Flag. optcall ()
118+ then specialize_instrs ~function_arity ~update_def opt_count p
119+ else p
118120 in
119121 if times () then Format. eprintf " optcall: %a@." Timer. print t;
120122 if stats () then Format. eprintf " Stats - optcall: %d@." ! opt_count;
0 commit comments