Skip to content

Commit

Permalink
Improve PureMicroPasses.filter_useless to simplify the matches
Browse files Browse the repository at this point in the history
  • Loading branch information
sonmarcho committed Dec 21, 2023
1 parent 0fb89f2 commit 6ee1063
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/PureMicroPasses.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1052,10 +1052,23 @@ let filter_useless (filter_monadic_calls : bool) (ctx : trans_ctx)
method! visit_expression env e =
match e with
| Var _ | CVar _ | Const _ | App _ | Qualif _
| Switch (_, _)
| Meta (_, _)
| StructUpdate _ | Lambda _ ->
super#visit_expression env e
| Switch (scrut, switch) -> (
match switch with
| If (_, _) -> super#visit_expression env e
| Match branches ->
(* Simplify the branches *)
let simplify_branch (br : match_branch) =
(* Compute the set of values used inside the branch *)
let branch, used = self#visit_texpression env br.branch in
(* Simplify the pattern *)
let pat, _ = filter_typed_pattern (used ()) br.pat in
{ pat; branch }
in
super#visit_expression env
(Switch (scrut, Match (List.map simplify_branch branches))))
| Let (monadic, lv, re, e) ->
(* Compute the set of values used in the next expression *)
let e, used = self#visit_texpression env e in
Expand Down

0 comments on commit 6ee1063

Please sign in to comment.