From 4c53fa4ae66dce8ff97853127bd71d419b9fce77 Mon Sep 17 00:00:00 2001 From: Tom Jack Date: Wed, 19 Feb 2020 14:55:02 -0600 Subject: [PATCH] Fix non-tail fail avoidance --- src/passes/9-self_michelson/dune | 3 ++- src/passes/9-self_michelson/self_michelson.ml | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/passes/9-self_michelson/dune b/src/passes/9-self_michelson/dune index b7387bdc1..c5275ec70 100644 --- a/src/passes/9-self_michelson/dune +++ b/src/passes/9-self_michelson/dune @@ -6,7 +6,8 @@ tezos-utils ) (preprocess - (pps ppx_let bisect_ppx --conditional) + (pps ppx_let bisect_ppx --conditional ppx_expect) ) + (inline_tests) (flags (:standard -w +1..62-4-9-44-40-42-48-30@39@33 -open Simple_utils )) ) diff --git a/src/passes/9-self_michelson/self_michelson.ml b/src/passes/9-self_michelson/self_michelson.ml index 19fe58476..8a3291204 100644 --- a/src/passes/9-self_michelson/self_michelson.ml +++ b/src/passes/9-self_michelson/self_michelson.ml @@ -382,14 +382,28 @@ let rec opt_tail_fail : michelson -> michelson = let rec aux args = match args with | [] -> [] - | arg :: _ when is_failing arg -> [arg] - | arg :: args -> arg :: aux args in - let args = aux args in - Seq (l, List.map opt_tail_fail args) + | arg :: args -> + let arg = opt_tail_fail arg in + if is_failing arg + then [arg] + else arg :: aux args in + Seq (l, aux args) | Prim (l, p, args, annot) -> Prim (l, p, List.map opt_tail_fail args, annot) | x -> x +let%expect_test _ = + let seq args = Seq(-1, args) in + let prim p args = Prim(-1, p, args, []) in + let code = seq [ prim I_IF_LEFT [ seq [ prim I_FAILWITH [] ; prim I_DROP [] ] + ; seq [ prim I_FAILWITH [] ; prim I_DROP [] ] + ] + ; prim I_DROP [] + ] in + let code = opt_tail_fail code in + Format.printf "%a" Tezos_utils.Michelson.pp code ; + [%expect {| { IF_LEFT { FAILWITH } { FAILWITH } } |}] + let rec opt_combine_drops (x : michelson) : michelson = let rec combine : michelson list -> michelson list = function | [] -> []