Skip to content

Commit

Permalink
Simplify hoisting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
msprotz committed Sep 9, 2024
1 parent e9b5977 commit 960b290
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/Simplify.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,23 +1028,15 @@ and hoist_stmt loc e =
nest lhs e.typ (mk (ELet (binder, e1, close_binder binder e2)))

| EIfThenElse (e1, e2, e3) ->
if e.typ = TUnit then
let lhs, e1 = hoist_expr loc Unspecified e1 in
let e2 = hoist_stmt loc e2 in
let e3 = hoist_stmt loc e3 in
nest lhs e.typ (mk (EIfThenElse (e1, e2, e3)))
else
let lhs, e = hoist_expr loc Unspecified e in
nest lhs e.typ e
let lhs, e1 = hoist_expr loc Unspecified e1 in
let e2 = hoist_stmt loc e2 in
let e3 = hoist_stmt loc e3 in
nest lhs e.typ (mk (EIfThenElse (e1, e2, e3)))

| ESwitch (e1, branches) ->
if e.typ = TUnit then
let lhs, e1 = hoist_expr loc Unspecified e1 in
let branches = List.map (fun (tag, e2) -> tag, hoist_stmt loc e2) branches in
nest lhs e.typ (mk (ESwitch (e1, branches)))
else
let lhs, e = hoist_expr loc Unspecified e in
nest lhs e.typ e
let lhs, e1 = hoist_expr loc Unspecified e1 in
let branches = List.map (fun (tag, e2) -> tag, hoist_stmt loc e2) branches in
nest lhs e.typ (mk (ESwitch (e1, branches)))

| EFor (binder, e1, e2, e3, e4) ->
assert (e.typ = TUnit);
Expand Down

0 comments on commit 960b290

Please sign in to comment.