Merge branch 'feature/remove-useless-constants' into 'dev'

Remove useless constants

See merge request ligolang/ligo!388
This commit is contained in:
Rémi Lesenechal 2020-02-06 21:26:04 +00:00
commit 8003a9e2b1
8 changed files with 15 additions and 64 deletions

View File

@ -7,13 +7,13 @@ let bad_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 {| 2066 bytes |}] ; [%expect {| 2062 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 |}] ;
run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ;
[%expect {| 2717 bytes |}] ; [%expect {| 2713 bytes |}] ;
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
[%expect {| 642 bytes |}] ; [%expect {| 642 bytes |}] ;
@ -86,7 +86,7 @@ let%expect_test _ =
SWAP ; SWAP ;
DIP { DUP ; CAR ; CAR } ; DIP { DUP ; CAR ; CAR } ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DUP ; DUP ;
CAR ; CAR ;
DIP { DUP ; CDR ; PUSH nat 1 ; ADD } ; DIP { DUP ; CDR ; PUSH nat 1 ; ADD } ;
@ -168,7 +168,7 @@ let%expect_test _ =
SWAP ; SWAP ;
DIP { DUP ; CAR ; CDR } ; DIP { DUP ; CAR ; CDR } ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DUP ; DUP ;
CAR ; CAR ;
SOURCE ; SOURCE ;
@ -182,7 +182,7 @@ let%expect_test _ =
CDR ; CDR ;
DIP { DIP { DUP } ; SWAP ; CAR ; CAR } ; DIP { DIP { DUP } ; SWAP ; CAR ; CAR } ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DUP ; DUP ;
CDR ; CDR ;
PUSH nat 1 ; PUSH nat 1 ;
@ -262,7 +262,7 @@ let%expect_test _ =
CAR ; CAR ;
DIP { DUP } ; DIP { DUP } ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DUP ; DUP ;
CAR ; CAR ;
SOURCE ; SOURCE ;
@ -488,7 +488,7 @@ let%expect_test _ =
CAR ; CAR ;
SENDER ; SENDER ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
PUSH nat 1 ; PUSH nat 1 ;
ADD ; ADD ;
SOME ; SOME ;
@ -529,7 +529,7 @@ let%expect_test _ =
CAR ; CAR ;
SENDER ; SENDER ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
PUSH nat 1 ; PUSH nat 1 ;
ADD ; ADD ;
SOME ; SOME ;
@ -572,7 +572,7 @@ let%expect_test _ =
CAR ; CAR ;
SENDER ; SENDER ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
DUP ; DUP ;
DIP { DIP 4 { DUP } ; DIG 4 ; CAR ; CDR ; CAR } ; DIP { DIP 4 { DUP } ; DIG 4 ; CAR ; CDR ; CAR } ;
COMPARE ; COMPARE ;
@ -768,7 +768,7 @@ let%expect_test _ =
CAR ; CAR ;
SENDER ; SENDER ;
GET ; GET ;
IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ;
PUSH nat 1 ; PUSH nat 1 ;
SWAP ; SWAP ;
SUB ; SUB ;

View File

