Merge branch 'feature/subtler-nontail-fail' into 'dev'

Fix non-tail fail avoidance

See merge request ligolang/ligo!438
This commit is contained in:
Rémi Lesenechal 2020-02-21 13:50:25 +00:00
commit 040ed8b6ff
2 changed files with 20 additions and 5 deletions

View File

@ -6,7 +6,8 @@
tezos-utils tezos-utils
) )
(preprocess (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 )) (flags (:standard -w +1..62-4-9-44-40-42-48-30@39@33 -open Simple_utils ))
) )

View File

@ -382,14 +382,28 @@ let rec opt_tail_fail : michelson -> michelson =
let rec aux args = let rec aux args =
match args with match args with
| [] -> [] | [] -> []
| arg :: _ when is_failing arg -> [arg] | arg :: args ->
| arg :: args -> arg :: aux args in let arg = opt_tail_fail arg in
let args = aux args in if is_failing arg
Seq (l, List.map opt_tail_fail args) then [arg]
else arg :: aux args in
Seq (l, aux args)
| Prim (l, p, args, annot) -> | Prim (l, p, args, annot) ->
Prim (l, p, List.map opt_tail_fail args, annot) Prim (l, p, List.map opt_tail_fail args, annot)
| x -> x | 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 opt_combine_drops (x : michelson) : michelson =
let rec combine : michelson list -> michelson list = function let rec combine : michelson list -> michelson list = function
| [] -> [] | [] -> []