Fix non-tail fail avoidance

This commit is contained in:
Tom Jack 2020-02-19 14:55:02 -06:00
parent ce4c2ee783
commit 4c53fa4ae6
2 changed files with 20 additions and 5 deletions

View File

@ -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 ))
)

View File

@ -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
| [] -> []