@ -490,7 +490,7 @@ and transpile_annotated_expression (ae:AST.annotated_expression) : expression re
) )
| E_look_up dsi -> ( | E_look_up dsi -> (
let%bind (ds', i') = bind_map_pair f dsi in let%bind (ds', i') = bind_map_pair f dsi in
return @@ E_constant (C_MAP_GET, [i' ; ds']) return @@ E_constant (C_MAP_FIND_OPT, [i' ; ds'])
) )
| E_sequence (a , b) -> ( | E_sequence (a , b) -> (
let%bind a' = transpile_annotated_expression a in let%bind a' = transpile_annotated_expression a in

View File

@ -23,7 +23,7 @@ let is_pure_constant : constant -> bool =
| C_NEG | C_OR | C_AND | C_XOR | C_NOT | C_NEG | C_OR | C_AND | C_XOR | C_NOT
| C_EQ | C_NEQ | C_LT | C_LE | C_GT | C_GE | C_EQ | C_NEQ | C_LT | C_LE | C_GT | C_GE
| C_SOME | C_SOME
| C_UPDATE | C_MAP_GET | C_MAP_FIND_OPT | C_MAP_ADD | C_MAP_UPDATE | C_UPDATE | C_MAP_FIND_OPT | C_MAP_ADD | C_MAP_UPDATE
| C_INT | C_ABS | C_IS_NAT | C_INT | C_ABS | C_IS_NAT
| C_BALANCE | C_AMOUNT | C_ADDRESS | C_NOW | C_SOURCE | C_SENDER | C_CHAIN_ID | C_BALANCE | C_AMOUNT | C_ADDRESS | C_NOW | C_SOURCE | C_SENDER | C_CHAIN_ID
| C_SET_MEM | C_SET_ADD | C_SET_REMOVE | C_SLICE | C_SET_MEM | C_SET_ADD | C_SET_REMOVE | C_SLICE
@ -34,7 +34,7 @@ let is_pure_constant : constant -> bool =
| C_ADD | C_SUB |C_MUL|C_DIV|C_MOD | C_ADD | C_SUB |C_MUL|C_DIV|C_MOD
(* impure: *) (* impure: *)
| C_ASSERTION | C_ASSERT_INFERRED | C_ASSERTION | C_ASSERT_INFERRED
| C_MAP_GET_FORCE | C_MAP_FIND | C_MAP_FIND
| C_FOLD_WHILE | C_FOLD_WHILE
| C_CALL | C_CALL
(* TODO... *) (* TODO... *)

View File

@ -66,7 +66,7 @@ module Simplify = struct
module Pascaligo = struct module Pascaligo = struct
let constants = function let constants = function
| "get_force" -> ok C_MAP_GET_FORCE | "get_force" -> ok C_MAP_FIND
| "get_chain_id" -> ok C_CHAIN_ID | "get_chain_id" -> ok C_CHAIN_ID
| "transaction" -> ok C_CALL | "transaction" -> ok C_CALL
| "get_contract" -> ok C_CONTRACT | "get_contract" -> ok C_CONTRACT
@ -109,7 +109,7 @@ module Simplify = struct
| "map_fold" -> ok C_MAP_FOLD | "map_fold" -> ok C_MAP_FOLD
| "map_remove" -> ok C_MAP_REMOVE | "map_remove" -> ok C_MAP_REMOVE
| "map_update" -> ok C_MAP_UPDATE | "map_update" -> ok C_MAP_UPDATE
| "map_get" -> ok C_MAP_GET | "map_get" -> ok C_MAP_FIND_OPT
| "map_mem" -> ok C_MAP_MEM | "map_mem" -> ok C_MAP_MEM
| "sha_256" -> ok C_SHA256 | "sha_256" -> ok C_SHA256
| "sha_512" -> ok C_SHA512 | "sha_512" -> ok C_SHA512
@ -163,7 +163,6 @@ module Simplify = struct
| "Current.failwith" -> ok C_FAILWITH | "Current.failwith" -> ok C_FAILWITH
| "failwith" -> ok C_FAILWITH | "failwith" -> ok C_FAILWITH
| "Crypto.hash" -> ok C_HASH
| "Crypto.blake2b" -> ok C_BLAKE2b | "Crypto.blake2b" -> ok C_BLAKE2b
| "Crypto.sha256" -> ok C_SHA256 | "Crypto.sha256" -> ok C_SHA256
| "Crypto.sha512" -> ok C_SHA512 | "Crypto.sha512" -> ok C_SHA512
@ -425,8 +424,6 @@ module Typer = struct
| C_LIST_FOLD -> ok @@ failwith "t_list_fold" ; | C_LIST_FOLD -> ok @@ failwith "t_list_fold" ;
| C_LIST_CONS -> ok @@ failwith "t_list_cons" ; | C_LIST_CONS -> ok @@ failwith "t_list_cons" ;
(* MAP *) (* MAP *)
| C_MAP_GET -> ok @@ failwith "t_map_get" ;
| C_MAP_GET_FORCE -> ok @@ failwith "t_map_get_force" ;
| C_MAP_ADD -> ok @@ t_map_add ; | C_MAP_ADD -> ok @@ t_map_add ;
| C_MAP_REMOVE -> ok @@ t_map_remove ; | C_MAP_REMOVE -> ok @@ t_map_remove ;
| C_MAP_UPDATE -> ok @@ t_map_update ; | C_MAP_UPDATE -> ok @@ t_map_update ;
@ -563,16 +560,6 @@ module Typer = struct
let default = t_unit () in let default = t_unit () in
ok @@ Simple_utils.Option.unopt ~default opt ok @@ Simple_utils.Option.unopt ~default opt
let map_get_force = typer_2 "MAP_GET_FORCE" @@ fun i m ->
let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) m in
let%bind _ = assert_type_value_eq (src, i) in
ok dst
let map_get = typer_2 "MAP_GET" @@ fun i m ->
let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) m in
let%bind _ = assert_type_value_eq (src, i) in
ok @@ t_option dst ()
let int : typer = typer_1 "INT" @@ fun t -> let int : typer = typer_1 "INT" @@ fun t ->
let%bind () = assert_t_nat t in let%bind () = assert_t_nat t in
ok @@ t_int () ok @@ t_int ()
@ -1035,8 +1022,6 @@ module Typer = struct
| C_LIST_FOLD -> ok @@ list_fold ; | C_LIST_FOLD -> ok @@ list_fold ;
| C_LIST_CONS -> ok @@ list_cons ; | C_LIST_CONS -> ok @@ list_cons ;
(* MAP *) (* MAP *)
| C_MAP_GET -> ok @@ map_get ;
| C_MAP_GET_FORCE -> ok @@ map_get_force ;
| C_MAP_ADD -> ok @@ map_add ; | C_MAP_ADD -> ok @@ map_add ;
| C_MAP_REMOVE -> ok @@ map_remove ; | C_MAP_REMOVE -> ok @@ map_remove ;
| C_MAP_UPDATE -> ok @@ map_update ; | C_MAP_UPDATE -> ok @@ map_update ;
@ -1116,9 +1101,7 @@ module Compiler = struct
| C_GE -> ok @@ simple_binary @@ seq [prim I_COMPARE ; prim I_GE] | C_GE -> ok @@ simple_binary @@ seq [prim I_COMPARE ; prim I_GE]
| C_UPDATE -> ok @@ simple_ternary @@ prim I_UPDATE | C_UPDATE -> ok @@ simple_ternary @@ prim I_UPDATE
| C_SOME -> ok @@ simple_unary @@ prim I_SOME | C_SOME -> ok @@ simple_unary @@ prim I_SOME
| C_MAP_GET_FORCE -> ok @@ simple_binary @@ seq [prim I_GET ; i_assert_some_msg (i_push_string "GET_FORCE")]
| C_MAP_FIND -> ok @@ simple_binary @@ seq [prim I_GET ; i_assert_some_msg (i_push_string "MAP FIND")] | C_MAP_FIND -> ok @@ simple_binary @@ seq [prim I_GET ; i_assert_some_msg (i_push_string "MAP FIND")]
| C_MAP_GET -> ok @@ simple_binary @@ prim I_GET
| C_MAP_MEM -> ok @@ simple_binary @@ prim I_MEM | C_MAP_MEM -> ok @@ simple_binary @@ prim I_MEM
| C_MAP_FIND_OPT -> ok @@ simple_binary @@ prim I_GET | C_MAP_FIND_OPT -> ok @@ simple_binary @@ prim I_GET
| C_MAP_ADD -> ok @@ simple_ternary @@ seq [dip (i_some) ; prim I_UPDATE] | C_MAP_ADD -> ok @@ simple_ternary @@ seq [dip (i_some) ; prim I_UPDATE]

