Skip to content

Commit 63e1264

Browse files
committed
refactor
1 parent f083a74 commit 63e1264

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

ARM/optimizer.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,22 @@ let tweak arm n strict =
233233

234234
let cache = Hashtbl.create 10
235235
let rec tweak_with_cache id arm n strict =
236-
match Hashtbl.find_opt cache (id, arm, n, strict) with
236+
let key = (id, arm, n, strict) in
237+
match Hashtbl.find_opt cache key with
237238
| None ->
238-
begin try tweak arm n strict ; raise TweakingFailed
239+
begin try
240+
tweak arm n strict ;
241+
begin match Hashtbl.find_opt cache key with
242+
| None -> ()
243+
| Some (old_res, _, _) ->
244+
Hashtbl.replace cache key (
245+
old_res,
246+
(fun () -> ()),
247+
(fun () -> raise TweakingFailed))
248+
end ;
249+
raise TweakingFailed
239250
with effect (Yield'' res), k ->
240-
Hashtbl.replace cache (id, arm, n, strict) (
251+
Hashtbl.replace cache key (
241252
res,
242253
(fun () -> try Effect.Deep.discontinue k Exit |> ignore with Exit -> ()),
243254
(fun () -> Effect.Deep.continue k ())) ;

0 commit comments

Comments
 (0)