From 08c2ded72b025e24bef41567213fc04ac6821784 Mon Sep 17 00:00:00 2001 From: lijunsong Date: Wed, 17 Dec 2014 21:49:54 -0500 Subject: [PATCH] fix bugs when search used id in lambda that has been shadowed --- src/optimization/ljs_less_mutation.ml | 4 +++- src/optimization/test/less_mutation_test.ml | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/optimization/ljs_less_mutation.ml b/src/optimization/ljs_less_mutation.ml index 03722b16..e107c6df 100644 --- a/src/optimization/ljs_less_mutation.ml +++ b/src/optimization/ljs_less_mutation.ml @@ -281,8 +281,10 @@ let id_used_in_env_lambda x env : bool = | Id (_, id) when in_lambda -> id = x | SetBang (_, id, v) when in_lambda -> id = x || search_id ~in_lambda x v | Lambda (_, xs, body) -> - if List.mem x xs then search_id ~in_lambda:false x body + if List.mem x xs then false else search_id ~in_lambda:true x body + | Let (_, letx, _, _) when letx = x -> false + | Rec (_, recx, _, _) when recx = x -> false | _ -> List.exists (fun e->search_id ~in_lambda x e) (child_exps exp) in diff --git a/src/optimization/test/less_mutation_test.ml b/src/optimization/test/less_mutation_test.ml index 57f8581a..2ea3ef8d 100644 --- a/src/optimization/test/less_mutation_test.ml +++ b/src/optimization/test/less_mutation_test.ml @@ -14,6 +14,14 @@ let suite = "let (x = 2) let (y=x) y" ); + "lift assignment" >:: + (cmp + "let (x = 1) + {x := 2; x}" + "let (x = 1) + let (x = 2) + x"); + (* todo setbang and recursive function *) "setbang x and usage x are in different seq" >:: (no_change