From 784c2da81b980a41177e41fb6ff43dad437009f7 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 6 Feb 2020 18:06:36 +0100 Subject: [PATCH 1/2] Remove useless constants: * C_HASH (removed) * C_MAP_GET --replaced--> C_MAP_FIND_OPT * C_MAP_GET_FORCE --replaced--> C_MAP_FIND --- src/bin/expect_tests/contract_tests.ml | 20 ++++++++++---------- src/passes/6-transpiler/transpiler.ml | 2 +- src/passes/7-self_mini_c/self_mini_c.ml | 4 ++-- src/passes/operators/operators.ml | 21 ++------------------- src/stages/common/PP.ml | 3 --- src/stages/common/types.ml | 3 --- 6 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 66a9b140b..cc0b054d2 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -7,13 +7,13 @@ let bad_contract basename = let%expect_test _ = run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ; - [%expect {| 2066 bytes |}] ; + [%expect {| 2062 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; [%expect {| 1093 bytes |}] ; 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" ] ; [%expect {| 642 bytes |}] ; @@ -86,7 +86,7 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; DUP ; CAR ; DIP { DUP ; CDR ; PUSH nat 1 ; ADD } ; @@ -168,7 +168,7 @@ let%expect_test _ = SWAP ; DIP { DUP ; CAR ; CDR } ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; DUP ; CAR ; SOURCE ; @@ -182,7 +182,7 @@ let%expect_test _ = CDR ; DIP { DIP { DUP } ; SWAP ; CAR ; CAR } ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; DUP ; CDR ; PUSH nat 1 ; @@ -262,7 +262,7 @@ let%expect_test _ = CAR ; DIP { DUP } ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; DUP ; CAR ; SOURCE ; @@ -488,7 +488,7 @@ let%expect_test _ = CAR ; SENDER ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; PUSH nat 1 ; ADD ; SOME ; @@ -529,7 +529,7 @@ let%expect_test _ = CAR ; SENDER ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; PUSH nat 1 ; ADD ; SOME ; @@ -572,7 +572,7 @@ let%expect_test _ = CAR ; SENDER ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; DUP ; DIP { DIP 4 { DUP } ; DIG 4 ; CAR ; CDR ; CAR } ; COMPARE ; @@ -768,7 +768,7 @@ let%expect_test _ = CAR ; SENDER ; GET ; - IF_NONE { PUSH string "GET_FORCE" ; FAILWITH } {} ; + IF_NONE { PUSH string "MAP FIND" ; FAILWITH } {} ; PUSH nat 1 ; SWAP ; SUB ; diff --git a/src/passes/6-transpiler/transpiler.ml b/src/passes/6-transpiler/transpiler.ml index 86c921c70..162231e7e 100644 --- a/src/passes/6-transpiler/transpiler.ml +++ b/src/passes/6-transpiler/transpiler.ml @@ -490,7 +490,7 @@ and transpile_annotated_expression (ae:AST.annotated_expression) : expression re ) | E_look_up dsi -> ( 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) -> ( let%bind a' = transpile_annotated_expression a in diff --git a/src/passes/7-self_mini_c/self_mini_c.ml b/src/passes/7-self_mini_c/self_mini_c.ml index 98bc0315c..7a12a9216 100644 --- a/src/passes/7-self_mini_c/self_mini_c.ml +++ b/src/passes/7-self_mini_c/self_mini_c.ml @@ -23,7 +23,7 @@ let is_pure_constant : constant -> bool = | C_NEG | C_OR | C_AND | C_XOR | C_NOT | C_EQ | C_NEQ | C_LT | C_LE | C_GT | C_GE | 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_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 @@ -34,7 +34,7 @@ let is_pure_constant : constant -> bool = | C_ADD | C_SUB |C_MUL|C_DIV|C_MOD (* impure: *) | C_ASSERTION | C_ASSERT_INFERRED - | C_MAP_GET_FORCE | C_MAP_FIND + | C_MAP_FIND | C_FOLD_WHILE | C_CALL (* TODO... *) diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 49f693030..fdeb599c2 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -66,7 +66,7 @@ module Simplify = struct module Pascaligo = struct let constants = function - | "get_force" -> ok C_MAP_GET_FORCE + | "get_force" -> ok C_MAP_FIND | "get_chain_id" -> ok C_CHAIN_ID | "transaction" -> ok C_CALL | "get_contract" -> ok C_CONTRACT @@ -109,7 +109,7 @@ module Simplify = struct | "map_fold" -> ok C_MAP_FOLD | "map_remove" -> ok C_MAP_REMOVE | "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 | "sha_256" -> ok C_SHA256 | "sha_512" -> ok C_SHA512 @@ -163,7 +163,6 @@ module Simplify = struct | "Current.failwith" -> ok C_FAILWITH | "failwith" -> ok C_FAILWITH - | "Crypto.hash" -> ok C_HASH | "Crypto.blake2b" -> ok C_BLAKE2b | "Crypto.sha256" -> ok C_SHA256 | "Crypto.sha512" -> ok C_SHA512 @@ -424,8 +423,6 @@ module Typer = struct | C_LIST_FOLD -> ok @@ failwith "t_list_fold" ; | C_LIST_CONS -> ok @@ failwith "t_list_cons" ; (* 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_REMOVE -> ok @@ t_map_remove ; | C_MAP_UPDATE -> ok @@ t_map_update ; @@ -562,16 +559,6 @@ module Typer = struct let default = t_unit () in 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%bind () = assert_t_nat t in ok @@ t_int () @@ -1034,8 +1021,6 @@ module Typer = struct | C_LIST_FOLD -> ok @@ list_fold ; | C_LIST_CONS -> ok @@ list_cons ; (* MAP *) - | C_MAP_GET -> ok @@ map_get ; - | C_MAP_GET_FORCE -> ok @@ map_get_force ; | C_MAP_ADD -> ok @@ map_add ; | C_MAP_REMOVE -> ok @@ map_remove ; | C_MAP_UPDATE -> ok @@ map_update ; @@ -1115,9 +1100,7 @@ module Compiler = struct | C_GE -> ok @@ simple_binary @@ seq [prim I_COMPARE ; prim I_GE] | C_UPDATE -> ok @@ simple_ternary @@ prim I_UPDATE | 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_GET -> ok @@ simple_binary @@ prim I_GET | C_MAP_MEM -> ok @@ simple_binary @@ prim I_MEM | C_MAP_FIND_OPT -> ok @@ simple_binary @@ prim I_GET | C_MAP_ADD -> ok @@ simple_ternary @@ seq [dip (i_some) ; prim I_UPDATE] diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index 773b5eaab..a47965e57 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -82,8 +82,6 @@ let constant ppf : constant -> unit = function | C_MAP -> fprintf ppf "MAP" | C_MAP_EMPTY -> fprintf ppf "MAP_EMPTY" | 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_REMOVE -> fprintf ppf "MAP_REMOVE" | C_MAP_UPDATE -> fprintf ppf "MAP_UPDATE" @@ -101,7 +99,6 @@ let constant ppf : constant -> unit = function | C_SHA256 -> fprintf ppf "SHA256" | C_SHA512 -> fprintf ppf "SHA512" | C_BLAKE2b -> fprintf ppf "BLAKE2b" - | C_HASH -> fprintf ppf "HASH" | C_HASH_KEY -> fprintf ppf "HASH_KEY" | C_CHECK_SIGNATURE -> fprintf ppf "CHECK_SIGNATURE" | C_CHAIN_ID -> fprintf ppf "CHAIN_ID" diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index a0c6f9cb6..1d65e14d5 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -199,8 +199,6 @@ type constant = | C_MAP | C_MAP_EMPTY | C_MAP_LITERAL - | C_MAP_GET - | C_MAP_GET_FORCE | C_MAP_ADD | C_MAP_REMOVE | C_MAP_UPDATE @@ -218,7 +216,6 @@ type constant = | C_SHA256 | C_SHA512 | C_BLAKE2b - | C_HASH | C_HASH_KEY | C_CHECK_SIGNATURE | C_CHAIN_ID From 78693b482c511f2e5814ecc3d24aade2de5c96c2 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 6 Feb 2020 18:12:44 +0100 Subject: [PATCH 2/2] remove unused test --- src/test/contracts/new-syntax.mligo | 19 ------------------- src/test/integration_tests.ml | 7 ------- 2 files changed, 26 deletions(-) delete mode 100644 src/test/contracts/new-syntax.mligo diff --git a/src/test/contracts/new-syntax.mligo b/src/test/contracts/new-syntax.mligo deleted file mode 100644 index 9f318f2d1..000000000 --- a/src/test/contracts/new-syntax.mligo +++ /dev/null @@ -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 diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 204d2fc55..247832641 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1458,12 +1458,6 @@ let assert_religo () : unit result = let%bind _ = expect_eq program "main" (make_input true) make_expected in 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%bind program = type_file "./contracts/guess_string.mligo" 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 (religo)" religo_list ; - (* test "guess the hash mligo" guess_the_hash_mligo ; WIP? *) test "failwith ligo" failwith_ligo ; test "failwith mligo" failwith_mligo ; test "assert mligo" assert_mligo ;