Add optimisation to skip variable aliasings

This particularly of effect to the code introduced by closure conversion.
This commit is contained in:
Louis Gesbert 2023-12-19 15:02:58 +01:00
parent 7233ec403a
commit ea4e191f27
4 changed files with 6 additions and 20 deletions

View File

@ -207,8 +207,9 @@ let rec optimize_expr :
in
EMatch { e = arg; cases; name = n1 }
| EApp { f = EAbs { binder; _ }, _; args }
when binder_vars_used_at_most_once binder ->
(* beta reduction when variables not used. *)
when binder_vars_used_at_most_once binder
|| List.for_all (function EVar _, _ -> true | _ -> false) args ->
(* beta reduction when variables not used, and for variable aliases *)
Mark.remove (Bindlib.msubst binder (List.map fst args |> Array.of_list))
| EStructAccess { name; field; e = EStruct { name = name1; fields }, _ }
when StructName.equal name name1 ->

View File

@ -64,13 +64,7 @@ let scope S (S_in: S_in {x_in: bool}): S {z: integer} =
(handle_default_opt
[]
(λ (_: unit) → true)
(λ (_: unit) →
ESome
(let code_and_env :
((closure_env, integer) → integer * closure_env) =
f
in
code_and_env.0 code_and_env.1 -1)))
(λ (_: unit) → ESome (f.0 f.1 -1)))
with
| ENone _ → raise NoValueProvided
| ESome arg → arg

View File

@ -64,13 +64,7 @@ let scope T (T_in: T_in): T {y: integer} =
(handle_default_opt
[]
(λ (_: unit) → true)
(λ (_: unit) →
ESome
(let code_and_env :
((closure_env, integer) → integer * closure_env) =
s.f
in
code_and_env.0 code_and_env.1 2)))
(λ (_: unit) → ESome (s.f.0 s.f.1 2)))
with
| ENone _ → raise NoValueProvided
| ESome arg → arg

View File

@ -158,10 +158,7 @@ let scope Foo
let set b : bool =
match
(handle_default_opt
[
let code_and_env : ((any, unit) → eoption bool * any) = b in
code_and_env.0 code_and_env.1 ()
]
[b.0 b.1 ()]
(λ (_: unit) → true)
(λ (_: unit) →
ESome