From 4cd3ec7cc3c14c1fa34add6914222f10930bfba6 Mon Sep 17 00:00:00 2001 From: adelaett <90894311+adelaett@users.noreply.github.com> Date: Tue, 28 Feb 2023 09:06:33 +0100 Subject: [PATCH] Add an optimization pass to remove struct access of struct constructor ie { e = x}.e -> x --- compiler/dcalc/optimizations.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/dcalc/optimizations.ml b/compiler/dcalc/optimizations.ml index e5332b8e..bff054c5 100644 --- a/compiler/dcalc/optimizations.ml +++ b/compiler/dcalc/optimizations.ml @@ -96,6 +96,9 @@ let rec partial_evaluation (ctx : partial_evaluation_ctx) (e : 'm expr) : | EApp { f = EAbs { binder; _ }, _; args } -> (* beta reduction *) Marked.unmark (Bindlib.msubst binder (List.map fst args |> Array.of_list)) + | EStructAccess { name; field; e = EStruct { name = name1; fields }, _ } + when name = name1 -> + Marked.unmark (StructField.Map.find field fields) | EDefault { excepts; just; cons } -> ( (* TODO: mechanically prove each of these optimizations correct :) *) let excepts =