From d947f3b462fe95e74e9f67cbfef0802898e0fb3e Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 11 Oct 2019 12:38:00 -0700 Subject: [PATCH] Change set patch to chain calls and only use one assignment --- src/passes/2-simplify/pascaligo.ml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index 5dda856b1..d8ea7bc5c 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -806,15 +806,19 @@ and simpl_single_instruction : Raw.single_instr -> (_ -> expression result) resu in ok e) @@ pseq_to_list setp.set_inj.value.elements in let%bind expr = - let aux = fun (v) -> - e_assign name access_path (e_constant "SET_ADD" [v ; e_variable name]) in - let assigns = List.map aux inj in + let rec chain_add = fun lst s : expression -> + match lst with + | [] -> s + | hd :: tl -> chain_add tl (e_constant "SET_ADD" [hd ; s]) in + let assigns = + match inj with + | [] -> e_skip ~loc () + | _ :: _ -> chain_add inj (e_variable name) in match assigns with - | [] -> ok @@ e_skip ~loc () - | hd :: tl -> ( - let aux acc cur = e_sequence acc cur in - ok @@ List.fold_left aux hd tl - ) + | {expression = E_skip; _} -> ok @@ e_skip ~loc () + | {expression = E_constant e; location = loc} -> + ok @@ e_assign name access_path {expression = (E_constant e); location = loc} + | _ -> fail @@ corner_case ~loc:__LOC__ "Unexpected expression type" in return_statement @@ expr )