Perform basic eta contraction in Self_mini_c

This commit is contained in:
Tom Jack 2020-04-08 19:11:01 -05:00
parent 11f4e6e3a6
commit 6acf91a3f2
2 changed files with 22 additions and 8 deletions

View File

@ -10,10 +10,10 @@ let%expect_test _ =
[%expect {| 1872 bytes |}] ; [%expect {| 1872 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ;
[%expect {| 1282 bytes |}] ; [%expect {| 1267 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ;
[%expect {| 2974 bytes |}] ; [%expect {| 2959 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
[%expect {| 589 bytes |}] ; [%expect {| 589 bytes |}] ;
@ -301,9 +301,6 @@ let%expect_test _ =
storage storage
(pair (pair (list %auth key) (nat %counter)) (pair (string %id) (nat %threshold))) ; (pair (pair (list %auth key) (nat %counter)) (pair (string %id) (nat %threshold))) ;
code { DUP ; code { DUP ;
CAR ;
DIP { DUP ; CDR } ;
PAIR ;
DUP ; DUP ;
CAR ; CAR ;
DIP { DUP } ; DIP { DUP } ;
@ -768,9 +765,6 @@ let%expect_test _ =
CAR ; CAR ;
PAIR } ; PAIR } ;
DUP ; DUP ;
CAR ;
DIP { DUP ; CDR } ;
PAIR ;
DIP { DROP 17 } } ; DIP { DROP 17 } } ;
DIP { DROP } } DIP { DROP } }
{ DUP ; { DUP ;

View File

@ -159,6 +159,25 @@ let betas : bool ref -> expression -> expression =
fun changed -> fun changed ->
map_expression (beta changed) map_expression (beta changed)
let eta : bool ref -> expression -> expression =
fun changed e ->
match e.content with
| E_constant {cons_name = C_PAIR; arguments = [ { content = E_constant {cons_name = C_CAR; arguments = [ e1 ]} ; type_value = _ } ;
{ content = E_constant {cons_name = C_CDR; arguments = [ e2 ]} ; type_value = _ }]} ->
(match (e1.content, e2.content) with
| E_variable x1, E_variable x2 ->
if Var.equal x1 x2
then
(changed := true;
{ e with content = e1.content })
else e
| _ -> e)
| _ -> e
let etas : bool ref -> expression -> expression =
fun changed ->
map_expression (eta changed)
let contract_check = let contract_check =
let all = [Michelson_restrictions.self_in_lambdas] in let all = [Michelson_restrictions.self_in_lambdas] in
let all_e = List.map Helpers.map_sub_level_expression all in let all_e = List.map Helpers.map_sub_level_expression all in
@ -169,6 +188,7 @@ let rec all_expression : expression -> expression =
let changed = ref false in let changed = ref false in
let e = inline_lets changed e in let e = inline_lets changed e in
let e = betas changed e in let e = betas changed e in
let e = etas changed e in
if !changed if !changed
then all_expression e then all_expression e
else e else e