View File

@ -82,8 +82,6 @@ let constant ppf : constant -> unit = function
| C_MAP -> fprintf ppf "MAP" | C_MAP -> fprintf ppf "MAP"
| C_MAP_EMPTY -> fprintf ppf "MAP_EMPTY" | C_MAP_EMPTY -> fprintf ppf "MAP_EMPTY"
| C_MAP_LITERAL -> fprintf ppf "MAP_LITERAL" | C_MAP_LITERAL -> fprintf ppf "MAP_LITERAL"
| C_MAP_GET -> fprintf ppf "MAP_GET"
| C_MAP_GET_FORCE -> fprintf ppf "MAP_GET_FORCE"
| C_MAP_ADD -> fprintf ppf "MAP_ADD" | C_MAP_ADD -> fprintf ppf "MAP_ADD"
| C_MAP_REMOVE -> fprintf ppf "MAP_REMOVE" | C_MAP_REMOVE -> fprintf ppf "MAP_REMOVE"
| C_MAP_UPDATE -> fprintf ppf "MAP_UPDATE" | C_MAP_UPDATE -> fprintf ppf "MAP_UPDATE"
@ -101,7 +99,6 @@ let constant ppf : constant -> unit = function
| C_SHA256 -> fprintf ppf "SHA256" | C_SHA256 -> fprintf ppf "SHA256"
| C_SHA512 -> fprintf ppf "SHA512" | C_SHA512 -> fprintf ppf "SHA512"
| C_BLAKE2b -> fprintf ppf "BLAKE2b" | C_BLAKE2b -> fprintf ppf "BLAKE2b"
| C_HASH -> fprintf ppf "HASH"
| C_HASH_KEY -> fprintf ppf "HASH_KEY" | C_HASH_KEY -> fprintf ppf "HASH_KEY"
| C_CHECK_SIGNATURE -> fprintf ppf "CHECK_SIGNATURE" | C_CHECK_SIGNATURE -> fprintf ppf "CHECK_SIGNATURE"
| C_CHAIN_ID -> fprintf ppf "CHAIN_ID" | C_CHAIN_ID -> fprintf ppf "CHAIN_ID"

