Skip to content

Commit

Permalink
fix bugs when search used id in lambda that has been shadowed
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunsong committed Dec 18, 2014
1 parent 1b91c6e commit 08c2ded
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/optimization/ljs_less_mutation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/optimization/test/less_mutation_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 08c2ded

Please sign in to comment.