Mini_c: Identify more pure constants

This commit is contained in:
Tom Jack 2019-11-25 18:10:49 -06:00
parent 66d2cda107
commit 06603b594a
2 changed files with 53 additions and 49 deletions

View File

@ -5,7 +5,7 @@ let contract basename =
let%expect_test _ = let%expect_test _ =
run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ;
[%expect {| 2068 bytes |}] ; [%expect {| 2066 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ;
[%expect {| 1093 bytes |}] ; [%expect {| 1093 bytes |}] ;
@ -14,7 +14,7 @@ let%expect_test _ =
[%expect {| 627 bytes |}] ; [%expect {| 627 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
[%expect {| 714 bytes |}] ; [%expect {| 628 bytes |}] ;
() ()
@ -204,10 +204,9 @@ let%expect_test _ =
NIL operation ; NIL operation ;
SWAP ; SWAP ;
CONS ; CONS ;
DUP ; DIP { DIP 7 { DUP } ; DIG 7 } ;
DIP { DIP 8 { DUP } ; DIG 8 } ;
PAIR ; PAIR ;
DIP { DROP 12 } } ; DIP { DROP 11 } } ;
DIP { DROP } } DIP { DROP } }
{ DUP ; { DUP ;
DIP { DIP { DUP } ; SWAP } ; DIP { DIP { DUP } ; SWAP } ;
@ -482,7 +481,10 @@ let%expect_test _ =
CAR ; CAR ;
IF_LEFT IF_LEFT
{ DUP ; { DUP ;
PUSH int 0 ; DUP ;
CAR ;
CAR ;
DIP { PUSH int 0 ;
SOME ; SOME ;
DIP { PUSH int 0 ; DIP { PUSH int 0 ;
SOME ; SOME ;
@ -491,26 +493,16 @@ let%expect_test _ =
PUSH string "Yes" ; PUSH string "Yes" ;
UPDATE } ; UPDATE } ;
PUSH string "No" ; PUSH string "No" ;
UPDATE ; UPDATE } ;
DIP { DUP } ;
SWAP ;
CAR ;
CAR ;
DIP { DUP } ;
PAIR ; PAIR ;
DIP { DIP { DUP } ; DIP { DUP ; CAR ; CDR ; DIP { DUP ; CDR } ; PAIR } ;
SWAP ;
CAR ;
CDR ;
DIP { DIP { DUP } ; SWAP ; CDR } ;
PAIR } ;
PAIR ; PAIR ;
EMPTY_SET address ; EMPTY_SET address ;
SWAP ; SWAP ;
PAIR ; PAIR ;
NIL operation ; NIL operation ;
PAIR ; PAIR ;
DIP { DROP 3 } } DIP { DROP 2 } }
{ DUP ; { DUP ;
DIP { DIP { DUP } ; SWAP ; CDR } ; DIP { DIP { DUP } ; SWAP ; CDR } ;
PAIR ; PAIR ;
@ -519,41 +511,36 @@ let%expect_test _ =
DIP { DUP } ; DIP { DUP } ;
SWAP ; SWAP ;
CDR ; CDR ;
NOW ; DIP { DUP } ;
SOURCE ; SWAP ;
DIP 3 { DUP } ; DIP { DUP ; CAR ; CAR ; CDR } ;
DIG 3 ;
DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR ; CDR } ;
GET ; GET ;
IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DIP 3 { DUP } ; DIP { DUP } ;
DIG 3 ; SWAP ;
CAR ; CAR ;
CAR ; CAR ;
CAR ; CAR ;
DIP { DIP 4 { DUP } ; DIP { DIP 2 { DUP } ;
DIG 4 ; DIG 2 ;
DIP { DUP ; DIP { DUP ;
PUSH int 1 ; PUSH int 1 ;
ADD ; ADD ;
SOME ; SOME ;
DIP { DIP 3 { DUP } ; DIG 3 ; CAR ; CAR ; CDR } } ; DIP { DIP { DUP } ; SWAP ; CAR ; CAR ; CDR } } ;
UPDATE } ; UPDATE } ;
PAIR ; PAIR ;
DIP { DIP 3 { DUP } ;
DIG 3 ;
CAR ;
CDR ;
CAR ;
DIP { DIP 3 { DUP } ; DIG 3 ; CAR ; CDR ; CDR } ;
PAIR } ;
PAIR ;
DIP { DIP { DUP } ; DIP { DIP { DUP } ;
SWAP ; SWAP ;
DIP { DIP 3 { DUP } ; DIG 3 ; CDR ; PUSH bool True } ; CAR ;
UPDATE } ; CDR ;
CAR ;
DIP { DIP { DUP } ; SWAP ; CAR ; CDR ; CDR } ;
PAIR } ;
PAIR ;
DIP { DIP { DUP } ; SWAP ; CDR ; PUSH bool True ; SOURCE ; UPDATE } ;
PAIR ; PAIR ;
NIL operation ; NIL operation ;
PAIR ; PAIR ;
DIP { DROP 7 } } ; DIP { DROP 5 } } ;
DIP { DROP } } } |}] DIP { DROP } } } |}]

View File

@ -17,12 +17,29 @@ let map_expression :
assuming arguments are pure *) assuming arguments are pure *)
let is_pure_constant : string -> bool = let is_pure_constant : string -> bool =
function function
| "CAR" | "UNIT"
| "CDR" | "CAR" | "CDR" | "PAIR"
| "PAIR" | "NIL" | "CONS"
| "NEG" | "OR" | "AND" | "XOR" | "NOT"
| "EQ" | "NEQ" | "LT" | "LE" | "GT" | "GE"
| "SOME"
| "UPDATE" | "MAP_GET" | "MAP_FIND_OPT" | "MAP_ADD" | "MAP_UPDATE"
| "INT" | "ABS" | "ISNAT"
| "BALANCE" | "AMOUNT" | "ADDRESS" | "NOW" | "SOURCE" | "SENDER" | "CHAIN_ID"
| "SET_MEM" | "SET_ADD" | "SET_REMOVE" | "SLICE"
| "SHA256" | "SHA512" | "BLAKE2B" | "CHECK_SIGNATURE"
| "HASH_KEY" | "PACK" | "CONCAT"
-> true -> true
(* unfortunately impure: *)
| "ADD"|"SUB"|"TIMES"|"DIV"|"MOD"
(* impure: *)
| "ASSERT" | "ASSERT_INFERRED"
| "MAP_GET_FORCE" | "MAP_FIND"
| "FOLD_WHILE"
| "CALL"
(* TODO... *) (* TODO... *)
| _ -> false | _
-> false
let rec is_pure : expression -> bool = fun e -> let rec is_pure : expression -> bool = fun e ->
match e.content with match e.content with