View File

@ -199,8 +199,6 @@ type constant =
| C_MAP | C_MAP
| C_MAP_EMPTY | C_MAP_EMPTY
| C_MAP_LITERAL | C_MAP_LITERAL
| C_MAP_GET
| C_MAP_GET_FORCE
| C_MAP_ADD | C_MAP_ADD
| C_MAP_REMOVE | C_MAP_REMOVE
| C_MAP_UPDATE | C_MAP_UPDATE
@ -218,7 +216,6 @@ type constant =
| C_SHA256 | C_SHA256
| C_SHA512 | C_SHA512
| C_BLAKE2b | C_BLAKE2b
| C_HASH
| C_HASH_KEY | C_HASH_KEY
| C_CHECK_SIGNATURE | C_CHECK_SIGNATURE
| C_CHAIN_ID | C_CHAIN_ID

View File

@ -1,19 +0,0 @@
type storage = {
challenge : string;
}
type param = {
new_challenge : string;
attempt : bytes;
}
let attempt (p: param) storage =
if Crypto.hash (Bytes.pack p.attempt) <> Bytes.pack storage.challenge
then failwith "Failed challenge"
else
let contract : unit contract =
Operation.get_contract sender in
let transfer : operation =
Operation.transaction (unit, contract, 10tz) in
let storage : storage = {challenge = p.new_challenge}
in ([] : operation list), storage

View File

@ -1458,12 +1458,6 @@ let assert_religo () : unit result =
let%bind _ = expect_eq program "main" (make_input true) make_expected in let%bind _ = expect_eq program "main" (make_input true) make_expected in
ok () ok ()
let guess_the_hash_mligo () : unit result =
let%bind program = mtype_file "./contracts/new-syntax.mligo" in
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
expect_eq_n program "main" make_input make_expected
let guess_string_mligo () : unit result = let guess_string_mligo () : unit result =
let%bind program = type_file "./contracts/guess_string.mligo" in let%bind program = type_file "./contracts/guess_string.mligo" in
let make_input = fun n -> e_pair (e_int n) (e_int 42) in let make_input = fun n -> e_pair (e_int n) (e_int 42) in
@ -2314,7 +2308,6 @@ let main = test_suite "Integration (End to End)" [
(* test "list matching (mligo)" mligo_list ; *) (* test "list matching (mligo)" mligo_list ; *)
test "list matching (mligo)" mligo_list ; test "list matching (mligo)" mligo_list ;
test "list matching (religo)" religo_list ; test "list matching (religo)" religo_list ;
(* test "guess the hash mligo" guess_the_hash_mligo ; WIP? *)
test "failwith ligo" failwith_ligo ; test "failwith ligo" failwith_ligo ;
test "failwith mligo" failwith_mligo ; test "failwith mligo" failwith_mligo ;
test "assert mligo" assert_mligo ; test "assert mligo" assert_mligo ;