From c5d9c9ffa37538a9b42a96ec8575b2f0fdc05b7a Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 16 Mar 2020 18:09:12 +0100 Subject: [PATCH 1/5] remove look_up --- src/passes/10-interpreter/interpreter.ml | 3 --- src/passes/10-transpiler/transpiler.ml | 5 ----- src/passes/6-sugar_to_core/sugar_to_core.ml | 4 ++-- src/passes/8-typer-new/typer.ml | 14 -------------- src/passes/8-typer-old/typer.ml | 8 -------- src/passes/9-self_ast_typed/helpers.ml | 11 ----------- src/passes/9-self_ast_typed/tail_recursion.ml | 4 ---- src/stages/3-ast_core/PP.ml | 2 -- src/stages/3-ast_core/combinators.ml | 1 - src/stages/3-ast_core/combinators.mli | 1 - src/stages/3-ast_core/misc.ml | 4 ++-- src/stages/3-ast_core/types.ml | 1 - src/stages/4-ast_typed/PP.ml | 2 -- src/stages/4-ast_typed/misc.ml | 3 +-- src/stages/4-ast_typed/misc_smart.ml | 3 --- src/stages/4-ast_typed/types.ml | 1 - src/stages/typesystem/misc.ml | 4 ---- 17 files changed, 5 insertions(+), 66 deletions(-) diff --git a/src/passes/10-interpreter/interpreter.ml b/src/passes/10-interpreter/interpreter.ml index 43e78312a..77d30cb71 100644 --- a/src/passes/10-interpreter/interpreter.ml +++ b/src/passes/10-interpreter/interpreter.ml @@ -378,9 +378,6 @@ and eval : Ast_typed.expression -> env -> value result ) | E_recursive {fun_name; fun_type=_; lambda} -> ok @@ V_Func_rec (fun_name, lambda.binder, lambda.result, env) - | E_look_up _ -> - let serr = Format.asprintf "Unsupported construct :\n %a\n" Ast_typed.PP.expression term in - simple_fail serr let dummy : Ast_typed.program -> string result = fun prg -> diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index b83e84bf6..b7935bbe4 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -234,7 +234,6 @@ and tree_of_sum : AST.type_expression -> (AST.constructor' * AST.type_expression and transpile_annotated_expression (ae:AST.expression) : expression result = let%bind tv = transpile_type ae.type_expression in let return ?(tv = tv) expr = ok @@ Combinators.Expression.make_tpl (expr, tv) in - let f = transpile_annotated_expression in let info = let title () = "translating expression" in let content () = Format.asprintf "%a" Location.pp ae.location in @@ -439,10 +438,6 @@ and transpile_annotated_expression (ae:AST.expression) : expression result = let init = return @@ E_make_empty_big_map (src, dst) in List.fold_left aux init m ) - | E_look_up dsi -> ( - let%bind (ds', i') = bind_map_pair f dsi in - return @@ E_constant {cons_name=C_MAP_FIND_OPT;arguments=[i' ; ds']} - ) | E_matching {matchee=expr; cases=m} -> ( let%bind expr' = transpile_annotated_expression expr in match m with diff --git a/src/passes/6-sugar_to_core/sugar_to_core.ml b/src/passes/6-sugar_to_core/sugar_to_core.ml index e75b9c2ff..e7a3f20fc 100644 --- a/src/passes/6-sugar_to_core/sugar_to_core.ml +++ b/src/passes/6-sugar_to_core/sugar_to_core.ml @@ -127,8 +127,8 @@ let rec compile_expression : I.expression -> O.expression result = let%bind set = bind_map_list compile_expression set in return @@ O.E_set set | I.E_look_up look_up -> - let%bind look_up = bind_map_pair compile_expression look_up in - return @@ O.E_look_up look_up + let%bind (path, index) = bind_map_pair compile_expression look_up in + return @@ O.E_constant {cons_name=C_MAP_FIND_OPT;arguments=[index;path]} | I.E_ascription {anno_expr; type_annotation} -> let%bind anno_expr = compile_expression anno_expr in let%bind type_annotation = idle_type_expression type_annotation in diff --git a/src/passes/8-typer-new/typer.ml b/src/passes/8-typer-new/typer.ml index f446c1076..94a1682bd 100644 --- a/src/passes/8-typer-new/typer.ml +++ b/src/passes/8-typer-new/typer.ml @@ -685,17 +685,6 @@ and type_expression : environment -> Solver.state -> ?tv_opt:O.type_expression - let wrapped = Wrap.application f'.type_expression args.type_expression in return_wrapped (E_application {lamb=f';args}) state'' wrapped - (* | E_look_up dsi -> - * let%bind (ds, ind) = bind_map_pair (type_expression e) dsi in - * let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) ds.type_annotation in - * let%bind _ = O.assert_type_value_eq (ind.type_annotation, src) in - * return (E_look_up (ds , ind)) (t_option dst ()) *) - - | E_look_up dsi -> - let aux' state' elt = type_expression e state' elt >>? swap in - let%bind (state'' , (ds , ind)) = bind_fold_map_pair aux' state dsi in - let wrapped = Wrap.look_up ds.type_expression ind.type_expression in - return_wrapped (E_look_up (ds , ind)) state'' wrapped (* Advanced *) (* | E_matching (ex, m) -> ( @@ -1076,9 +1065,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = | E_set lst -> let%bind lst' = bind_map_list untype_expression lst in return (e_set lst') - | E_look_up dsi -> - let%bind (a , b) = bind_map_pair untype_expression dsi in - return (e_look_up a b) | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index d26828230..2b6764dea 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -703,11 +703,6 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression lamb'.location in return (E_application {lamb=lamb'; args=args'}) tv - | E_look_up dsi -> - let%bind (ds, ind) = bind_map_pair (type_expression' e) dsi in - let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) ds.type_expression in - let%bind _ = O.assert_type_expression_eq (ind.type_expression, src) in - return (E_look_up (ds , ind)) (t_option dst ()) (* Advanced *) | E_matching {matchee;cases} -> ( let%bind ex' = type_expression' e matchee in @@ -882,9 +877,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = | E_set lst -> let%bind lst' = bind_map_list untype_expression lst in return (e_set lst') - | E_look_up dsi -> - let%bind (a , b) = bind_map_pair untype_expression dsi in - return (e_look_up a b) | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/9-self_ast_typed/helpers.ml b/src/passes/9-self_ast_typed/helpers.ml index 90a9fe9cc..658a05f31 100644 --- a/src/passes/9-self_ast_typed/helpers.ml +++ b/src/passes/9-self_ast_typed/helpers.ml @@ -16,9 +16,6 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini let%bind res = bind_fold_list (bind_fold_pair self) init' lst in ok res ) - | E_look_up ab -> - let%bind res = bind_fold_pair self init' ab in - ok res | E_application {lamb; args} -> ( let ab = (lamb, args) in let%bind res = bind_fold_pair self init' ab in @@ -109,10 +106,6 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> let%bind lst' = bind_map_list (bind_map_pair self) lst in return @@ E_big_map lst' ) - | E_look_up ab -> ( - let%bind ab' = bind_map_pair self ab in - return @@ E_look_up ab' - ) | E_matching {matchee=e;cases} -> ( let%bind e' = self e in let%bind cases' = map_cases f cases in @@ -224,10 +217,6 @@ let rec fold_map_expression : 'a fold_mapper -> 'a -> expression -> ('a * expres let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in ok (res, return @@ E_big_map lst') ) - | E_look_up ab -> ( - let%bind (res, ab') = bind_fold_map_pair self init' ab in - ok (res, return @@ E_look_up ab') - ) | E_matching {matchee=e;cases} -> ( let%bind (res, e') = self init' e in let%bind (res,cases') = fold_map_cases f res cases in diff --git a/src/passes/9-self_ast_typed/tail_recursion.ml b/src/passes/9-self_ast_typed/tail_recursion.ml index 5e3953bc3..c95f10c06 100644 --- a/src/passes/9-self_ast_typed/tail_recursion.ml +++ b/src/passes/9-self_ast_typed/tail_recursion.ml @@ -67,10 +67,6 @@ let rec check_recursive_call : expression_variable -> bool -> expression -> unit | E_list el | E_set el -> let%bind _ = bind_map_list (check_recursive_call n false) el in ok () - | E_look_up (e1,e2) -> - let%bind _ = check_recursive_call n false e1 in - let%bind _ = check_recursive_call n false e2 in - ok () and check_recursive_call_in_matching = fun n final_path c -> match c with diff --git a/src/stages/3-ast_core/PP.ml b/src/stages/3-ast_core/PP.ml index 0d648065e..9673beef7 100644 --- a/src/stages/3-ast_core/PP.ml +++ b/src/stages/3-ast_core/PP.ml @@ -39,8 +39,6 @@ and expression_content ppf (ec : expression_content) = fprintf ppf "list[%a]" (list_sep_d expression) lst | E_set lst -> fprintf ppf "set[%a]" (list_sep_d expression) lst - | E_look_up (ds, ind) -> - fprintf ppf "(%a)[%a]" expression ds expression ind | E_lambda {binder; input_type; output_type; result} -> fprintf ppf "lambda (%a:%a) : %a return %a" expression_variable binder diff --git a/src/stages/3-ast_core/combinators.ml b/src/stages/3-ast_core/combinators.ml index 90d1cebd8..91a77d217 100644 --- a/src/stages/3-ast_core/combinators.ml +++ b/src/stages/3-ast_core/combinators.ml @@ -127,7 +127,6 @@ let e_annotation ?loc anno_expr ty = make_expr ?loc @@ E_ascription {anno_expr; let e_application ?loc a b = make_expr ?loc @@ E_application {lamb=a ; args=b} let e_binop ?loc name a b = make_expr ?loc @@ E_constant {cons_name = name ; arguments = [a ; b]} let e_constant ?loc name lst = make_expr ?loc @@ E_constant {cons_name=name ; arguments = lst} -let e_look_up ?loc x y = make_expr ?loc @@ E_look_up (x , y) let e_cond ?loc expr match_true match_false = e_matching expr ?loc (Match_bool {match_true; match_false}) (* let e_assign ?loc a b c = location_wrap ?loc @@ E_assign (Var.of_name a , b , c) (* TODO handlethat*) diff --git a/src/stages/3-ast_core/combinators.mli b/src/stages/3-ast_core/combinators.mli index ae0aab1bd..a16a36600 100644 --- a/src/stages/3-ast_core/combinators.mli +++ b/src/stages/3-ast_core/combinators.mli @@ -89,7 +89,6 @@ val e_annotation : ?loc:Location.t -> expression -> type_expression -> expressio val e_application : ?loc:Location.t -> expression -> expression -> expression val e_binop : ?loc:Location.t -> constant' -> expression -> expression -> expression val e_constant : ?loc:Location.t -> constant' -> expression list -> expression -val e_look_up : ?loc:Location.t -> expression -> expression -> expression val ez_match_variant : ((string * string ) * 'a ) list -> ('a,unit) matching_content val e_matching_variant : ?loc:Location.t -> expression -> ((string * string) * expression) list -> expression diff --git a/src/stages/3-ast_core/misc.ml b/src/stages/3-ast_core/misc.ml index a09efa475..96a9f3750 100644 --- a/src/stages/3-ast_core/misc.ml +++ b/src/stages/3-ast_core/misc.ml @@ -183,8 +183,8 @@ let rec assert_value_eq (a, b: (expression * expression )) : unit result = | (E_variable _, _) | (E_lambda _, _) | (E_application _, _) | (E_let_in _, _) | (E_recursive _,_) | (E_record_accessor _, _) - | (E_look_up _, _) | (E_matching _, _) - -> simple_fail "comparing not a value" + | (E_matching _, _) + -> simple_fail "comparing not a value" let is_value_eq (a , b) = to_bool @@ assert_value_eq (a , b) diff --git a/src/stages/3-ast_core/types.ml b/src/stages/3-ast_core/types.ml index 81ba90fa2..4ad14d148 100644 --- a/src/stages/3-ast_core/types.ml +++ b/src/stages/3-ast_core/types.ml @@ -49,7 +49,6 @@ and expression_content = | E_big_map of (expression * expression) list (*move to operator *) | E_list of expression list | E_set of expression list - | E_look_up of (expression * expression) (* Advanced *) | E_ascription of ascription diff --git a/src/stages/4-ast_typed/PP.ml b/src/stages/4-ast_typed/PP.ml index ab655c80b..3fe4f02c8 100644 --- a/src/stages/4-ast_typed/PP.ml +++ b/src/stages/4-ast_typed/PP.ml @@ -40,8 +40,6 @@ and expression_content ppf (ec: expression_content) = fprintf ppf "list[%a]" (list_sep_d expression) lst | E_set lst -> fprintf ppf "set[%a]" (list_sep_d expression) lst - | E_look_up (ds, ind) -> - fprintf ppf "(%a)[%a]" expression ds expression ind | E_lambda {binder; result} -> fprintf ppf "lambda (%a) return %a" expression_variable binder expression result diff --git a/src/stages/4-ast_typed/misc.ml b/src/stages/4-ast_typed/misc.ml index 533520fe7..5def088a8 100644 --- a/src/stages/4-ast_typed/misc.ml +++ b/src/stages/4-ast_typed/misc.ml @@ -214,7 +214,6 @@ module Free_variables = struct | E_list lst -> unions @@ List.map self lst | E_set lst -> unions @@ List.map self lst | (E_map m | E_big_map m) -> unions @@ List.map self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m - | E_look_up (a , b) -> unions @@ List.map self [ a ; b ] | E_matching {matchee; cases;_} -> union (self matchee) (matching_expression b cases) | E_let_in { let_binder; rhs; let_result; _} -> let b' = union (singleton let_binder) b in @@ -534,7 +533,7 @@ let rec assert_value_eq (a, b: (expression*expression)) : unit result = | (E_literal _, _) | (E_variable _, _) | (E_application _, _) | (E_lambda _, _) | (E_let_in _, _) | (E_recursive _, _) | (E_record_accessor _, _) | (E_record_update _,_) - | (E_look_up _, _) | (E_matching _, _) + | (E_matching _, _) -> fail @@ error_uncomparable_values "can't compare sequences nor loops" a b let merge_annotation (a:type_expression option) (b:type_expression option) err : type_expression result = diff --git a/src/stages/4-ast_typed/misc_smart.ml b/src/stages/4-ast_typed/misc_smart.ml index 1d1110a1c..763bfa399 100644 --- a/src/stages/4-ast_typed/misc_smart.ml +++ b/src/stages/4-ast_typed/misc_smart.ml @@ -84,9 +84,6 @@ module Captured_variables = struct | (E_map m | E_big_map m) -> let%bind lst' = bind_map_list self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m in ok @@ unions lst' - | E_look_up (a , b) -> - let%bind lst' = bind_map_list self [ a ; b ] in - ok @@ unions lst' | E_matching {matchee;cases;_} -> let%bind a' = self matchee in let%bind cs' = matching_expression b cases in diff --git a/src/stages/4-ast_typed/types.ml b/src/stages/4-ast_typed/types.ml index 5fbe79554..fa303e21c 100644 --- a/src/stages/4-ast_typed/types.ml +++ b/src/stages/4-ast_typed/types.ml @@ -55,7 +55,6 @@ and expression_content = | E_big_map of (expression * expression) list (*move to operator *) | E_list of expression list | E_set of expression list - | E_look_up of (expression * expression) and constant = { cons_name: constant' diff --git a/src/stages/typesystem/misc.ml b/src/stages/typesystem/misc.ml index affe9fd37..c74e9e8f1 100644 --- a/src/stages/typesystem/misc.ml +++ b/src/stages/typesystem/misc.ml @@ -210,10 +210,6 @@ module Substitution = struct | T.E_set vals -> let%bind vals = bind_map_list (s_expression ~substs) vals in ok @@ T.E_set vals - | T.E_look_up (val1, val2) -> - let%bind val1 = s_expression ~substs val1 in - let%bind val2 = s_expression ~substs val2 in - ok @@ T.E_look_up (val1 , val2) | T.E_matching {matchee;cases} -> let%bind matchee = s_expression ~substs matchee in let%bind cases = s_matching_expr ~substs cases in From a39c900b72f9753bc770e127621c79734c72fb87 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 16 Mar 2020 18:34:43 +0100 Subject: [PATCH 2/5] remove set and list --- src/bin/expect_tests/contract_tests.ml | 124 ++++++++++-------- src/bin/expect_tests/typer_error_tests.ml | 2 +- src/passes/10-interpreter/interpreter.ml | 13 +- src/passes/10-transpiler/transpiler.ml | 20 --- src/passes/10-transpiler/untranspiler.ml | 11 +- src/passes/11-self_mini_c/helpers.ml | 8 +- src/passes/11-self_mini_c/self_mini_c.ml | 2 - src/passes/11-self_mini_c/subst.ml | 6 +- src/passes/12-compiler/compiler_program.ml | 13 +- src/passes/6-sugar_to_core/sugar_to_core.ml | 27 ++-- src/passes/8-typer-new/typer.ml | 17 --- src/passes/8-typer-old/typer.ml | 63 +++------ src/passes/9-self_ast_typed/helpers.ml | 18 +-- src/passes/9-self_ast_typed/tail_recursion.ml | 3 - src/passes/operators/operators.ml | 8 +- src/stages/1-ast_imperative/combinators.ml | 5 +- src/stages/1-ast_imperative/combinators.mli | 1 + src/stages/3-ast_core/PP.ml | 4 - src/stages/3-ast_core/combinators.ml | 25 ++-- src/stages/3-ast_core/combinators.mli | 8 -- src/stages/3-ast_core/misc.ml | 35 ++--- src/stages/3-ast_core/types.ml | 2 - src/stages/4-ast_typed/PP.ml | 4 - src/stages/4-ast_typed/combinators.ml | 2 - src/stages/4-ast_typed/combinators.mli | 2 - .../4-ast_typed/combinators_environment.ml | 1 - .../4-ast_typed/combinators_environment.mli | 1 - src/stages/4-ast_typed/misc.ml | 20 --- src/stages/4-ast_typed/misc_smart.ml | 6 - src/stages/4-ast_typed/types.ml | 2 - src/stages/5-mini_c/PP.ml | 4 +- src/stages/5-mini_c/misc.ml | 2 - src/stages/5-mini_c/types.ml | 2 - src/stages/common/PP.ml | 2 + src/stages/common/types.ml | 2 + src/stages/typesystem/misc.ml | 6 - 36 files changed, 157 insertions(+), 314 deletions(-) diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 311d96b41..913a89352 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 {| 1870 bytes |}] ; + [%expect {| 1872 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ; [%expect {| 1294 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ; - [%expect {| 2935 bytes |}] ; + [%expect {| 3268 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; [%expect {| 589 bytes |}] ; @@ -227,16 +227,17 @@ let%expect_test _ = NIL operation ; SWAP ; CONS ; - DIP { DIP 4 { DUP } ; - DIG 4 ; - DIP 4 { DUP } ; - DIG 4 ; + DUP ; + DIP { DIP 5 { DUP } ; + DIG 5 ; + DIP 5 { DUP } ; + DIG 5 ; DIP { DUP ; CDR ; SWAP ; CAR ; CAR } ; SWAP ; PAIR ; PAIR } ; PAIR ; - DIP { DROP 13 } } ; + DIP { DROP 14 } } ; DIP { DROP } } { DUP ; DIP { DIP { DUP } ; SWAP } ; @@ -513,19 +514,19 @@ let%expect_test _ = GT ; IF { PUSH string "Message size exceed maximum limit" ; FAILWITH } { PUSH unit Unit } ; - DIP 4 { DUP } ; - DIG 4 ; EMPTY_SET address ; + DUP ; + DIP { DIP 5 { DUP } ; DIG 5 } ; PAIR ; - DIP 2 { DUP } ; - DIG 2 ; - DIP { DIP 5 { DUP } ; DIG 5 ; CAR ; CDR ; CDR } ; + DIP 3 { DUP } ; + DIG 3 ; + DIP { DIP 6 { DUP } ; DIG 6 ; CAR ; CDR ; CDR } ; GET ; IF_NONE - { DIP 5 { DUP } ; - DIG 5 ; - DIP 6 { DUP } ; + { DIP 6 { DUP } ; DIG 6 ; + DIP 7 { DUP } ; + DIG 7 ; CDR ; CAR ; CAR ; @@ -535,7 +536,7 @@ let%expect_test _ = PUSH nat 1 ; ADD ; SOME ; - DIP { DIP 6 { DUP } ; DIG 6 ; CDR ; CAR ; CAR } ; + DIP { DIP 7 { DUP } ; DIG 7 ; CDR ; CAR ; CAR } ; SENDER ; UPDATE ; DIP { DUP ; CAR ; SWAP ; CDR ; DUP ; CDR ; SWAP ; CAR ; CDR } ; @@ -543,31 +544,33 @@ let%expect_test _ = PAIR ; SWAP ; PAIR ; - DIP { DUP } ; - SWAP ; - CAR ; - DIP { DUP } ; - PAIR ; EMPTY_SET address ; PUSH bool True ; SENDER ; UPDATE ; + DIP 2 { DUP } ; + DIG 2 ; + DIP 2 { DUP } ; + DIG 2 ; SWAP ; + CAR ; + PAIR ; CDR ; + DIP { DUP } ; SWAP ; PAIR ; - DIP { DROP } } - { DIP 6 { DUP } ; - DIG 6 ; + DIP { DROP 2 } } + { DIP 7 { DUP } ; + DIG 7 ; DIP { DUP } ; SWAP ; SENDER ; MEM ; IF { DUP } - { DIP 7 { DUP } ; - DIG 7 ; - DIP 8 { DUP } ; + { DIP 8 { DUP } ; DIG 8 ; + DIP 9 { DUP } ; + DIG 9 ; CDR ; CAR ; CAR ; @@ -577,7 +580,7 @@ let%expect_test _ = PUSH nat 1 ; ADD ; SOME ; - DIP { DIP 8 { DUP } ; DIG 8 ; CDR ; CAR ; CAR } ; + DIP { DIP 9 { DUP } ; DIG 9 ; CDR ; CAR ; CAR } ; SENDER ; UPDATE ; DIP { DUP ; CAR ; SWAP ; CDR ; DUP ; CDR ; SWAP ; CAR ; CDR } ; @@ -623,21 +626,26 @@ let%expect_test _ = GT ; IF { PUSH string "Maximum number of proposal reached" ; FAILWITH } { PUSH unit Unit } ; - DIP 2 { DUP } ; - DIG 2 ; NIL operation ; + DIP 10 { DUP } ; + DIG 10 ; + DIP { DIP 4 { DUP } ; DIG 4 } ; PAIR ; - DIP 4 { DUP } ; - DIG 4 ; + DIP { DIP 9 { DUP } ; DIG 9 ; DIP { DUP } ; PAIR } ; + PAIR ; + DIP { DIP 3 { DUP } ; DIG 3 } ; + PAIR ; + DIP 5 { DUP } ; + DIG 5 ; SIZE ; - DIP { DIP 3 { DUP } ; DIG 3 ; CDR ; CDR } ; + DIP { DIP 4 { DUP } ; DIG 4 ; CDR ; CDR } ; COMPARE ; GE ; - IF { DIP 3 { DUP } ; - DIG 3 ; - DIP 9 { DUP } ; - DIG 9 ; - DIP { DIP 4 { DUP } ; DIG 4 ; CAR ; CDR ; CDR ; NONE (set address) } ; + IF { DIP 4 { DUP } ; + DIG 4 ; + DIP 11 { DUP } ; + DIG 11 ; + DIP { DIP 5 { DUP } ; DIG 5 ; CAR ; CDR ; CDR ; NONE (set address) } ; UPDATE ; DIP { DUP ; CDR ; SWAP ; CAR ; DUP ; CAR ; SWAP ; CDR ; CAR } ; SWAP ; @@ -649,7 +657,7 @@ let%expect_test _ = CDR ; CAR ; CDR ; - DIP { DIP 10 { DUP } ; DIG 10 } ; + DIP { DIP 12 { DUP } ; DIG 12 } ; EXEC ; DIP { DUP } ; SWAP ; @@ -658,7 +666,7 @@ let%expect_test _ = CDR ; CAR ; CDR ; - DIP { DIP 11 { DUP } ; DIG 11 } ; + DIP { DIP 13 { DUP } ; DIG 13 } ; CONCAT ; SHA256 ; DIP { DUP ; CAR ; SWAP ; CDR ; DUP ; CDR ; SWAP ; CAR ; CAR } ; @@ -683,8 +691,12 @@ let%expect_test _ = DIP { DUP } ; SWAP ; DIP { DUP } ; - SWAP ; - DIP { DIP 11 { DUP } ; DIG 11 } ; + PAIR ; + DIP { DIP 2 { DUP } ; DIG 2 } ; + PAIR ; + DIP 2 { DUP } ; + DIG 2 ; + DIP { DIP 13 { DUP } ; DIG 13 } ; MEM ; IF { DIP 2 { DUP } ; DIG 2 ; @@ -746,14 +758,14 @@ let%expect_test _ = PAIR ; DIP { DROP 4 } } { DUP ; - DIP 4 { DUP } ; - DIG 4 ; - DIP 10 { DUP } ; - DIG 10 ; - DIP { DIP 6 { DUP } ; - DIG 6 ; + DIP 5 { DUP } ; + DIG 5 ; + DIP 12 { DUP } ; + DIG 12 ; + DIP { DIP 7 { DUP } ; + DIG 7 ; SOME ; - DIP { DIP 5 { DUP } ; DIG 5 ; CAR ; CDR ; CDR } } ; + DIP { DIP 6 { DUP } ; DIG 6 ; CAR ; CDR ; CDR } } ; UPDATE ; DIP { DUP ; CDR ; SWAP ; CAR ; DUP ; CAR ; SWAP ; CDR ; CAR } ; SWAP ; @@ -768,7 +780,7 @@ let%expect_test _ = CAR ; DIP { DUP ; CDR } ; PAIR ; - DIP { DROP 15 } } ; + DIP { DROP 17 } } ; DIP { DROP } } { DUP ; DIP { DIP { DUP } ; SWAP } ; @@ -1033,11 +1045,11 @@ let%expect_test _ = let%expect_test _ = run_ligo_good [ "dry-run" ; contract "redeclaration.ligo" ; "main" ; "unit" ; "0" ] ; - [%expect {|( list[] , 0 ) |}] + [%expect {|( LIST_EMPTY() , 0 ) |}] let%expect_test _ = run_ligo_good [ "dry-run" ; contract "double_main.ligo" ; "main" ; "unit" ; "0" ] ; - [%expect {|( list[] , 2 ) |}] + [%expect {|( LIST_EMPTY() , 2 ) |}] let%expect_test _ = run_ligo_good [ "compile-contract" ; contract "subtle_nontail_fail.mligo" ; "main" ] ; @@ -1095,7 +1107,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_good [ "dry-run" ; contract "super-counter.mligo" ; "main" ; "test_param" ; "test_storage" ] ; [%expect {| - ( list[] , 3 ) |}] + ( LIST_EMPTY() , 3 ) |}] let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "redundant_constructors.mligo" ; "main" ] ; @@ -1114,7 +1126,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return let rhs#702 = #P in let p = rhs#702.0 in let s = rhs#702.1 in ( list[] : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} +ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return let rhs#654 = #P in let p = rhs#654.0 in let s = rhs#654.1 in ( LIST_EMPTY() : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1127,7 +1139,7 @@ ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return let rhs#705 = #P in let p = rhs#705.0 in let s = rhs#705.1 in ( list[] : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} +ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return let rhs#657 = #P in let p = rhs#657.0 in let s = rhs#657.1 in ( LIST_EMPTY() : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can @@ -1336,4 +1348,4 @@ let%expect_test _ = * Visit our documentation: https://ligolang.org/docs/intro/what-and-why/ * Ask a question on our Discord: https://discord.gg/9rhYaEt * Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new - * Check the changelog by running 'ligo changelog' |}] \ No newline at end of file + * Check the changelog by running 'ligo changelog' |}] diff --git a/src/bin/expect_tests/typer_error_tests.ml b/src/bin/expect_tests/typer_error_tests.ml index ecf5ce7e3..facf1e75c 100644 --- a/src/bin/expect_tests/typer_error_tests.ml +++ b/src/bin/expect_tests/typer_error_tests.ml @@ -175,7 +175,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_good [ "interpret" ; "Set.literal [ (1,(2,3)) ; (2,(3,4)) ]" ; "--syntax=cameligo" ] ; [%expect {| - set[( 2 , ( 3 , 4 ) ) , ( 1 , ( 2 , 3 ) )] |}]; + SET_ADD(( 2 , ( 3 , 4 ) ) , SET_ADD(( 1 , ( 2 , 3 ) ) , SET_EMPTY())) |}]; run_ligo_bad [ "interpret" ; "Set.literal [ (1,2,3) ; (2,3,4) ]" ; "--syntax=cameligo" ] ; [%expect {| diff --git a/src/passes/10-interpreter/interpreter.ml b/src/passes/10-interpreter/interpreter.ml index 77d30cb71..6925a0243 100644 --- a/src/passes/10-interpreter/interpreter.ml +++ b/src/passes/10-interpreter/interpreter.ml @@ -119,6 +119,7 @@ let rec apply_operator : Ast_typed.constant' -> value list -> value result = | ( C_OR , [ V_Ct (C_bool a' ) ; V_Ct (C_bool b' ) ] ) -> return_ct @@ C_bool (a' || b') | ( C_AND , [ V_Ct (C_bool a' ) ; V_Ct (C_bool b' ) ] ) -> return_ct @@ C_bool (a' && b') | ( C_XOR , [ V_Ct (C_bool a' ) ; V_Ct (C_bool b' ) ] ) -> return_ct @@ C_bool ( (a' || b') && (not (a' && b')) ) + | ( C_LIST_EMPTY, []) -> ok @@ V_List ([]) | ( C_LIST_MAP , [ V_Func_val (arg_name, body, env) ; V_List (elts) ] ) -> let%bind elts' = bind_map_list (fun elt -> @@ -188,6 +189,7 @@ let rec apply_operator : Ast_typed.constant' -> value list -> value result = | "None" -> ok @@ V_Map (List.remove_assoc k kvs) | _ -> simple_fail "update without an option" ) + | ( C_SET_EMPTY, []) -> ok @@ V_Set ([]) | ( C_SET_ADD , [ v ; V_Set l ] ) -> ok @@ V_Set (List.sort_uniq compare (v::l)) | ( C_SET_FOLD , [ V_Func_val (arg_name, body, env) ; V_Set elts ; init ] ) -> bind_fold_list @@ -294,17 +296,6 @@ and eval : Ast_typed.expression -> env -> value result (fun kv -> bind_map_pair (fun (el:Ast_typed.expression) -> eval el env) kv) kvlist in ok @@ V_Map kvlist' - | E_list expl -> - let%bind expl' = bind_map_list - (fun (exp:Ast_typed.expression) -> eval exp env) - expl in - ok @@ V_List expl' - | E_set expl -> - let%bind expl' = bind_map_list - (fun (exp:Ast_typed.expression) -> eval exp env) - (List.sort_uniq compare expl) - in - ok @@ V_Set expl' | E_literal l -> eval_literal l | E_variable var -> diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index b7935bbe4..82f048614 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -390,26 +390,6 @@ and transpile_annotated_expression (ae:AST.expression) : expression result = transpile_lambda l io | E_recursive r -> transpile_recursive r - | E_list lst -> ( - let%bind t = - trace_strong (corner_case ~loc:__LOC__ "not a list") @@ - get_t_list tv in - let%bind lst' = bind_map_list (transpile_annotated_expression) lst in - let aux : expression -> expression -> expression result = fun prev cur -> - return @@ E_constant {cons_name=C_CONS;arguments=[cur ; prev]} in - let%bind (init : expression) = return @@ E_make_empty_list t in - bind_fold_right_list aux init lst' - ) - | E_set lst -> ( - let%bind t = - trace_strong (corner_case ~loc:__LOC__ "not a set") @@ - get_t_set tv in - let%bind lst' = bind_map_list (transpile_annotated_expression) lst in - let aux : expression -> expression -> expression result = fun prev cur -> - return @@ E_constant {cons_name=C_SET_ADD;arguments=[cur ; prev]} in - let%bind (init : expression) = return @@ E_make_empty_set t in - bind_fold_list aux init lst' - ) | E_map m -> ( let%bind (src, dst) = trace_strong (corner_case ~loc:__LOC__ "not a map") @@ diff --git a/src/passes/10-transpiler/untranspiler.ml b/src/passes/10-transpiler/untranspiler.ml index 49f9cde37..e9a924c53 100644 --- a/src/passes/10-transpiler/untranspiler.ml +++ b/src/passes/10-transpiler/untranspiler.ml @@ -181,7 +181,10 @@ let rec untranspile (v : value) (t : AST.type_expression) : AST.expression resul let%bind lst' = let aux = fun e -> untranspile e ty in bind_map_list aux lst in - return (E_list lst') + let aux = fun prev cur -> + return @@ E_constant {cons_name=C_CONS;arguments=[cur ; prev]} in + let%bind init = return @@ E_constant {cons_name=C_LIST_EMPTY;arguments=[]} in + bind_fold_right_list aux init lst' ) | TC_arrow _ -> ( let%bind n = @@ -196,7 +199,11 @@ let rec untranspile (v : value) (t : AST.type_expression) : AST.expression resul let%bind lst' = let aux = fun e -> untranspile e ty in bind_map_list aux lst in - return (E_set lst') + let lst' = List.sort_uniq compare lst' in + let aux = fun prev cur -> + return @@ E_constant {cons_name=C_SET_ADD;arguments=[cur ; prev]} in + let%bind init = return @@ E_constant {cons_name=C_SET_EMPTY;arguments=[]} in + bind_fold_list aux init lst' ) | TC_contract _ -> fail @@ bad_untranspile "contract" v diff --git a/src/passes/11-self_mini_c/helpers.ml b/src/passes/11-self_mini_c/helpers.ml index 6b77cf2ee..ea6d1355c 100644 --- a/src/passes/11-self_mini_c/helpers.ml +++ b/src/passes/11-self_mini_c/helpers.ml @@ -27,10 +27,6 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini | E_variable _ | E_skip | E_make_none _ | E_make_empty_map _ | E_make_empty_big_map _ - | E_make_empty_list _ - | E_make_empty_set _ -> ( - ok init' - ) | E_literal _ -> ok init' | E_constant (c) -> ( let%bind res = bind_fold_list self init' c.arguments in @@ -95,9 +91,7 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> match e'.content with | E_variable _ | E_literal _ | E_skip | E_make_none _ | E_make_empty_map _ - | E_make_empty_big_map _ - | E_make_empty_list _ - | E_make_empty_set _ as em -> return em + | E_make_empty_big_map _ as em -> return em | E_constant (c) -> ( let%bind lst = bind_map_list self c.arguments in return @@ E_constant {cons_name = c.cons_name; arguments = lst} diff --git a/src/passes/11-self_mini_c/self_mini_c.ml b/src/passes/11-self_mini_c/self_mini_c.ml index 66a0a06b8..56ee521df 100644 --- a/src/passes/11-self_mini_c/self_mini_c.ml +++ b/src/passes/11-self_mini_c/self_mini_c.ml @@ -49,8 +49,6 @@ let rec is_pure : expression -> bool = fun e -> | E_variable _ | E_make_empty_map _ | E_make_empty_big_map _ - | E_make_empty_list _ - | E_make_empty_set _ | E_make_none _ -> true diff --git a/src/passes/11-self_mini_c/subst.ml b/src/passes/11-self_mini_c/subst.ml index c2103c9f5..1914cbe2c 100644 --- a/src/passes/11-self_mini_c/subst.ml +++ b/src/passes/11-self_mini_c/subst.ml @@ -42,8 +42,6 @@ let rec replace : expression -> var_name -> var_name -> expression = return @@ E_variable z | E_make_empty_map _ -> e | E_make_empty_big_map _ -> e - | E_make_empty_list _ -> e - | E_make_empty_set _ -> e | E_make_none _ -> e | E_iterator (name, ((v, tv), body), expr) -> let body = replace body in @@ -176,9 +174,7 @@ let rec subst_expression : body:expression -> x:var_name -> expr:expression -> e (* All that follows is boilerplate *) | E_literal _ | E_skip | E_make_none _ | E_make_empty_map (_,_) - | E_make_empty_big_map _ - | E_make_empty_list _ - | E_make_empty_set _ as em -> return em + | E_make_empty_big_map _ as em -> return em | E_constant (c) -> ( let lst = List.map self c.arguments in return @@ E_constant {cons_name = c.cons_name; arguments = lst } diff --git a/src/passes/12-compiler/compiler_program.ml b/src/passes/12-compiler/compiler_program.ml index 9a2001298..2ebfcbc34 100644 --- a/src/passes/12-compiler/compiler_program.ml +++ b/src/passes/12-compiler/compiler_program.ml @@ -66,10 +66,15 @@ let rec get_operator : constant' -> type_value -> expression list -> predicate r let%bind m_ty = Compiler_type.type_ ty in ok @@ simple_unary @@ prim ~children:[m_ty] I_RIGHT ) + | C_LIST_EMPTY -> ( + let%bind ty' = Mini_c.get_t_list ty in + let%bind m_ty = Compiler_type.type_ ty' in + ok @@ simple_constant @@ i_nil m_ty + ) | C_SET_EMPTY -> ( let%bind ty' = Mini_c.get_t_set ty in let%bind m_ty = Compiler_type.type_ ty' in - ok @@ simple_constant @@ prim ~children:[m_ty] I_EMPTY_SET + ok @@ simple_constant @@ i_empty_set m_ty ) | C_BYTES_UNPACK -> ( let%bind ty' = Mini_c.get_t_option ty in @@ -303,12 +308,6 @@ and translate_expression (expr:expression) (env:environment) : michelson result | E_make_empty_big_map sd -> let%bind (src, dst) = bind_map_pair Compiler_type.type_ sd in return @@ i_empty_big_map src dst - | E_make_empty_list t -> - let%bind t' = Compiler_type.type_ t in - return @@ i_nil t' - | E_make_empty_set t -> - let%bind t' = Compiler_type.type_ t in - return @@ i_empty_set t' | E_make_none o -> let%bind o' = Compiler_type.type_ o in return @@ i_none o' diff --git a/src/passes/6-sugar_to_core/sugar_to_core.ml b/src/passes/6-sugar_to_core/sugar_to_core.ml index e7a3f20fc..6c664a45b 100644 --- a/src/passes/6-sugar_to_core/sugar_to_core.ml +++ b/src/passes/6-sugar_to_core/sugar_to_core.ml @@ -121,11 +121,19 @@ let rec compile_expression : I.expression -> O.expression result = in return @@ O.E_big_map big_map | I.E_list lst -> - let%bind lst = bind_map_list compile_expression lst in - return @@ O.E_list lst - | I.E_set set -> - let%bind set = bind_map_list compile_expression set in - return @@ O.E_set set + let%bind lst' = bind_map_list (compile_expression) lst in + let aux = fun prev cur -> + return @@ E_constant {cons_name=C_CONS;arguments=[cur ; prev]} in + let%bind init = return @@ E_constant {cons_name=C_LIST_EMPTY;arguments=[]} in + bind_fold_right_list aux init lst' + | I.E_set set -> ( + let%bind lst' = bind_map_list (compile_expression) set in + let lst' = List.sort_uniq compare lst' in + let aux = fun prev cur -> + return @@ E_constant {cons_name=C_SET_ADD;arguments=[cur ; prev]} in + let%bind init = return @@ E_constant {cons_name=C_SET_EMPTY;arguments=[]} in + bind_fold_list aux init lst' + ) | I.E_look_up look_up -> let%bind (path, index) = bind_map_pair compile_expression look_up in return @@ O.E_constant {cons_name=C_MAP_FIND_OPT;arguments=[index;path]} @@ -313,15 +321,6 @@ let rec uncompile_expression : O.expression -> I.expression result = ) big_map in return @@ I.E_big_map big_map - | O.E_list lst -> - let%bind lst = bind_map_list uncompile_expression lst in - return @@ I.E_list lst - | O.E_set set -> - let%bind set = bind_map_list uncompile_expression set in - return @@ I.E_set set - | O.E_look_up look_up -> - let%bind look_up = bind_map_pair uncompile_expression look_up in - return @@ I.E_look_up look_up | O.E_ascription {anno_expr; type_annotation} -> let%bind anno_expr = uncompile_expression anno_expr in let%bind type_annotation = uncompile_type_expression type_annotation in diff --git a/src/passes/8-typer-new/typer.ml b/src/passes/8-typer-new/typer.ml index 94a1682bd..754659597 100644 --- a/src/passes/8-typer-new/typer.ml +++ b/src/passes/8-typer-new/typer.ml @@ -578,17 +578,6 @@ and type_expression : environment -> Solver.state -> ?tv_opt:O.type_expression - return (E_map lst') tv *) - | E_list lst -> - let%bind (state', lst') = - bind_fold_map_list (fun state' elt -> type_expression e state' elt >>? swap) state lst in - let wrapped = Wrap.list (List.map (fun x -> O.(x.type_expression)) lst') in - return_wrapped (E_list lst') state' wrapped - | E_set set -> - let aux = fun state' elt -> type_expression e state' elt >>? swap in - let%bind (state', set') = - bind_fold_map_list aux state set in - let wrapped = Wrap.set (List.map (fun x -> O.(x.type_expression)) set') in - return_wrapped (E_set set') state' wrapped | E_map map -> let aux' state' elt = type_expression e state' elt >>? swap in let aux = fun state' elt -> bind_fold_map_pair aux' state' elt in @@ -1059,12 +1048,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = | E_big_map m -> let%bind m' = bind_map_list (bind_map_pair untype_expression) m in return (e_big_map m') - | E_list lst -> - let%bind lst' = bind_map_list untype_expression lst in - return (e_list lst') - | E_set lst -> - let%bind lst' = bind_map_list untype_expression lst in - return (e_set lst') | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index 2b6764dea..879c44b19 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -511,48 +511,6 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let%bind () = O.assert_type_expression_eq (tv, get_type_expression update) in return (E_record_update {record; path; update}) wrapped (* Data-structure *) - | E_list lst -> - let%bind lst' = bind_map_list (type_expression' e) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_expression_eq (c, c') in - ok (Some c') in - let%bind init = match tv_opt with - | None -> ok None - | Some ty -> - let%bind ty' = get_t_list ty in - ok (Some ty') in - let%bind ty = - let%bind opt = bind_fold_list aux init - @@ List.map get_type_expression lst' in - trace_option (needs_annotation ae "empty list") opt in - ok (t_list ty ()) - in - return (E_list lst') tv - | E_set lst -> - let%bind lst' = bind_map_list (type_expression' e) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_expression_eq (c, c') in - ok (Some c') in - let%bind init = match tv_opt with - | None -> ok None - | Some ty -> - let%bind ty' = get_t_set ty in - ok (Some ty') in - let%bind ty = - let%bind opt = bind_fold_list aux init - @@ List.map get_type_expression lst' in - trace_option (needs_annotation ae "empty set") opt in - ok (t_set ty ()) - in - return (E_set lst') tv | E_map lst -> let%bind lst' = bind_map_list (bind_map_pair (type_expression' e)) lst in let%bind tv = @@ -682,6 +640,21 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let%bind (name', tv) = type_constant cons_name tv_lst tv_opt in return (E_constant {cons_name=name';arguments=lst'}) tv + | E_constant {cons_name=C_SET_ADD|C_CONS as cst;arguments=[key;set]} -> + let%bind key' = type_expression' e key in + let tv_key = get_type_expression key' in + let tv = match tv_opt with + Some (tv) -> tv + | None -> match cst with + C_SET_ADD -> t_set tv_key () + | C_CONS -> t_list tv_key () + | _ -> failwith "impossible" + in + let%bind set' = type_expression' e ~tv_opt:tv set in + let tv_set = get_type_expression set' in + let tv_lst = [tv_key;tv_set] in + let%bind (name', tv) = type_constant cst tv_lst tv_opt in + return (E_constant {cons_name=name';arguments=[key';set']}) tv | E_constant {cons_name;arguments} -> let%bind lst' = bind_list @@ List.map (type_expression' e) arguments in let tv_lst = List.map get_type_expression lst' in @@ -871,12 +844,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = | E_big_map m -> let%bind m' = bind_map_list (bind_map_pair untype_expression) m in return (e_big_map m') - | E_list lst -> - let%bind lst' = bind_map_list untype_expression lst in - return (e_list lst') - | E_set lst -> - let%bind lst' = bind_map_list untype_expression lst in - return (e_set lst') | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/9-self_ast_typed/helpers.ml b/src/passes/9-self_ast_typed/helpers.ml index 658a05f31..76d6c0f21 100644 --- a/src/passes/9-self_ast_typed/helpers.ml +++ b/src/passes/9-self_ast_typed/helpers.ml @@ -8,7 +8,7 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini let%bind init' = f init e in match e.expression_content with | E_literal _ | E_variable _ -> ok init' - | E_list lst | E_set lst | E_constant {arguments=lst} -> ( + | E_constant {arguments=lst} -> ( let%bind res = bind_fold_list self init' lst in ok res ) @@ -90,14 +90,6 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> let%bind e' = f e in let return expression_content = ok { e' with expression_content } in match e'.expression_content with - | E_list lst -> ( - let%bind lst' = bind_map_list self lst in - return @@ E_list lst' - ) - | E_set lst -> ( - let%bind lst' = bind_map_list self lst in - return @@ E_set lst' - ) | E_map lst -> ( let%bind lst' = bind_map_list (bind_map_pair self) lst in return @@ E_map lst' @@ -201,14 +193,6 @@ let rec fold_map_expression : 'a fold_mapper -> 'a -> expression -> ('a * expres else let return expression_content = { e' with expression_content } in match e'.expression_content with - | E_list lst -> ( - let%bind (res, lst') = bind_fold_map_list self init' lst in - ok (res, return @@ E_list lst') - ) - | E_set lst -> ( - let%bind (res, lst') = bind_fold_map_list self init' lst in - ok (res, return @@ E_set lst') - ) | E_map lst -> ( let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in ok (res, return @@ E_map lst') diff --git a/src/passes/9-self_ast_typed/tail_recursion.ml b/src/passes/9-self_ast_typed/tail_recursion.ml index c95f10c06..f5f30e923 100644 --- a/src/passes/9-self_ast_typed/tail_recursion.ml +++ b/src/passes/9-self_ast_typed/tail_recursion.ml @@ -64,9 +64,6 @@ let rec check_recursive_call : expression_variable -> bool -> expression -> unit in let%bind _ = bind_map_list aux eel in ok () - | E_list el | E_set el -> - let%bind _ = bind_map_list (check_recursive_call n false) el in - ok () and check_recursive_call_in_matching = fun n final_path c -> match c with diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 472b67506..8e011b316 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -949,6 +949,11 @@ module Typer = struct then ok (t_unit ()) else fail @@ Operator_errors.type_error "bad set iter" key arg () + let list_empty = typer_0 "LIST_EMPTY" @@ fun tv_opt -> + match tv_opt with + | None -> simple_fail "untyped LIST_EMPTY" + | Some t -> ok t + let list_iter = typer_2 "LIST_ITER" @@ fun body lst -> let%bind (arg , res) = get_t_function body in let%bind () = Assert.assert_true (eq_1 res (t_unit ())) in @@ -1145,7 +1150,6 @@ module Typer = struct | C_SLICE -> ok @@ slice ; | C_BYTES_PACK -> ok @@ bytes_pack ; | C_BYTES_UNPACK -> ok @@ bytes_unpack ; - | C_CONS -> ok @@ cons ; (* SET *) | C_SET_EMPTY -> ok @@ set_empty ; | C_SET_ADD -> ok @@ set_add ; @@ -1155,6 +1159,8 @@ module Typer = struct | C_SET_MEM -> ok @@ set_mem ; (* LIST *) + | C_CONS -> ok @@ cons ; + | C_LIST_EMPTY -> ok @@ list_empty ; | C_LIST_ITER -> ok @@ list_iter ; | C_LIST_MAP -> ok @@ list_map ; | C_LIST_FOLD -> ok @@ list_fold ; diff --git a/src/stages/1-ast_imperative/combinators.ml b/src/stages/1-ast_imperative/combinators.ml index bc66d4ac0..e49f811b3 100644 --- a/src/stages/1-ast_imperative/combinators.ml +++ b/src/stages/1-ast_imperative/combinators.ml @@ -168,8 +168,9 @@ let e_typed_none ?loc t_opt = let type_annotation = t_option t_opt in e_annotation ?loc (e_none ?loc ()) type_annotation -let e_typed_list ?loc lst t = - e_annotation ?loc (e_list lst) (t_list t) +let e_typed_list ?loc lst t = e_annotation ?loc (e_list lst) (t_list t) +let e_typed_list_literal ?loc lst t = + e_annotation ?loc (e_constant C_LIST_LITERAL lst) (t_list t) let e_typed_map ?loc lst k v = e_annotation ?loc (e_map lst) (t_map k v) let e_typed_big_map ?loc lst k v = e_annotation ?loc (e_big_map lst) (t_big_map k v) diff --git a/src/stages/1-ast_imperative/combinators.mli b/src/stages/1-ast_imperative/combinators.mli index 1cf5986c9..3d0ae94b9 100644 --- a/src/stages/1-ast_imperative/combinators.mli +++ b/src/stages/1-ast_imperative/combinators.mli @@ -100,6 +100,7 @@ val make_option_typed : ?loc:Location.t -> expression -> type_expression option val e_typed_none : ?loc:Location.t -> type_expression -> expression val e_typed_list : ?loc:Location.t -> expression list -> type_expression -> expression +val e_typed_list_literal : ?loc:Location.t -> expression list -> type_expression -> expression val e_typed_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression val e_typed_big_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression diff --git a/src/stages/3-ast_core/PP.ml b/src/stages/3-ast_core/PP.ml index 9673beef7..149a92631 100644 --- a/src/stages/3-ast_core/PP.ml +++ b/src/stages/3-ast_core/PP.ml @@ -35,10 +35,6 @@ and expression_content ppf (ec : expression_content) = fprintf ppf "map[%a]" (list_sep_d assoc_expression) m | E_big_map m -> fprintf ppf "big_map[%a]" (list_sep_d assoc_expression) m - | E_list lst -> - fprintf ppf "list[%a]" (list_sep_d expression) lst - | E_set lst -> - fprintf ppf "set[%a]" (list_sep_d expression) lst | E_lambda {binder; input_type; output_type; result} -> fprintf ppf "lambda (%a:%a) : %a return %a" expression_variable binder diff --git a/src/stages/3-ast_core/combinators.ml b/src/stages/3-ast_core/combinators.ml index 91a77d217..a1fdd1242 100644 --- a/src/stages/3-ast_core/combinators.ml +++ b/src/stages/3-ast_core/combinators.ml @@ -113,8 +113,6 @@ let e_none ?loc () : expression = make_expr ?loc @@ E_constant {cons_name = C_NO let e_string_cat ?loc sl sr : expression = make_expr ?loc @@ E_constant {cons_name = C_CONCAT; arguments = [sl ; sr ]} let e_map_add ?loc k v old : expression = make_expr ?loc @@ E_constant {cons_name = C_MAP_ADD; arguments = [k ; v ; old]} let e_map ?loc lst : expression = make_expr ?loc @@ E_map lst -let e_set ?loc lst : expression = make_expr ?loc @@ E_set lst -let e_list ?loc lst : expression = make_expr ?loc @@ E_list lst let e_constructor ?loc s a : expression = make_expr ?loc @@ E_constructor { constructor = Constructor s; element = a} let e_matching ?loc a b : expression = make_expr ?loc @@ E_matching {matchee=a;cases=b} let e_matching_bool ?loc a b c : expression = e_matching ?loc a (Match_bool {match_true = b ; match_false = c}) @@ -160,14 +158,9 @@ let e_typed_none ?loc t_opt = let type_annotation = t_option t_opt in e_annotation ?loc (e_none ?loc ()) type_annotation -let e_typed_list ?loc lst t = - e_annotation ?loc (e_list lst) (t_list t) - let e_typed_map ?loc lst k v = e_annotation ?loc (e_map lst) (t_map k v) let e_typed_big_map ?loc lst k v = e_annotation ?loc (e_big_map lst) (t_big_map k v) -let e_typed_set ?loc lst k = e_annotation ?loc (e_set lst) (t_set k) - let e_lambda ?loc (binder : expression_variable) (input_type : type_expression option) @@ -220,9 +213,16 @@ let get_e_pair = fun t -> | _ -> simple_fail "not a pair" let get_e_list = fun t -> - match t with - | E_list lst -> ok lst - | _ -> simple_fail "not a list" + let rec aux t = + match t with + E_constant {cons_name=C_CONS;arguments=[key;lst]} -> + let%bind lst = aux lst.expression_content in + ok @@ key::(lst) + | E_constant {cons_name=C_LIST_EMPTY;arguments=[]} -> + ok @@ [] + | _ -> simple_fail "not a list" + in + aux t let tuple_of_record (m: _ LMap.t) = let aux i = @@ -249,11 +249,6 @@ let extract_pair : expression -> (expression * expression) result = fun e -> ) | _ -> fail @@ bad_kind "pair" e.location -let extract_list : expression -> (expression list) result = fun e -> - match e.expression_content with - | E_list lst -> ok lst - | _ -> fail @@ bad_kind "list" e.location - let extract_record : expression -> (label * expression) list result = fun e -> match e.expression_content with | E_record lst -> ok @@ LMap.to_kv_list lst diff --git a/src/stages/3-ast_core/combinators.mli b/src/stages/3-ast_core/combinators.mli index a16a36600..dfb78bf43 100644 --- a/src/stages/3-ast_core/combinators.mli +++ b/src/stages/3-ast_core/combinators.mli @@ -74,8 +74,6 @@ val e_none : ?loc:Location.t -> unit -> expression val e_string_cat : ?loc:Location.t -> expression -> expression -> expression val e_map_add : ?loc:Location.t -> expression -> expression -> expression -> expression val e_map : ?loc:Location.t -> ( expression * expression ) list -> expression -val e_set : ?loc:Location.t -> expression list -> expression -val e_list : ?loc:Location.t -> expression list -> expression val e_pair : ?loc:Location.t -> expression -> expression -> expression val e_constructor : ?loc:Location.t -> string -> expression -> expression val e_matching : ?loc:Location.t -> expression -> matching_expr -> expression @@ -96,13 +94,9 @@ val make_option_typed : ?loc:Location.t -> expression -> type_expression option val e_typed_none : ?loc:Location.t -> type_expression -> expression -val e_typed_list : ?loc:Location.t -> expression list -> type_expression -> expression - val e_typed_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression val e_typed_big_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression -val e_typed_set : ?loc:Location.t -> expression list -> type_expression -> expression - val e_lambda : ?loc:Location.t -> expression_variable -> type_expression option -> type_expression option -> expression -> expression val e_recursive : ?loc:Location.t -> expression_variable -> type_expression -> lambda -> expression val e_record : ?loc:Location.t -> expr Map.String.t -> expression @@ -125,8 +119,6 @@ val is_e_failwith : expression -> bool *) val extract_pair : expression -> ( expression * expression ) result -val extract_list : expression -> (expression list) result - val extract_record : expression -> (label * expression) list result val extract_map : expression -> (expression * expression) list result diff --git a/src/stages/3-ast_core/misc.ml b/src/stages/3-ast_core/misc.ml index 96a9f3750..fc5319eed 100644 --- a/src/stages/3-ast_core/misc.ml +++ b/src/stages/3-ast_core/misc.ml @@ -88,6 +88,19 @@ let rec assert_value_eq (a, b: (expression * expression )) : unit result = assert_literal_eq (a, b) | E_literal _ , _ -> simple_fail "comparing a literal with not a literal" + | E_constant {cons_name=C_SET_LITERAL;arguments=lsta}, + E_constant {cons_name=C_SET_LITERAL;arguments=lstb} -> ( + let lsta' = List.sort (compare) lsta in + let lstb' = List.sort (compare) lstb in + let%bind lst = + generic_try (simple_error "set of different lengths") + (fun () -> List.combine lsta' lstb') in + let%bind _all = bind_map_list assert_value_eq lst in + ok () + ) + | E_constant {cons_name=C_SET_LITERAL;_}, _ -> + simple_fail "comparing set with other expression" + | E_constant (ca) , E_constant (cb) when ca.cons_name = cb.cons_name -> ( let%bind lst = generic_try (simple_error "constants with different number of elements") @@ -156,28 +169,6 @@ let rec assert_value_eq (a, b: (expression * expression )) : unit result = | (E_map _ | E_big_map _), _ -> simple_fail "comparing map with other expression" - | E_list lsta, E_list lstb -> ( - let%bind lst = - generic_try (simple_error "list of different lengths") - (fun () -> List.combine lsta lstb) in - let%bind _all = bind_map_list assert_value_eq lst in - ok () - ) - | E_list _, _ -> - simple_fail "comparing list with other expression" - - | E_set lsta, E_set lstb -> ( - let lsta' = List.sort (compare) lsta in - let lstb' = List.sort (compare) lstb in - let%bind lst = - generic_try (simple_error "set of different lengths") - (fun () -> List.combine lsta' lstb') in - let%bind _all = bind_map_list assert_value_eq lst in - ok () - ) - | E_set _, _ -> - simple_fail "comparing set with other expression" - | (E_ascription a , _b') -> assert_value_eq (a.anno_expr , b) | (_a' , E_ascription b) -> assert_value_eq (a , b.anno_expr) | (E_variable _, _) | (E_lambda _, _) diff --git a/src/stages/3-ast_core/types.ml b/src/stages/3-ast_core/types.ml index 4ad14d148..ae3bb2283 100644 --- a/src/stages/3-ast_core/types.ml +++ b/src/stages/3-ast_core/types.ml @@ -47,8 +47,6 @@ and expression_content = (* TODO : move to constant*) | E_map of (expression * expression) list (*move to operator *) | E_big_map of (expression * expression) list (*move to operator *) - | E_list of expression list - | E_set of expression list (* Advanced *) | E_ascription of ascription diff --git a/src/stages/4-ast_typed/PP.ml b/src/stages/4-ast_typed/PP.ml index 3fe4f02c8..62e085c51 100644 --- a/src/stages/4-ast_typed/PP.ml +++ b/src/stages/4-ast_typed/PP.ml @@ -36,10 +36,6 @@ and expression_content ppf (ec: expression_content) = fprintf ppf "map[%a]" (list_sep_d assoc_expression) m | E_big_map m -> fprintf ppf "big_map[%a]" (list_sep_d assoc_expression) m - | E_list lst -> - fprintf ppf "list[%a]" (list_sep_d expression) lst - | E_set lst -> - fprintf ppf "set[%a]" (list_sep_d expression) lst | E_lambda {binder; result} -> fprintf ppf "lambda (%a) return %a" expression_variable binder expression result diff --git a/src/stages/4-ast_typed/combinators.ml b/src/stages/4-ast_typed/combinators.ml index 5abb2a2bc..9a8bf2af5 100644 --- a/src/stages/4-ast_typed/combinators.ml +++ b/src/stages/4-ast_typed/combinators.ml @@ -296,7 +296,6 @@ let e_lambda l : expression_content = E_lambda l let e_pair a b : expression_content = ez_e_record [(Label "0",a);(Label "1", b)] let e_application lamb args : expression_content = E_application {lamb;args} let e_variable v : expression_content = E_variable v -let e_list lst : expression_content = E_list lst let e_let_in let_binder inline rhs let_result = E_let_in { let_binder ; rhs ; let_result; inline } let e_a_unit = make_a_e (e_unit ()) (t_unit ()) @@ -315,7 +314,6 @@ let e_a_application a b = make_a_e (e_application a b) (get_type_expression b) let e_a_variable v ty = make_a_e (e_variable v) ty let ez_e_a_record r = make_a_e (ez_e_record r) (ez_t_record (List.map (fun (x, y) -> x, y.type_expression) r) ()) let e_a_map lst k v = make_a_e (e_map lst) (t_map k v ()) -let e_a_list lst t = make_a_e (e_list lst) (t_list t ()) let e_a_let_in binder expr body attributes = make_a_e (e_let_in binder expr body attributes) (get_type_expression body) diff --git a/src/stages/4-ast_typed/combinators.mli b/src/stages/4-ast_typed/combinators.mli index a42abd3cc..9bbd75504 100644 --- a/src/stages/4-ast_typed/combinators.mli +++ b/src/stages/4-ast_typed/combinators.mli @@ -128,7 +128,6 @@ val e_lambda : lambda -> expression_content val e_pair : expression -> expression -> expression_content val e_application : expression -> expr -> expression_content val e_variable : expression_variable -> expression_content -val e_list : expression list -> expression_content val e_let_in : expression_variable -> inline -> expression -> expression -> expression_content val e_a_unit : full_environment -> expression @@ -147,7 +146,6 @@ val e_a_application : expression -> expression -> full_environment -> expression val e_a_variable : expression_variable -> type_expression -> full_environment -> expression val ez_e_a_record : ( label * expression ) list -> full_environment -> expression val e_a_map : ( expression * expression ) list -> type_expression -> type_expression -> full_environment -> expression -val e_a_list : expression list -> type_expression -> full_environment -> expression val e_a_let_in : expression_variable -> bool -> expression -> expression -> full_environment -> expression val get_a_int : expression -> int result diff --git a/src/stages/4-ast_typed/combinators_environment.ml b/src/stages/4-ast_typed/combinators_environment.ml index f92ef3aea..e296ae914 100644 --- a/src/stages/4-ast_typed/combinators_environment.ml +++ b/src/stages/4-ast_typed/combinators_environment.ml @@ -15,7 +15,6 @@ let e_a_empty_some s = e_a_some s Environment.full_empty let e_a_empty_none t = e_a_none t Environment.full_empty let e_a_empty_record r = e_a_record r Environment.full_empty let e_a_empty_map lst k v = e_a_map lst k v Environment.full_empty -let e_a_empty_list lst t = e_a_list lst t Environment.full_empty let ez_e_a_empty_record r = ez_e_a_record r Environment.full_empty let e_a_empty_lambda l i o = e_a_lambda l i o Environment.full_empty diff --git a/src/stages/4-ast_typed/combinators_environment.mli b/src/stages/4-ast_typed/combinators_environment.mli index da4b2cfb9..ceb438afe 100644 --- a/src/stages/4-ast_typed/combinators_environment.mli +++ b/src/stages/4-ast_typed/combinators_environment.mli @@ -14,7 +14,6 @@ val e_a_empty_some : expression -> expression val e_a_empty_none : type_expression -> expression val e_a_empty_record : expression label_map -> expression val e_a_empty_map : (expression * expression ) list -> type_expression -> type_expression -> expression -val e_a_empty_list : expression list -> type_expression -> expression val ez_e_a_empty_record : ( label * expression ) list -> expression val e_a_empty_lambda : lambda -> type_expression -> type_expression -> expression diff --git a/src/stages/4-ast_typed/misc.ml b/src/stages/4-ast_typed/misc.ml index 5def088a8..6966fe414 100644 --- a/src/stages/4-ast_typed/misc.ml +++ b/src/stages/4-ast_typed/misc.ml @@ -211,8 +211,6 @@ module Free_variables = struct | E_record m -> unions @@ List.map self @@ LMap.to_list m | E_record_accessor {record;_} -> self record | E_record_update {record; update;_} -> union (self record) @@ self update - | E_list lst -> unions @@ List.map self lst - | E_set lst -> unions @@ List.map self lst | (E_map m | E_big_map m) -> unions @@ List.map self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m | E_matching {matchee; cases;_} -> union (self matchee) (matching_expression b cases) | E_let_in { let_binder; rhs; let_result; _} -> @@ -512,24 +510,6 @@ let rec assert_value_eq (a, b: (expression*expression)) : unit result = | (E_map _ | E_big_map _), _ -> fail @@ different_values_because_different_types "map vs. non-map" a b - | E_list lsta, E_list lstb -> ( - let%bind lst = - generic_try (different_size_values "lists of different lengths" a b) - (fun () -> List.combine lsta lstb) in - let%bind _all = bind_map_list assert_value_eq lst in - ok () - ) - | E_list _, _ -> - fail @@ different_values_because_different_types "list vs. non-list" a b - | E_set lsta, E_set lstb -> ( - let%bind lst = - generic_try (different_size_values "sets of different lengths" a b) - (fun () -> List.combine lsta lstb) in - let%bind _all = bind_map_list assert_value_eq lst in - ok () - ) - | E_set _, _ -> - fail @@ different_values_because_different_types "set vs. non-set" a b | (E_literal _, _) | (E_variable _, _) | (E_application _, _) | (E_lambda _, _) | (E_let_in _, _) | (E_recursive _, _) | (E_record_accessor _, _) | (E_record_update _,_) diff --git a/src/stages/4-ast_typed/misc_smart.ml b/src/stages/4-ast_typed/misc_smart.ml index 763bfa399..fa34a5014 100644 --- a/src/stages/4-ast_typed/misc_smart.ml +++ b/src/stages/4-ast_typed/misc_smart.ml @@ -75,12 +75,6 @@ module Captured_variables = struct let%bind r = self record in let%bind e = self update in ok @@ union r e - | E_list lst -> - let%bind lst' = bind_map_list self lst in - ok @@ unions lst' - | E_set lst -> - let%bind lst' = bind_map_list self lst in - ok @@ unions lst' | (E_map m | E_big_map m) -> let%bind lst' = bind_map_list self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m in ok @@ unions lst' diff --git a/src/stages/4-ast_typed/types.ml b/src/stages/4-ast_typed/types.ml index fa303e21c..b892d499f 100644 --- a/src/stages/4-ast_typed/types.ml +++ b/src/stages/4-ast_typed/types.ml @@ -53,8 +53,6 @@ and expression_content = (* TODO : move to constant*) | E_map of (expression * expression) list (*move to operator *) | E_big_map of (expression * expression) list (*move to operator *) - | E_list of expression list - | E_set of expression list and constant = { cons_name: constant' diff --git a/src/stages/5-mini_c/PP.ml b/src/stages/5-mini_c/PP.ml index dfbbfdd64..8f0316253 100644 --- a/src/stages/5-mini_c/PP.ml +++ b/src/stages/5-mini_c/PP.ml @@ -88,8 +88,6 @@ and expression' ppf (e:expression') = match e with | E_literal v -> fprintf ppf "L(%a)" value v | E_make_empty_map _ -> fprintf ppf "map[]" | E_make_empty_big_map _ -> fprintf ppf "big_map[]" - | E_make_empty_list _ -> fprintf ppf "list[]" - | E_make_empty_set _ -> fprintf ppf "set[]" | E_make_none _ -> fprintf ppf "none" | E_if_bool (c, a, b) -> fprintf ppf "%a ? %a : %a" expression c expression a expression b | E_if_none (c, n, ((name, _) , s)) -> fprintf ppf "%a ?? %a : %a -> %a" expression c expression n Var.pp name expression s @@ -199,6 +197,8 @@ and constant ppf : constant' -> unit = function | C_SET_FOLD -> fprintf ppf "SET_FOLD" | C_SET_MEM -> fprintf ppf "SET_MEM" (* List *) + | C_LIST_EMPTY -> fprintf ppf "LIST_EMPTY" + | C_LIST_LITERAL -> fprintf ppf "LIST_LITERAL" | C_LIST_ITER -> fprintf ppf "LIST_ITER" | C_LIST_MAP -> fprintf ppf "LIST_MAP" | C_LIST_FOLD -> fprintf ppf "LIST_FOLD" diff --git a/src/stages/5-mini_c/misc.ml b/src/stages/5-mini_c/misc.ml index 31c816178..bbcee5ed1 100644 --- a/src/stages/5-mini_c/misc.ml +++ b/src/stages/5-mini_c/misc.ml @@ -46,8 +46,6 @@ module Free_variables = struct | E_variable n -> var_name b n | E_make_empty_map _ -> empty | E_make_empty_big_map _ -> empty - | E_make_empty_list _ -> empty - | E_make_empty_set _ -> empty | E_make_none _ -> empty | E_iterator (_, ((v, _), body), expr) -> unions [ expression (union (singleton v) b) body ; diff --git a/src/stages/5-mini_c/types.ml b/src/stages/5-mini_c/types.ml index b1e419b8b..f16054a25 100644 --- a/src/stages/5-mini_c/types.ml +++ b/src/stages/5-mini_c/types.ml @@ -61,8 +61,6 @@ and expression' = | E_variable of var_name | E_make_empty_map of (type_value * type_value) | E_make_empty_big_map of (type_value * type_value) - | E_make_empty_list of type_value - | E_make_empty_set of type_value | E_make_none of type_value | E_iterator of constant' * ((var_name * type_value) * expression) * expression | E_fold of (((var_name * type_value) * expression) * expression * expression) diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index c3557f3d5..f8d594a89 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -105,6 +105,8 @@ let constant ppf : constant' -> unit = function | C_SET_FOLD -> fprintf ppf "SET_FOLD" | C_SET_MEM -> fprintf ppf "SET_MEM" (* List *) + | C_LIST_EMPTY -> fprintf ppf "LIST_EMPTY" + | C_LIST_LITERAL -> fprintf ppf "LIST_LITERAL" | C_LIST_ITER -> fprintf ppf "LIST_ITER" | C_LIST_MAP -> fprintf ppf "LIST_MAP" | C_LIST_FOLD -> fprintf ppf "LIST_FOLD" diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index 20964d3b6..6ffdb5485 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -247,6 +247,8 @@ and constant' = | C_SET_FOLD | C_SET_MEM (* List *) + | C_LIST_EMPTY + | C_LIST_LITERAL | C_LIST_ITER | C_LIST_MAP | C_LIST_FOLD diff --git a/src/stages/typesystem/misc.ml b/src/stages/typesystem/misc.ml index c74e9e8f1..ce7937c7e 100644 --- a/src/stages/typesystem/misc.ml +++ b/src/stages/typesystem/misc.ml @@ -204,12 +204,6 @@ module Substitution = struct ok @@ (val1 , val2) ) val_val_list in ok @@ T.E_big_map val_val_list - | T.E_list vals -> - let%bind vals = bind_map_list (s_expression ~substs) vals in - ok @@ T.E_list vals - | T.E_set vals -> - let%bind vals = bind_map_list (s_expression ~substs) vals in - ok @@ T.E_set vals | T.E_matching {matchee;cases} -> let%bind matchee = s_expression ~substs matchee in let%bind cases = s_matching_expr ~substs cases in From 330c48e66a26bce91cf2cec70d30b33fff4672c5 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Thu, 19 Mar 2020 16:55:13 +0100 Subject: [PATCH 3/5] remove Map and BIG_Map --- src/passes/10-interpreter/interpreter.ml | 5 - src/passes/10-transpiler/transpiler.ml | 28 ---- src/passes/10-transpiler/untranspiler.ml | 26 ++-- src/passes/11-self_mini_c/helpers.ml | 5 +- src/passes/11-self_mini_c/self_mini_c.ml | 2 - src/passes/11-self_mini_c/subst.ml | 5 +- src/passes/12-compiler/compiler_program.ml | 16 ++- src/passes/6-sugar_to_core/sugar_to_core.ml | 38 +++-- src/passes/8-typer-new/typer.ml | 130 ------------------ src/passes/8-typer-old/typer.ml | 94 ++++--------- src/passes/9-self_ast_typed/helpers.ml | 20 --- src/passes/9-self_ast_typed/tail_recursion.ml | 8 -- src/passes/operators/operators.ml | 6 + src/stages/3-ast_core/PP.ml | 4 - src/stages/3-ast_core/combinators.ml | 18 +-- src/stages/3-ast_core/combinators.mli | 5 - src/stages/3-ast_core/misc.ml | 30 ---- src/stages/3-ast_core/types.ml | 4 - src/stages/4-ast_typed/PP.ml | 4 - src/stages/4-ast_typed/combinators.ml | 3 - src/stages/4-ast_typed/combinators.mli | 2 - .../4-ast_typed/combinators_environment.ml | 1 - .../4-ast_typed/combinators_environment.mli | 1 - src/stages/4-ast_typed/misc.ml | 17 --- src/stages/4-ast_typed/misc_smart.ml | 3 - src/stages/4-ast_typed/types.ml | 4 - src/stages/5-mini_c/PP.ml | 3 +- src/stages/5-mini_c/misc.ml | 2 - src/stages/5-mini_c/types.ml | 2 - src/stages/common/PP.ml | 1 + src/stages/common/types.ml | 1 + src/stages/typesystem/misc.ml | 14 -- 32 files changed, 92 insertions(+), 410 deletions(-) diff --git a/src/passes/10-interpreter/interpreter.ml b/src/passes/10-interpreter/interpreter.ml index 6925a0243..2c06cab83 100644 --- a/src/passes/10-interpreter/interpreter.ml +++ b/src/passes/10-interpreter/interpreter.ml @@ -291,11 +291,6 @@ and eval : Ast_typed.expression -> env -> value result let%bind rhs' = eval rhs env in eval let_result (Env.extend env (let_binder,rhs')) ) - | E_map kvlist | E_big_map kvlist -> - let%bind kvlist' = bind_map_list - (fun kv -> bind_map_pair (fun (el:Ast_typed.expression) -> eval el env) kv) - kvlist in - ok @@ V_Map kvlist' | E_literal l -> eval_literal l | E_variable var -> diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index 82f048614..8554b2d8e 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -390,34 +390,6 @@ and transpile_annotated_expression (ae:AST.expression) : expression result = transpile_lambda l io | E_recursive r -> transpile_recursive r - | E_map m -> ( - let%bind (src, dst) = - trace_strong (corner_case ~loc:__LOC__ "not a map") @@ - Mini_c.Combinators.get_t_map tv in - let aux : expression result -> (AST.expression * AST.expression) -> expression result = fun prev (k, v) -> - let%bind prev' = prev in - let%bind (k', v') = - let v' = e_a_some v ae.environment in - bind_map_pair (transpile_annotated_expression) (k , v') in - return @@ E_constant {cons_name=C_UPDATE;arguments=[k' ; v' ; prev']} - in - let init = return @@ E_make_empty_map (src, dst) in - List.fold_left aux init m - ) - | E_big_map m -> ( - let%bind (src, dst) = - trace_strong (corner_case ~loc:__LOC__ "not a map") @@ - Mini_c.Combinators.get_t_big_map tv in - let aux : expression result -> (AST.expression * AST.expression) -> expression result = fun prev (k, v) -> - let%bind prev' = prev in - let%bind (k', v') = - let v' = e_a_some v ae.environment in - bind_map_pair (transpile_annotated_expression) (k , v') in - return @@ E_constant {cons_name=C_UPDATE;arguments=[k' ; v' ; prev']} - in - let init = return @@ E_make_empty_big_map (src, dst) in - List.fold_left aux init m - ) | E_matching {matchee=expr; cases=m} -> ( let%bind expr' = transpile_annotated_expression expr in match m with diff --git a/src/passes/10-transpiler/untranspiler.ml b/src/passes/10-transpiler/untranspiler.ml index e9a924c53..9a7149eed 100644 --- a/src/passes/10-transpiler/untranspiler.ml +++ b/src/passes/10-transpiler/untranspiler.ml @@ -151,28 +151,38 @@ let rec untranspile (v : value) (t : AST.type_expression) : AST.expression resul ok (e_a_empty_some s') ) | TC_map (k_ty,v_ty)-> ( - let%bind lst = + let%bind map = trace_strong (wrong_mini_c_value "map" v) @@ get_map v in - let%bind lst' = + let%bind map' = let aux = fun (k, v) -> let%bind k' = untranspile k k_ty in let%bind v' = untranspile v v_ty in ok (k', v') in - bind_map_list aux lst in - return (E_map lst') + bind_map_list aux map in + let aux = fun prev (k, v) -> + let (k', v') = (k , v ) in + return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k' ; v' ; prev]} + in + let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in + bind_fold_list aux init map' ) | TC_big_map (k_ty, v_ty) -> ( - let%bind lst = + let%bind map = trace_strong (wrong_mini_c_value "big_map" v) @@ get_big_map v in - let%bind lst' = + let%bind map' = let aux = fun (k, v) -> let%bind k' = untranspile k k_ty in let%bind v' = untranspile v v_ty in ok (k', v') in - bind_map_list aux lst in - return (E_big_map lst') + bind_map_list aux map in + let map' = List.sort_uniq compare map' in + let aux = fun prev (k, v) -> + return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k ; v ; prev]} + in + let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in + bind_fold_list aux init map' ) | TC_list ty -> ( let%bind lst = diff --git a/src/passes/11-self_mini_c/helpers.ml b/src/passes/11-self_mini_c/helpers.ml index ea6d1355c..fd35db639 100644 --- a/src/passes/11-self_mini_c/helpers.ml +++ b/src/passes/11-self_mini_c/helpers.ml @@ -25,8 +25,6 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini let%bind init' = f init e in match e.content with | E_variable _ | E_skip | E_make_none _ - | E_make_empty_map _ - | E_make_empty_big_map _ | E_literal _ -> ok init' | E_constant (c) -> ( let%bind res = bind_fold_list self init' c.arguments in @@ -90,8 +88,7 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> let return content = ok { e' with content } in match e'.content with | E_variable _ | E_literal _ | E_skip | E_make_none _ - | E_make_empty_map _ - | E_make_empty_big_map _ as em -> return em + as em -> return em | E_constant (c) -> ( let%bind lst = bind_map_list self c.arguments in return @@ E_constant {cons_name = c.cons_name; arguments = lst} diff --git a/src/passes/11-self_mini_c/self_mini_c.ml b/src/passes/11-self_mini_c/self_mini_c.ml index 56ee521df..95e03a661 100644 --- a/src/passes/11-self_mini_c/self_mini_c.ml +++ b/src/passes/11-self_mini_c/self_mini_c.ml @@ -47,8 +47,6 @@ let rec is_pure : expression -> bool = fun e -> | E_closure _ | E_skip | E_variable _ - | E_make_empty_map _ - | E_make_empty_big_map _ | E_make_none _ -> true diff --git a/src/passes/11-self_mini_c/subst.ml b/src/passes/11-self_mini_c/subst.ml index 1914cbe2c..1637a7bbe 100644 --- a/src/passes/11-self_mini_c/subst.ml +++ b/src/passes/11-self_mini_c/subst.ml @@ -40,8 +40,6 @@ let rec replace : expression -> var_name -> var_name -> expression = | E_variable z -> let z = replace_var z in return @@ E_variable z - | E_make_empty_map _ -> e - | E_make_empty_big_map _ -> e | E_make_none _ -> e | E_iterator (name, ((v, tv), body), expr) -> let body = replace body in @@ -173,8 +171,7 @@ let rec subst_expression : body:expression -> x:var_name -> expr:expression -> e ) (* All that follows is boilerplate *) | E_literal _ | E_skip | E_make_none _ - | E_make_empty_map (_,_) - | E_make_empty_big_map _ as em -> return em + as em -> return em | E_constant (c) -> ( let lst = List.map self c.arguments in return @@ E_constant {cons_name = c.cons_name; arguments = lst } diff --git a/src/passes/12-compiler/compiler_program.ml b/src/passes/12-compiler/compiler_program.ml index 2ebfcbc34..200bd0cf9 100644 --- a/src/passes/12-compiler/compiler_program.ml +++ b/src/passes/12-compiler/compiler_program.ml @@ -76,6 +76,16 @@ let rec get_operator : constant' -> type_value -> expression list -> predicate r let%bind m_ty = Compiler_type.type_ ty' in ok @@ simple_constant @@ i_empty_set m_ty ) + | C_MAP_EMPTY -> ( + let%bind sd = Mini_c.get_t_map ty in + let%bind (src, dst) = bind_map_pair Compiler_type.type_ sd in + ok @@ simple_constant @@ i_empty_map src dst + ) + | C_BIG_MAP_EMPTY -> ( + let%bind sd = Mini_c.get_t_big_map ty in + let%bind (src, dst) = bind_map_pair Compiler_type.type_ sd in + ok @@ simple_constant @@ i_empty_big_map src dst + ) | C_BYTES_UNPACK -> ( let%bind ty' = Mini_c.get_t_option ty in let%bind m_ty = Compiler_type.type_ ty' in @@ -302,12 +312,6 @@ and translate_expression (expr:expression) (env:environment) : michelson result error title content in trace error @@ return code - | E_make_empty_map sd -> - let%bind (src, dst) = bind_map_pair Compiler_type.type_ sd in - return @@ i_empty_map src dst - | E_make_empty_big_map sd -> - let%bind (src, dst) = bind_map_pair Compiler_type.type_ sd in - return @@ i_empty_big_map src dst | E_make_none o -> let%bind o' = Compiler_type.type_ o in return @@ i_none o' diff --git a/src/passes/6-sugar_to_core/sugar_to_core.ml b/src/passes/6-sugar_to_core/sugar_to_core.ml index 6c664a45b..e79ab336f 100644 --- a/src/passes/6-sugar_to_core/sugar_to_core.ml +++ b/src/passes/6-sugar_to_core/sugar_to_core.ml @@ -108,18 +108,24 @@ let rec compile_expression : I.expression -> O.expression result = let%bind record = compile_expression record in let%bind update = compile_expression update in return @@ O.E_record_update {record;path;update} - | I.E_map map -> - let%bind map = bind_map_list ( - bind_map_pair compile_expression - ) map + | I.E_map map -> ( + let map = List.sort_uniq compare map in + let aux = fun prev (k, v) -> + let%bind (k', v') = bind_map_pair (compile_expression) (k, v) in + return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k' ; v' ; prev]} in - return @@ O.E_map map - | I.E_big_map big_map -> - let%bind big_map = bind_map_list ( - bind_map_pair compile_expression - ) big_map + let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in + bind_fold_list aux init map + ) + | I.E_big_map big_map -> ( + let map = List.sort_uniq compare big_map in + let aux = fun prev (k, v) -> + let%bind (k', v') = bind_map_pair (compile_expression) (k, v) in + return @@ E_constant {cons_name=C_BIG_MAP_ADD;arguments=[k' ; v' ; prev]} in - return @@ O.E_big_map big_map + let%bind init = return @@ E_constant {cons_name=C_BIG_MAP_EMPTY;arguments=[]} in + bind_fold_list aux init map + ) | I.E_list lst -> let%bind lst' = bind_map_list (compile_expression) lst in let aux = fun prev cur -> @@ -309,18 +315,6 @@ let rec uncompile_expression : O.expression -> I.expression result = let%bind record = uncompile_expression record in let%bind update = uncompile_expression update in return @@ I.E_record_update {record;path;update} - | O.E_map map -> - let%bind map = bind_map_list ( - bind_map_pair uncompile_expression - ) map - in - return @@ I.E_map map - | O.E_big_map big_map -> - let%bind big_map = bind_map_list ( - bind_map_pair uncompile_expression - ) big_map - in - return @@ I.E_big_map big_map | O.E_ascription {anno_expr; type_annotation} -> let%bind anno_expr = uncompile_expression anno_expr in let%bind type_annotation = uncompile_type_expression type_annotation in diff --git a/src/passes/8-typer-new/typer.ml b/src/passes/8-typer-new/typer.ml index 754659597..6166666bc 100644 --- a/src/passes/8-typer-new/typer.ml +++ b/src/passes/8-typer-new/typer.ml @@ -163,7 +163,6 @@ end open Errors -let swap (a,b) = ok (b,a) (* let rec type_program (p:I.program) : O.program result = let aux (e, acc:(environment * O.declaration Location.wrap list)) (d:I.declaration Location.wrap) = @@ -503,129 +502,6 @@ and type_expression : environment -> Solver.state -> ?tv_opt:O.type_expression - return_wrapped (E_record_update {record; path; update}) state (Wrap.record wrapped) (* Data-structure *) -(* - | E_list lst -> - let%bind lst' = bind_map_list (type_expression e) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_value_eq (c, c') in - ok (Some c') in - let%bind init = match tv_opt with - | None -> ok None - | Some ty -> - let%bind ty' = get_t_list ty in - ok (Some ty') in - let%bind ty = - let%bind opt = bind_fold_list aux init - @@ List.map get_type_annotation lst' in - trace_option (needs_annotation ae "empty list") opt in - ok (t_list ty ()) - in - return (E_list lst') tv - | E_set lst -> - let%bind lst' = bind_map_list (type_expression e) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_value_eq (c, c') in - ok (Some c') in - let%bind init = match tv_opt with - | None -> ok None - | Some ty -> - let%bind ty' = get_t_set ty in - ok (Some ty') in - let%bind ty = - let%bind opt = bind_fold_list aux init - @@ List.map get_type_annotation lst' in - trace_option (needs_annotation ae "empty set") opt in - ok (t_set ty ()) - in - return (E_set lst') tv - | E_map lst -> - let%bind lst' = bind_map_list (bind_map_pair (type_expression e)) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_value_eq (c, c') in - ok (Some c') in - let%bind key_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_annotation - @@ List.map fst lst' in - let%bind annot = bind_map_option get_t_map_key tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - let%bind value_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_annotation - @@ List.map snd lst' in - let%bind annot = bind_map_option get_t_map_value tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - ok (t_map key_type value_type ()) - in - return (E_map lst') tv -*) - - | E_map map -> - let aux' state' elt = type_expression e state' elt >>? swap in - let aux = fun state' elt -> bind_fold_map_pair aux' state' elt in - let%bind (state', map') = - bind_fold_map_list aux state map in - let aux (x, y) = O.(x.type_expression , y.type_expression) in - let wrapped = Wrap.map (List.map aux map') in - return_wrapped (E_map map') state' wrapped - - (* | E_big_map lst -> - * let%bind lst' = bind_map_list (bind_map_pair (type_expression e)) lst in - * let%bind tv = - * let aux opt c = - * match opt with - * | None -> ok (Some c) - * | Some c' -> - * let%bind _eq = Ast_typed.assert_type_value_eq (c, c') in - * ok (Some c') in - * let%bind key_type = - * let%bind sub = - * bind_fold_list aux None - * @@ List.map get_type_annotation - * @@ List.map fst lst' in - * let%bind annot = bind_map_option get_t_big_map_key tv_opt in - * trace (simple_info "empty map expression without a type annotation") @@ - * O.merge_annotation annot sub (needs_annotation ae "this map literal") - * in - * let%bind value_type = - * let%bind sub = - * bind_fold_list aux None - * @@ List.map get_type_annotation - * @@ List.map snd lst' in - * let%bind annot = bind_map_option get_t_big_map_value tv_opt in - * trace (simple_info "empty map expression without a type annotation") @@ - * O.merge_annotation annot sub (needs_annotation ae "this map literal") - * in - * ok (t_big_map key_type value_type ()) - * in - * return (E_big_map lst') tv *) - | E_big_map big_map -> - let aux' state' elt = type_expression e state' elt >>? swap in - let aux = fun state' elt -> bind_fold_map_pair aux' state' elt in - let%bind (state', big_map') = - bind_fold_map_list aux state big_map in - let aux (x, y) = O.(x.type_expression , y.type_expression) in - let wrapped = Wrap.big_map (List.map aux big_map') in - return_wrapped (E_big_map big_map') state' wrapped - (* | E_lambda { * binder ; * input_type ; @@ -1042,12 +918,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = let%bind e = untype_expression update in let Label l = path in return (e_update r' l e) - | E_map m -> - let%bind m' = bind_map_list (bind_map_pair untype_expression) m in - return (e_map m') - | E_big_map m -> - let%bind m' = bind_map_list (bind_map_pair untype_expression) m in - return (e_big_map m') | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index 879c44b19..ce64fa5b9 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -511,66 +511,6 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let%bind () = O.assert_type_expression_eq (tv, get_type_expression update) in return (E_record_update {record; path; update}) wrapped (* Data-structure *) - | E_map lst -> - let%bind lst' = bind_map_list (bind_map_pair (type_expression' e)) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_expression_eq (c, c') in - ok (Some c') in - let%bind key_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_expression - @@ List.map fst lst' in - let%bind annot = bind_map_option get_t_map_key tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - let%bind value_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_expression - @@ List.map snd lst' in - let%bind annot = bind_map_option get_t_map_value tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - ok (t_map key_type value_type ()) - in - return (E_map lst') tv - | E_big_map lst -> - let%bind lst' = bind_map_list (bind_map_pair (type_expression' e)) lst in - let%bind tv = - let aux opt c = - match opt with - | None -> ok (Some c) - | Some c' -> - let%bind _eq = Ast_typed.assert_type_expression_eq (c, c') in - ok (Some c') in - let%bind key_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_expression - @@ List.map fst lst' in - let%bind annot = bind_map_option get_t_big_map_key tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - let%bind value_type = - let%bind sub = - bind_fold_list aux None - @@ List.map get_type_expression - @@ List.map snd lst' in - let%bind annot = bind_map_option get_t_big_map_value tv_opt in - trace (simple_info "empty map expression without a type annotation") @@ - O.merge_annotation annot sub (needs_annotation ae "this map literal") - in - ok (t_big_map key_type value_type ()) - in - return (E_big_map lst') tv | E_lambda lambda -> let%bind (lambda, lambda_type) = type_lambda e lambda in return (E_lambda lambda ) lambda_type @@ -655,6 +595,34 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let tv_lst = [tv_key;tv_set] in let%bind (name', tv) = type_constant cst tv_lst tv_opt in return (E_constant {cons_name=name';arguments=[key';set']}) tv + | E_constant {cons_name=C_MAP_ADD as cst; arguments=[key;value;map]} -> + let%bind key' = type_expression' e key in + let%bind val' = type_expression' e value in + let tv_key = get_type_expression key' in + let tv_val = get_type_expression val' in + let tv = match tv_opt with + Some (tv) -> tv + | None -> t_map tv_key tv_val () + in + let%bind map' = type_expression' e ~tv_opt:tv map in + let tv_map = get_type_expression map' in + let tv_lst = [tv_key;tv_val;tv_map] in + let%bind (name', tv) = type_constant cst tv_lst tv_opt in + return (E_constant {cons_name=name';arguments=[key';val';map']}) tv + | E_constant {cons_name=C_BIG_MAP_ADD as cst; arguments=[key;value;map]} -> + let%bind key' = type_expression' e key in + let%bind val' = type_expression' e value in + let tv_key = get_type_expression key' in + let tv_val = get_type_expression val' in + let tv = match tv_opt with + Some (tv) -> tv + | None -> t_big_map tv_key tv_val () + in + let%bind map' = type_expression' e ~tv_opt:tv map in + let tv_map = get_type_expression map' in + let tv_lst = [tv_key;tv_val;tv_map] in + let%bind (name', tv) = type_constant cst tv_lst tv_opt in + return (E_constant {cons_name=name';arguments=[key';val';map']}) tv | E_constant {cons_name;arguments} -> let%bind lst' = bind_list @@ List.map (type_expression' e) arguments in let tv_lst = List.map get_type_expression lst' in @@ -838,12 +806,6 @@ let rec untype_expression (e:O.expression) : (I.expression) result = let%bind e = untype_expression e in let Label l = l in return (e_update r' l e) - | E_map m -> - let%bind m' = bind_map_list (bind_map_pair untype_expression) m in - return (e_map m') - | E_big_map m -> - let%bind m' = bind_map_list (bind_map_pair untype_expression) m in - return (e_big_map m') | E_matching {matchee;cases} -> let%bind ae' = untype_expression matchee in let%bind m' = untype_matching untype_expression cases in diff --git a/src/passes/9-self_ast_typed/helpers.ml b/src/passes/9-self_ast_typed/helpers.ml index 76d6c0f21..92e887282 100644 --- a/src/passes/9-self_ast_typed/helpers.ml +++ b/src/passes/9-self_ast_typed/helpers.ml @@ -12,10 +12,6 @@ let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f ini let%bind res = bind_fold_list self init' lst in ok res ) - | E_map lst | E_big_map lst -> ( - let%bind res = bind_fold_list (bind_fold_pair self) init' lst in - ok res - ) | E_application {lamb; args} -> ( let ab = (lamb, args) in let%bind res = bind_fold_pair self init' ab in @@ -90,14 +86,6 @@ let rec map_expression : mapper -> expression -> expression result = fun f e -> let%bind e' = f e in let return expression_content = ok { e' with expression_content } in match e'.expression_content with - | E_map lst -> ( - let%bind lst' = bind_map_list (bind_map_pair self) lst in - return @@ E_map lst' - ) - | E_big_map lst -> ( - let%bind lst' = bind_map_list (bind_map_pair self) lst in - return @@ E_big_map lst' - ) | E_matching {matchee=e;cases} -> ( let%bind e' = self e in let%bind cases' = map_cases f cases in @@ -193,14 +181,6 @@ let rec fold_map_expression : 'a fold_mapper -> 'a -> expression -> ('a * expres else let return expression_content = { e' with expression_content } in match e'.expression_content with - | E_map lst -> ( - let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in - ok (res, return @@ E_map lst') - ) - | E_big_map lst -> ( - let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in - ok (res, return @@ E_big_map lst') - ) | E_matching {matchee=e;cases} -> ( let%bind (res, e') = self init' e in let%bind (res,cases') = fold_map_cases f res cases in diff --git a/src/passes/9-self_ast_typed/tail_recursion.ml b/src/passes/9-self_ast_typed/tail_recursion.ml index f5f30e923..00847e79f 100644 --- a/src/passes/9-self_ast_typed/tail_recursion.ml +++ b/src/passes/9-self_ast_typed/tail_recursion.ml @@ -56,14 +56,6 @@ let rec check_recursive_call : expression_variable -> bool -> expression -> unit let%bind _ = check_recursive_call n false record in let%bind _ = check_recursive_call n false update in ok () - | E_map eel | E_big_map eel-> - let aux (e1,e2) = - let%bind _ = check_recursive_call n false e1 in - let%bind _ = check_recursive_call n false e2 in - ok () - in - let%bind _ = bind_map_list aux eel in - ok () and check_recursive_call_in_matching = fun n final_path c -> match c with diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 8e011b316..9e6a093af 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -621,6 +621,11 @@ module Typer = struct let%bind () = assert_type_expression_eq (src , k) in ok m + let map_empty = typer_0 "MAP_EMPTY" @@ fun tv_opt -> + match tv_opt with + | None -> simple_fail "untyped MAP_EMPTY" + | Some t -> ok t + let map_add : typer = typer_3 "MAP_ADD" @@ fun k v m -> let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) m in let%bind () = assert_type_expression_eq (src, k) in @@ -1165,6 +1170,7 @@ module Typer = struct | C_LIST_MAP -> ok @@ list_map ; | C_LIST_FOLD -> ok @@ list_fold ; (* MAP *) + | C_MAP_EMPTY -> ok @@ map_empty ; | C_MAP_ADD -> ok @@ map_add ; | C_MAP_REMOVE -> ok @@ map_remove ; | C_MAP_UPDATE -> ok @@ map_update ; diff --git a/src/stages/3-ast_core/PP.ml b/src/stages/3-ast_core/PP.ml index 149a92631..10ab7e9d4 100644 --- a/src/stages/3-ast_core/PP.ml +++ b/src/stages/3-ast_core/PP.ml @@ -31,10 +31,6 @@ and expression_content ppf (ec : expression_content) = fprintf ppf "%a.%a" expression ra.record label ra.label | E_record_update {record; path; update} -> fprintf ppf "{ %a with { %a = %a } }" expression record label path expression update - | E_map m -> - fprintf ppf "map[%a]" (list_sep_d assoc_expression) m - | E_big_map m -> - fprintf ppf "big_map[%a]" (list_sep_d assoc_expression) m | E_lambda {binder; input_type; output_type; result} -> fprintf ppf "lambda (%a:%a) : %a return %a" expression_variable binder diff --git a/src/stages/3-ast_core/combinators.ml b/src/stages/3-ast_core/combinators.ml index a1fdd1242..2c5dbf56d 100644 --- a/src/stages/3-ast_core/combinators.ml +++ b/src/stages/3-ast_core/combinators.ml @@ -107,12 +107,10 @@ let e_bytes_raw ?loc (b: bytes) : expression = make_expr ?loc @@ E_literal (Literal_bytes b) let e_bytes_string ?loc (s: string) : expression = make_expr ?loc @@ E_literal (Literal_bytes (Hex.to_bytes (Hex.of_string s))) -let e_big_map ?loc lst : expression = make_expr ?loc @@ E_big_map lst let e_some ?loc s : expression = make_expr ?loc @@ E_constant {cons_name = C_SOME; arguments = [s]} let e_none ?loc () : expression = make_expr ?loc @@ E_constant {cons_name = C_NONE; arguments = []} let e_string_cat ?loc sl sr : expression = make_expr ?loc @@ E_constant {cons_name = C_CONCAT; arguments = [sl ; sr ]} let e_map_add ?loc k v old : expression = make_expr ?loc @@ E_constant {cons_name = C_MAP_ADD; arguments = [k ; v ; old]} -let e_map ?loc lst : expression = make_expr ?loc @@ E_map lst let e_constructor ?loc s a : expression = make_expr ?loc @@ E_constructor { constructor = Constructor s; element = a} let e_matching ?loc a b : expression = make_expr ?loc @@ E_matching {matchee=a;cases=b} let e_matching_bool ?loc a b c : expression = e_matching ?loc a (Match_bool {match_true = b ; match_false = c}) @@ -158,10 +156,6 @@ let e_typed_none ?loc t_opt = let type_annotation = t_option t_opt in e_annotation ?loc (e_none ?loc ()) type_annotation -let e_typed_map ?loc lst k v = e_annotation ?loc (e_map lst) (t_map k v) -let e_typed_big_map ?loc lst k v = e_annotation ?loc (e_big_map lst) (t_big_map k v) - - let e_lambda ?loc (binder : expression_variable) (input_type : type_expression option) (output_type : type_expression option) @@ -255,6 +249,12 @@ let extract_record : expression -> (label * expression) list result = fun e -> | _ -> fail @@ bad_kind "record" e.location let extract_map : expression -> (expression * expression) list result = fun e -> - match e.expression_content with - | E_map lst -> ok lst - | _ -> fail @@ bad_kind "map" e.location + let rec aux e = + match e.expression_content with + E_constant {cons_name=C_UPDATE; arguments=[k;v;map]} -> + let%bind map = aux map in + ok @@ (k,v)::map + | E_constant {cons_name=C_MAP_EMPTY; arguments=[]} -> ok @@ [] + | _ -> fail @@ bad_kind "map" e.location + in + aux e diff --git a/src/stages/3-ast_core/combinators.mli b/src/stages/3-ast_core/combinators.mli index dfb78bf43..40a2a8496 100644 --- a/src/stages/3-ast_core/combinators.mli +++ b/src/stages/3-ast_core/combinators.mli @@ -65,7 +65,6 @@ val e'_bytes : string -> expression_content result val e_bytes_hex : ?loc:Location.t -> string -> expression result val e_bytes_raw : ?loc:Location.t -> bytes -> expression val e_bytes_string : ?loc:Location.t -> string -> expression -val e_big_map : ?loc:Location.t -> ( expr * expr ) list -> expression val e_record_ez : ?loc:Location.t -> ( string * expr ) list -> expression val e_tuple : ?loc:Location.t -> expression list -> expression @@ -73,7 +72,6 @@ val e_some : ?loc:Location.t -> expression -> expression val e_none : ?loc:Location.t -> unit -> expression val e_string_cat : ?loc:Location.t -> expression -> expression -> expression val e_map_add : ?loc:Location.t -> expression -> expression -> expression -> expression -val e_map : ?loc:Location.t -> ( expression * expression ) list -> expression val e_pair : ?loc:Location.t -> expression -> expression -> expression val e_constructor : ?loc:Location.t -> string -> expression -> expression val e_matching : ?loc:Location.t -> expression -> matching_expr -> expression @@ -94,9 +92,6 @@ val make_option_typed : ?loc:Location.t -> expression -> type_expression option val e_typed_none : ?loc:Location.t -> type_expression -> expression -val e_typed_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression -val e_typed_big_map : ?loc:Location.t -> ( expression * expression ) list -> type_expression -> type_expression -> expression - val e_lambda : ?loc:Location.t -> expression_variable -> type_expression option -> type_expression option -> expression -> expression val e_recursive : ?loc:Location.t -> expression_variable -> type_expression -> lambda -> expression val e_record : ?loc:Location.t -> expr Map.String.t -> expression diff --git a/src/stages/3-ast_core/misc.ml b/src/stages/3-ast_core/misc.ml index fc5319eed..ad38b9fec 100644 --- a/src/stages/3-ast_core/misc.ml +++ b/src/stages/3-ast_core/misc.ml @@ -88,19 +88,6 @@ let rec assert_value_eq (a, b: (expression * expression )) : unit result = assert_literal_eq (a, b) | E_literal _ , _ -> simple_fail "comparing a literal with not a literal" - | E_constant {cons_name=C_SET_LITERAL;arguments=lsta}, - E_constant {cons_name=C_SET_LITERAL;arguments=lstb} -> ( - let lsta' = List.sort (compare) lsta in - let lstb' = List.sort (compare) lstb in - let%bind lst = - generic_try (simple_error "set of different lengths") - (fun () -> List.combine lsta' lstb') in - let%bind _all = bind_map_list assert_value_eq lst in - ok () - ) - | E_constant {cons_name=C_SET_LITERAL;_}, _ -> - simple_fail "comparing set with other expression" - | E_constant (ca) , E_constant (cb) when ca.cons_name = cb.cons_name -> ( let%bind lst = generic_try (simple_error "constants with different number of elements") @@ -152,23 +139,6 @@ let rec assert_value_eq (a, b: (expression * expression )) : unit result = ok () | E_record_update _, _ -> simple_fail "comparing record update with other expression" - - | (E_map lsta, E_map lstb | E_big_map lsta, E_big_map lstb) -> ( - let%bind lst = generic_try (simple_error "maps of different lengths") - (fun () -> - let lsta' = List.sort compare lsta in - let lstb' = List.sort compare lstb in - List.combine lsta' lstb') in - let aux = fun ((ka, va), (kb, vb)) -> - let%bind _ = assert_value_eq (ka, kb) in - let%bind _ = assert_value_eq (va, vb) in - ok () in - let%bind _all = bind_map_list aux lst in - ok () - ) - | (E_map _ | E_big_map _), _ -> - simple_fail "comparing map with other expression" - | (E_ascription a , _b') -> assert_value_eq (a.anno_expr , b) | (_a' , E_ascription b) -> assert_value_eq (a , b.anno_expr) | (E_variable _, _) | (E_lambda _, _) diff --git a/src/stages/3-ast_core/types.ml b/src/stages/3-ast_core/types.ml index ae3bb2283..ac59228c7 100644 --- a/src/stages/3-ast_core/types.ml +++ b/src/stages/3-ast_core/types.ml @@ -43,10 +43,6 @@ and expression_content = | E_record of expression label_map | E_record_accessor of accessor | E_record_update of update - (* Data Structures *) - (* TODO : move to constant*) - | E_map of (expression * expression) list (*move to operator *) - | E_big_map of (expression * expression) list (*move to operator *) (* Advanced *) | E_ascription of ascription diff --git a/src/stages/4-ast_typed/PP.ml b/src/stages/4-ast_typed/PP.ml index 62e085c51..7461dd7de 100644 --- a/src/stages/4-ast_typed/PP.ml +++ b/src/stages/4-ast_typed/PP.ml @@ -32,10 +32,6 @@ and expression_content ppf (ec: expression_content) = fprintf ppf "%a.%a" expression ra.record label ra.label | E_record_update {record; path; update} -> fprintf ppf "{ %a with { %a = %a } }" expression record label path expression update - | E_map m -> - fprintf ppf "map[%a]" (list_sep_d assoc_expression) m - | E_big_map m -> - fprintf ppf "big_map[%a]" (list_sep_d assoc_expression) m | E_lambda {binder; result} -> fprintf ppf "lambda (%a) return %a" expression_variable binder expression result diff --git a/src/stages/4-ast_typed/combinators.ml b/src/stages/4-ast_typed/combinators.ml index 9a8bf2af5..9961dbc0a 100644 --- a/src/stages/4-ast_typed/combinators.ml +++ b/src/stages/4-ast_typed/combinators.ml @@ -276,8 +276,6 @@ let ez_e_record (lst : (label * expression) list) : expression_content = let e_some s : expression_content = E_constant {cons_name=C_SOME;arguments=[s]} let e_none (): expression_content = E_constant {cons_name=C_NONE; arguments=[]} -let e_map lst : expression_content = E_map lst - let e_unit () : expression_content = E_literal (Literal_unit) let e_int n : expression_content = E_literal (Literal_int n) let e_nat n : expression_content = E_literal (Literal_nat n) @@ -313,7 +311,6 @@ let e_a_record r = make_a_e (e_record r) (t_record (LMap.map get_type_expression let e_a_application a b = make_a_e (e_application a b) (get_type_expression b) let e_a_variable v ty = make_a_e (e_variable v) ty let ez_e_a_record r = make_a_e (ez_e_record r) (ez_t_record (List.map (fun (x, y) -> x, y.type_expression) r) ()) -let e_a_map lst k v = make_a_e (e_map lst) (t_map k v ()) let e_a_let_in binder expr body attributes = make_a_e (e_let_in binder expr body attributes) (get_type_expression body) diff --git a/src/stages/4-ast_typed/combinators.mli b/src/stages/4-ast_typed/combinators.mli index 9bbd75504..dd88ffd00 100644 --- a/src/stages/4-ast_typed/combinators.mli +++ b/src/stages/4-ast_typed/combinators.mli @@ -109,7 +109,6 @@ val ez_e_record : ( string * expression ) list -> expression *) val e_some : expression -> expression_content val e_none : unit -> expression_content -val e_map : ( expression * expression ) list -> expression_content val e_unit : unit -> expression_content val e_int : int -> expression_content val e_nat : int -> expression_content @@ -145,7 +144,6 @@ val e_a_record : expression label_map -> full_environment -> expression val e_a_application : expression -> expression -> full_environment -> expression val e_a_variable : expression_variable -> type_expression -> full_environment -> expression val ez_e_a_record : ( label * expression ) list -> full_environment -> expression -val e_a_map : ( expression * expression ) list -> type_expression -> type_expression -> full_environment -> expression val e_a_let_in : expression_variable -> bool -> expression -> expression -> full_environment -> expression val get_a_int : expression -> int result diff --git a/src/stages/4-ast_typed/combinators_environment.ml b/src/stages/4-ast_typed/combinators_environment.ml index e296ae914..f73c2b305 100644 --- a/src/stages/4-ast_typed/combinators_environment.ml +++ b/src/stages/4-ast_typed/combinators_environment.ml @@ -14,7 +14,6 @@ let e_a_empty_pair a b = e_a_pair a b Environment.full_empty let e_a_empty_some s = e_a_some s Environment.full_empty let e_a_empty_none t = e_a_none t Environment.full_empty let e_a_empty_record r = e_a_record r Environment.full_empty -let e_a_empty_map lst k v = e_a_map lst k v Environment.full_empty let ez_e_a_empty_record r = ez_e_a_record r Environment.full_empty let e_a_empty_lambda l i o = e_a_lambda l i o Environment.full_empty diff --git a/src/stages/4-ast_typed/combinators_environment.mli b/src/stages/4-ast_typed/combinators_environment.mli index ceb438afe..830ac7ee2 100644 --- a/src/stages/4-ast_typed/combinators_environment.mli +++ b/src/stages/4-ast_typed/combinators_environment.mli @@ -13,7 +13,6 @@ val e_a_empty_pair : expression -> expression -> expression val e_a_empty_some : expression -> expression val e_a_empty_none : type_expression -> expression val e_a_empty_record : expression label_map -> expression -val e_a_empty_map : (expression * expression ) list -> type_expression -> type_expression -> expression val ez_e_a_empty_record : ( label * expression ) list -> expression val e_a_empty_lambda : lambda -> type_expression -> type_expression -> expression diff --git a/src/stages/4-ast_typed/misc.ml b/src/stages/4-ast_typed/misc.ml index 6966fe414..f101f3857 100644 --- a/src/stages/4-ast_typed/misc.ml +++ b/src/stages/4-ast_typed/misc.ml @@ -211,7 +211,6 @@ module Free_variables = struct | E_record m -> unions @@ List.map self @@ LMap.to_list m | E_record_accessor {record;_} -> self record | E_record_update {record; update;_} -> union (self record) @@ self update - | (E_map m | E_big_map m) -> unions @@ List.map self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m | E_matching {matchee; cases;_} -> union (self matchee) (matching_expression b cases) | E_let_in { let_binder; rhs; let_result; _} -> let b' = union (singleton let_binder) b in @@ -494,22 +493,6 @@ let rec assert_value_eq (a, b: (expression*expression)) : unit result = | E_record _, _ -> fail @@ (different_values_because_different_types "record vs. non-record" a b) - | (E_map lsta, E_map lstb | E_big_map lsta, E_big_map lstb) -> ( - let%bind lst = generic_try (different_size_values "maps of different lengths" a b) - (fun () -> - let lsta' = List.sort compare lsta in - let lstb' = List.sort compare lstb in - List.combine lsta' lstb') in - let aux = fun ((ka, va), (kb, vb)) -> - let%bind _ = assert_value_eq (ka, kb) in - let%bind _ = assert_value_eq (va, vb) in - ok () in - let%bind _all = bind_map_list aux lst in - ok () - ) - | (E_map _ | E_big_map _), _ -> - fail @@ different_values_because_different_types "map vs. non-map" a b - | (E_literal _, _) | (E_variable _, _) | (E_application _, _) | (E_lambda _, _) | (E_let_in _, _) | (E_recursive _, _) | (E_record_accessor _, _) | (E_record_update _,_) diff --git a/src/stages/4-ast_typed/misc_smart.ml b/src/stages/4-ast_typed/misc_smart.ml index fa34a5014..b4a0b5095 100644 --- a/src/stages/4-ast_typed/misc_smart.ml +++ b/src/stages/4-ast_typed/misc_smart.ml @@ -75,9 +75,6 @@ module Captured_variables = struct let%bind r = self record in let%bind e = self update in ok @@ union r e - | (E_map m | E_big_map m) -> - let%bind lst' = bind_map_list self @@ List.concat @@ List.map (fun (a, b) -> [ a ; b ]) m in - ok @@ unions lst' | E_matching {matchee;cases;_} -> let%bind a' = self matchee in let%bind cs' = matching_expression b cases in diff --git a/src/stages/4-ast_typed/types.ml b/src/stages/4-ast_typed/types.ml index b892d499f..e5ef3dd36 100644 --- a/src/stages/4-ast_typed/types.ml +++ b/src/stages/4-ast_typed/types.ml @@ -49,10 +49,6 @@ and expression_content = | E_record of expression label_map | E_record_accessor of accessor | E_record_update of update - (* Data Structures *) - (* TODO : move to constant*) - | E_map of (expression * expression) list (*move to operator *) - | E_big_map of (expression * expression) list (*move to operator *) and constant = { cons_name: constant' diff --git a/src/stages/5-mini_c/PP.ml b/src/stages/5-mini_c/PP.ml index 8f0316253..1231f5ed6 100644 --- a/src/stages/5-mini_c/PP.ml +++ b/src/stages/5-mini_c/PP.ml @@ -86,8 +86,6 @@ and expression' ppf (e:expression') = match e with | E_constant c -> fprintf ppf "%a %a" constant c.cons_name (pp_print_list ~pp_sep:space_sep expression) c.arguments | E_literal v -> fprintf ppf "L(%a)" value v - | E_make_empty_map _ -> fprintf ppf "map[]" - | E_make_empty_big_map _ -> fprintf ppf "big_map[]" | E_make_none _ -> fprintf ppf "none" | E_if_bool (c, a, b) -> fprintf ppf "%a ? %a : %a" expression c expression a expression b | E_if_none (c, n, ((name, _) , s)) -> fprintf ppf "%a ?? %a : %a -> %a" expression c expression n Var.pp name expression s @@ -219,6 +217,7 @@ and constant ppf : constant' -> unit = function | C_MAP_FIND_OPT -> fprintf ppf "MAP_FIND_OP" (* Big Maps *) | C_BIG_MAP -> fprintf ppf "BIG_MAP" + | C_BIG_MAP_ADD -> fprintf ppf "BIG_MAP_ADD" | C_BIG_MAP_EMPTY -> fprintf ppf "BIG_MAP_EMPTY" | C_BIG_MAP_LITERAL -> fprintf ppf "BIG_MAP_LITERAL" (* Crypto *) diff --git a/src/stages/5-mini_c/misc.ml b/src/stages/5-mini_c/misc.ml index bbcee5ed1..5aef14523 100644 --- a/src/stages/5-mini_c/misc.ml +++ b/src/stages/5-mini_c/misc.ml @@ -44,8 +44,6 @@ module Free_variables = struct | E_constant (c) -> unions @@ List.map self c.arguments | E_application (f, x) -> unions @@ [ self f ; self x ] | E_variable n -> var_name b n - | E_make_empty_map _ -> empty - | E_make_empty_big_map _ -> empty | E_make_none _ -> empty | E_iterator (_, ((v, _), body), expr) -> unions [ expression (union (singleton v) b) body ; diff --git a/src/stages/5-mini_c/types.ml b/src/stages/5-mini_c/types.ml index f16054a25..8461df787 100644 --- a/src/stages/5-mini_c/types.ml +++ b/src/stages/5-mini_c/types.ml @@ -59,8 +59,6 @@ and expression' = | E_constant of constant | E_application of (expression * expression) | E_variable of var_name - | E_make_empty_map of (type_value * type_value) - | E_make_empty_big_map of (type_value * type_value) | E_make_none of type_value | E_iterator of constant' * ((var_name * type_value) * expression) * expression | E_fold of (((var_name * type_value) * expression) * expression * expression) diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index f8d594a89..b5da63ec4 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -127,6 +127,7 @@ let constant ppf : constant' -> unit = function | C_MAP_FIND_OPT -> fprintf ppf "MAP_FIND_OP" (* Big Maps *) | C_BIG_MAP -> fprintf ppf "BIG_MAP" + | C_BIG_MAP_ADD -> fprintf ppf "BIG_MAP_ADD" | C_BIG_MAP_EMPTY -> fprintf ppf "BIG_MAP_EMPTY" | C_BIG_MAP_LITERAL -> fprintf ppf "BIG_MAP_LITERAL" (* Crypto *) diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index 6ffdb5485..5d62b62c7 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -269,6 +269,7 @@ and constant' = | C_MAP_FIND_OPT (* Big Maps *) | C_BIG_MAP + | C_BIG_MAP_ADD | C_BIG_MAP_EMPTY | C_BIG_MAP_LITERAL (* Crypto *) diff --git a/src/stages/typesystem/misc.ml b/src/stages/typesystem/misc.ml index ce7937c7e..545534b77 100644 --- a/src/stages/typesystem/misc.ml +++ b/src/stages/typesystem/misc.ml @@ -190,20 +190,6 @@ module Substitution = struct let%bind record = s_expression ~substs record in let%bind update = s_expression ~substs update in ok @@ T.E_record_update {record;path;update} - | T.E_map val_val_list -> - let%bind val_val_list = bind_map_list (fun (val1 , val2) -> - let%bind val1 = s_expression ~substs val1 in - let%bind val2 = s_expression ~substs val2 in - ok @@ (val1 , val2) - ) val_val_list in - ok @@ T.E_map val_val_list - | T.E_big_map val_val_list -> - let%bind val_val_list = bind_map_list (fun (val1 , val2) -> - let%bind val1 = s_expression ~substs val1 in - let%bind val2 = s_expression ~substs val2 in - ok @@ (val1 , val2) - ) val_val_list in - ok @@ T.E_big_map val_val_list | T.E_matching {matchee;cases} -> let%bind matchee = s_expression ~substs matchee in let%bind cases = s_matching_expr ~substs cases in From 6a9547e9109adedf1c5607075b0405a5e35f31e6 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Wed, 25 Mar 2020 19:10:04 +0100 Subject: [PATCH 4/5] add type map_or_big_map to solve issue of typing big_map_empty from map_add --- .../expect_tests/ligo_interpreter_tests.ml | 6 +++--- src/passes/10-interpreter/interpreter.ml | 1 + src/passes/10-transpiler/transpiler.ml | 2 ++ src/passes/10-transpiler/untranspiler.ml | 16 ++++++++------- .../imperative_to_sugar.ml | 6 ++++++ src/passes/6-sugar_to_core/sugar_to_core.ml | 14 +++++++++---- src/passes/8-typer-new/solver.ml | 2 ++ src/passes/8-typer-new/typer.ml | 8 ++++++++ src/passes/8-typer-old/typer.ml | 20 +++++-------------- src/passes/operators/operators.ml | 12 ++++++++++- src/stages/4-ast_typed/combinators.ml | 3 +++ src/stages/4-ast_typed/combinators.mli | 1 + src/stages/4-ast_typed/misc.ml | 9 +++++---- src/stages/5-mini_c/PP.ml | 1 - src/stages/common/PP.ml | 2 +- src/stages/common/types.ml | 6 +++++- 16 files changed, 72 insertions(+), 37 deletions(-) diff --git a/src/bin/expect_tests/ligo_interpreter_tests.ml b/src/bin/expect_tests/ligo_interpreter_tests.ml index 9a6069338..5910c0669 100644 --- a/src/bin/expect_tests/ligo_interpreter_tests.ml +++ b/src/bin/expect_tests/ligo_interpreter_tests.ml @@ -43,12 +43,12 @@ let%expect_test _ = val map_finds = Some(2 : int) val map_finds_fail = "failed map find" : failure val map_empty = { ; 0 = ([]) ; 1 = ([]) } - val m = [ ; "one" : string -> 1 : int ; "two" : string -> 2 : int ; "three" : string -> 3 : int] + val m = [ ; "one" : string -> 1 : int ; "three" : string -> 3 : int ; "two" : string -> 2 : int] val map_fold = 4 : int val map_iter = unit - val map_map = [ ; "one" : string -> 4 : int ; "two" : string -> 5 : int ; "three" : string -> 8 : int] + val map_map = [ ; "one" : string -> 4 : int ; "three" : string -> 8 : int ; "two" : string -> 5 : int] val map_mem = { ; 0 = (true) ; 1 = (false) } - val map_remove = { ; 0 = ([ ; "two" : string -> 2 : int ; "three" : string -> 3 : int]) ; 1 = ([ ; "one" : string -> 1 : int ; "two" : string -> 2 : int ; "three" : string -> 3 : int]) } + val map_remove = { ; 0 = ([ ; "three" : string -> 3 : int ; "two" : string -> 2 : int]) ; 1 = ([ ; "one" : string -> 1 : int ; "three" : string -> 3 : int ; "two" : string -> 2 : int]) } val map_update = { ; 0 = ([ ; "one" : string -> 1 : int]) ; 1 = ([]) ; 2 = ([]) ; 3 = ([ ; "one" : string -> 1 : int]) } val s = { ; 1 : int ; 2 : int ; 3 : int} val set_add = { ; 0 = ({ ; 1 : int ; 2 : int ; 3 : int}) ; 1 = ({ ; 1 : int ; 2 : int ; 3 : int ; 4 : int}) ; 2 = ({ ; 1 : int}) } diff --git a/src/passes/10-interpreter/interpreter.ml b/src/passes/10-interpreter/interpreter.ml index 2c06cab83..d319d49a7 100644 --- a/src/passes/10-interpreter/interpreter.ml +++ b/src/passes/10-interpreter/interpreter.ml @@ -171,6 +171,7 @@ let rec apply_operator : Ast_typed.constant' -> value list -> value result = eval body env' ) init elts + | ( C_MAP_EMPTY , []) -> ok @@ V_Map ([]) | ( C_MAP_FOLD , [ V_Func_val (arg_name, body, env) ; V_Map kvs ; init ] ) -> bind_fold_list (fun prev kv -> diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index 8554b2d8e..553ee4425 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -141,6 +141,8 @@ let rec transpile_type (t:AST.type_expression) : type_value result = | T_operator (TC_big_map (key,value)) -> let%bind kv' = bind_map_pair transpile_type (key, value) in ok (T_big_map kv') + | T_operator (TC_map_or_big_map (_,_)) -> + fail @@ corner_case ~loc:"transpiler" "TC_map_or_big_map should be resolve before transpilation" | T_operator (TC_list t) -> let%bind t' = transpile_type t in ok (T_list t') diff --git a/src/passes/10-transpiler/untranspiler.ml b/src/passes/10-transpiler/untranspiler.ml index 9a7149eed..f87cab0cd 100644 --- a/src/passes/10-transpiler/untranspiler.ml +++ b/src/passes/10-transpiler/untranspiler.ml @@ -160,30 +160,32 @@ let rec untranspile (v : value) (t : AST.type_expression) : AST.expression resul let%bind v' = untranspile v v_ty in ok (k', v') in bind_map_list aux map in + let map' = List.sort_uniq compare map' in let aux = fun prev (k, v) -> let (k', v') = (k , v ) in return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k' ; v' ; prev]} in let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in - bind_fold_list aux init map' + bind_fold_right_list aux init map' ) | TC_big_map (k_ty, v_ty) -> ( - let%bind map = + let%bind big_map = trace_strong (wrong_mini_c_value "big_map" v) @@ get_big_map v in - let%bind map' = + let%bind big_map' = let aux = fun (k, v) -> let%bind k' = untranspile k k_ty in let%bind v' = untranspile v v_ty in ok (k', v') in - bind_map_list aux map in - let map' = List.sort_uniq compare map' in + bind_map_list aux big_map in + let big_map' = List.sort_uniq compare big_map' in let aux = fun prev (k, v) -> return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k ; v ; prev]} in - let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in - bind_fold_list aux init map' + let%bind init = return @@ E_constant {cons_name=C_BIG_MAP_EMPTY;arguments=[]} in + bind_fold_right_list aux init big_map' ) + | TC_map_or_big_map (_, _) -> fail @@ corner_case ~loc:"untranspiler" "should not be present in mini-c" | TC_list ty -> ( let%bind lst = trace_strong (wrong_mini_c_value "list" v) @@ diff --git a/src/passes/4-imperative_to_sugar/imperative_to_sugar.ml b/src/passes/4-imperative_to_sugar/imperative_to_sugar.ml index 2ac37fc71..7b214a2aa 100644 --- a/src/passes/4-imperative_to_sugar/imperative_to_sugar.ml +++ b/src/passes/4-imperative_to_sugar/imperative_to_sugar.ml @@ -154,6 +154,9 @@ and compile_type_operator : I.type_operator -> O.type_operator result = | TC_big_map (k,v) -> let%bind (k,v) = bind_map_pair compile_type_expression (k,v) in ok @@ O.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind (k,v) = bind_map_pair compile_type_expression (k,v) in + ok @@ O.TC_map_or_big_map (k,v) | TC_arrow (i,o) -> let%bind (i,o) = bind_map_pair compile_type_expression (i,o) in ok @@ O.TC_arrow (i,o) @@ -569,6 +572,9 @@ and uncompile_type_operator : O.type_operator -> I.type_operator result = | TC_big_map (k,v) -> let%bind (k,v) = bind_map_pair uncompile_type_expression (k,v) in ok @@ I.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind (k,v) = bind_map_pair uncompile_type_expression (k,v) in + ok @@ I.TC_map_or_big_map (k,v) | TC_arrow (i,o) -> let%bind (i,o) = bind_map_pair uncompile_type_expression (i,o) in ok @@ I.TC_arrow (i,o) diff --git a/src/passes/6-sugar_to_core/sugar_to_core.ml b/src/passes/6-sugar_to_core/sugar_to_core.ml index e79ab336f..986f1cc16 100644 --- a/src/passes/6-sugar_to_core/sugar_to_core.ml +++ b/src/passes/6-sugar_to_core/sugar_to_core.ml @@ -55,6 +55,9 @@ and idle_type_operator : I.type_operator -> O.type_operator result = | TC_big_map (k,v) -> let%bind (k,v) = bind_map_pair idle_type_expression (k,v) in ok @@ O.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind (k,v) = bind_map_pair idle_type_expression (k,v) in + ok @@ O.TC_map_or_big_map (k,v) | TC_arrow (i,o) -> let%bind (i,o) = bind_map_pair idle_type_expression (i,o) in ok @@ O.TC_arrow (i,o) @@ -115,16 +118,16 @@ let rec compile_expression : I.expression -> O.expression result = return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k' ; v' ; prev]} in let%bind init = return @@ E_constant {cons_name=C_MAP_EMPTY;arguments=[]} in - bind_fold_list aux init map + bind_fold_right_list aux init map ) | I.E_big_map big_map -> ( - let map = List.sort_uniq compare big_map in + let big_map = List.sort_uniq compare big_map in let aux = fun prev (k, v) -> let%bind (k', v') = bind_map_pair (compile_expression) (k, v) in - return @@ E_constant {cons_name=C_BIG_MAP_ADD;arguments=[k' ; v' ; prev]} + return @@ E_constant {cons_name=C_MAP_ADD;arguments=[k' ; v' ; prev]} in let%bind init = return @@ E_constant {cons_name=C_BIG_MAP_EMPTY;arguments=[]} in - bind_fold_list aux init map + bind_fold_right_list aux init big_map ) | I.E_list lst -> let%bind lst' = bind_map_list (compile_expression) lst in @@ -258,6 +261,9 @@ and uncompile_type_operator : O.type_operator -> I.type_operator result = | TC_big_map (k,v) -> let%bind (k,v) = bind_map_pair uncompile_type_expression (k,v) in ok @@ I.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind (k,v) = bind_map_pair uncompile_type_expression (k,v) in + ok @@ I.TC_map_or_big_map (k,v) | TC_arrow (i,o) -> let%bind (i,o) = bind_map_pair uncompile_type_expression (i,o) in ok @@ I.TC_arrow (i,o) diff --git a/src/passes/8-typer-new/solver.ml b/src/passes/8-typer-new/solver.ml index 328cfe015..25409822f 100644 --- a/src/passes/8-typer-new/solver.ml +++ b/src/passes/8-typer-new/solver.ml @@ -70,6 +70,7 @@ module Wrap = struct | TC_set s -> (C_set, [s]) | TC_map ( k , v ) -> (C_map, [k;v]) | TC_big_map ( k , v) -> (C_big_map, [k;v]) + | TC_map_or_big_map ( k , v) -> (C_map, [k;v]) | TC_arrow ( arg , ret ) -> (C_arrow, [ arg ; ret ]) | TC_list l -> (C_list, [l]) | TC_contract c -> (C_contract, [c]) @@ -103,6 +104,7 @@ module Wrap = struct | TC_set s -> (C_set , [s]) | TC_map ( k , v ) -> (C_map , [k;v]) | TC_big_map ( k , v ) -> (C_big_map, [k;v]) + | TC_map_or_big_map ( k , v) -> (C_map, [k;v]) | TC_contract c -> (C_contract, [c]) | TC_arrow ( arg , ret ) -> (C_arrow, [ arg ; ret ]) ) diff --git a/src/passes/8-typer-new/typer.ml b/src/passes/8-typer-new/typer.ml index 6166666bc..c1d4065a6 100644 --- a/src/passes/8-typer-new/typer.ml +++ b/src/passes/8-typer-new/typer.ml @@ -345,6 +345,10 @@ and evaluate_type (e:environment) (t:I.type_expression) : O.type_expression resu let%bind k = evaluate_type e k in let%bind v = evaluate_type e v in ok @@ O.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind k = evaluate_type e k in + let%bind v = evaluate_type e v in + ok @@ O.TC_map_or_big_map (k,v) | TC_contract c -> let%bind c = evaluate_type e c in ok @@ O.TC_contract c @@ -837,6 +841,10 @@ let rec untype_type_expression (t:O.type_expression) : (I.type_expression) resul let%bind k = untype_type_expression k in let%bind v = untype_type_expression v in ok @@ I.TC_big_map (k,v) + | O.TC_map_or_big_map (k,v) -> + let%bind k = untype_type_expression k in + let%bind v = untype_type_expression v in + ok @@ I.TC_map_or_big_map (k,v) | O.TC_arrow ( arg , ret ) -> let%bind arg' = untype_type_expression arg in let%bind ret' = untype_type_expression ret in diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index ce64fa5b9..4dc472468 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -381,6 +381,10 @@ and evaluate_type (e:environment) (t:I.type_expression) : O.type_expression resu let%bind k = evaluate_type e k in let%bind v = evaluate_type e v in ok @@ O.TC_big_map (k,v) + | TC_map_or_big_map (k,v) -> + let%bind k = evaluate_type e k in + let%bind v = evaluate_type e v in + ok @@ O.TC_map_or_big_map (k,v) | TC_arrow ( arg , ret ) -> let%bind arg' = evaluate_type e arg in let%bind ret' = evaluate_type e ret in @@ -602,21 +606,7 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let tv_val = get_type_expression val' in let tv = match tv_opt with Some (tv) -> tv - | None -> t_map tv_key tv_val () - in - let%bind map' = type_expression' e ~tv_opt:tv map in - let tv_map = get_type_expression map' in - let tv_lst = [tv_key;tv_val;tv_map] in - let%bind (name', tv) = type_constant cst tv_lst tv_opt in - return (E_constant {cons_name=name';arguments=[key';val';map']}) tv - | E_constant {cons_name=C_BIG_MAP_ADD as cst; arguments=[key;value;map]} -> - let%bind key' = type_expression' e key in - let%bind val' = type_expression' e value in - let tv_key = get_type_expression key' in - let tv_val = get_type_expression val' in - let tv = match tv_opt with - Some (tv) -> tv - | None -> t_big_map tv_key tv_val () + | None -> t_map_or_big_map tv_key tv_val () in let%bind map' = type_expression' e ~tv_opt:tv map in let tv_map = get_type_expression map' in diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 9e6a093af..4d9e76d9d 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -624,7 +624,16 @@ module Typer = struct let map_empty = typer_0 "MAP_EMPTY" @@ fun tv_opt -> match tv_opt with | None -> simple_fail "untyped MAP_EMPTY" - | Some t -> ok t + | Some t -> + let%bind (src, dst) = get_t_map t in + ok @@ t_map src dst () + + let big_map_empty = typer_0 "BIG_MAP_EMPTY" @@ fun tv_opt -> + match tv_opt with + | None -> simple_fail "untyped BIG_MAP_EMPTY" + | Some t -> + let%bind (src, dst) = get_t_big_map t in + ok @@ t_big_map src dst () let map_add : typer = typer_3 "MAP_ADD" @@ fun k v m -> let%bind (src, dst) = bind_map_or (get_t_map , get_t_big_map) m in @@ -1171,6 +1180,7 @@ module Typer = struct | C_LIST_FOLD -> ok @@ list_fold ; (* MAP *) | C_MAP_EMPTY -> ok @@ map_empty ; + | C_BIG_MAP_EMPTY -> ok @@ big_map_empty ; | C_MAP_ADD -> ok @@ map_add ; | C_MAP_REMOVE -> ok @@ map_remove ; | C_MAP_UPDATE -> ok @@ map_update ; diff --git a/src/stages/4-ast_typed/combinators.ml b/src/stages/4-ast_typed/combinators.ml index 9961dbc0a..8a399bb35 100644 --- a/src/stages/4-ast_typed/combinators.ml +++ b/src/stages/4-ast_typed/combinators.ml @@ -64,6 +64,7 @@ let t_pair a b ?s () : type_expression = ez_t_record [(Label "0",a) ; (Label " let t_map key value ?s () = make_t (T_operator (TC_map (key , value))) s let t_big_map key value ?s () = make_t (T_operator (TC_big_map (key , value))) s +let t_map_or_big_map key value ?s () = make_t (T_operator (TC_map_or_big_map (key,value))) s let t_sum m ?s () : type_expression = make_t (T_sum m) s let make_t_ez_sum (lst:(constructor' * type_expression) list) : type_expression = @@ -190,11 +191,13 @@ let get_t_record (t:type_expression) : type_expression label_map result = match let get_t_map (t:type_expression) : (type_expression * type_expression) result = match t.type_content with | T_operator (TC_map (k,v)) -> ok (k, v) + | T_operator (TC_map_or_big_map (k,v)) -> ok (k, v) | _ -> fail @@ Errors.not_a_x_type "map" t () let get_t_big_map (t:type_expression) : (type_expression * type_expression) result = match t.type_content with | T_operator (TC_big_map (k,v)) -> ok (k, v) + | T_operator (TC_map_or_big_map (k,v)) -> ok (k, v) | _ -> fail @@ Errors.not_a_x_type "big_map" t () let get_t_map_key : type_expression -> type_expression result = fun t -> diff --git a/src/stages/4-ast_typed/combinators.mli b/src/stages/4-ast_typed/combinators.mli index dd88ffd00..fadef09e3 100644 --- a/src/stages/4-ast_typed/combinators.mli +++ b/src/stages/4-ast_typed/combinators.mli @@ -31,6 +31,7 @@ val ez_t_record : ( label * type_expression ) list -> ?s:S.type_expression -> un val t_map : type_expression -> type_expression -> ?s:S.type_expression -> unit -> type_expression val t_big_map : type_expression -> type_expression -> ?s:S.type_expression -> unit -> type_expression +val t_map_or_big_map : type_expression -> type_expression -> ?s:S.type_expression -> unit -> type_expression val t_sum : type_expression constructor_map -> ?s:S.type_expression -> unit -> type_expression val make_t_ez_sum : ( constructor' * type_expression ) list -> type_expression val t_function : type_expression -> type_expression -> ?s:S.type_expression -> unit -> type_expression diff --git a/src/stages/4-ast_typed/misc.ml b/src/stages/4-ast_typed/misc.ml index f101f3857..8f6158109 100644 --- a/src/stages/4-ast_typed/misc.ml +++ b/src/stages/4-ast_typed/misc.ml @@ -338,10 +338,11 @@ let rec assert_type_expression_eq (a, b: (type_expression * type_expression)) : | TC_list la, TC_list lb | TC_contract la, TC_contract lb | TC_set la, TC_set lb -> ok @@ ([la], [lb]) - | TC_map (ka,va), TC_map (kb,vb) - | TC_big_map (ka,va), TC_big_map (kb,vb) -> ok @@ ([ka;va] ,[kb;vb]) - | (TC_option _ | TC_list _ | TC_contract _ | TC_set _ | TC_map _ | TC_big_map _ | TC_arrow _), - (TC_option _ | TC_list _ | TC_contract _ | TC_set _ | TC_map _ | TC_big_map _ | TC_arrow _ ) -> fail @@ different_operators opa opb + | (TC_map (ka,va) | TC_map_or_big_map (ka,va)), (TC_map (kb,vb) | TC_map_or_big_map (kb,vb)) + | (TC_big_map (ka,va) | TC_map_or_big_map (ka,va)), (TC_big_map (kb,vb) | TC_map_or_big_map (kb,vb)) + -> ok @@ ([ka;va] ,[kb;vb]) + | (TC_option _ | TC_list _ | TC_contract _ | TC_set _ | TC_map _ | TC_big_map _ | TC_map_or_big_map _ | TC_arrow _), + (TC_option _ | TC_list _ | TC_contract _ | TC_set _ | TC_map _ | TC_big_map _ | TC_map_or_big_map _ | TC_arrow _ ) -> fail @@ different_operators opa opb in if List.length lsta <> List.length lstb then fail @@ different_operator_number_of_arguments opa opb (List.length lsta) (List.length lstb) diff --git a/src/stages/5-mini_c/PP.ml b/src/stages/5-mini_c/PP.ml index 1231f5ed6..808b65873 100644 --- a/src/stages/5-mini_c/PP.ml +++ b/src/stages/5-mini_c/PP.ml @@ -217,7 +217,6 @@ and constant ppf : constant' -> unit = function | C_MAP_FIND_OPT -> fprintf ppf "MAP_FIND_OP" (* Big Maps *) | C_BIG_MAP -> fprintf ppf "BIG_MAP" - | C_BIG_MAP_ADD -> fprintf ppf "BIG_MAP_ADD" | C_BIG_MAP_EMPTY -> fprintf ppf "BIG_MAP_EMPTY" | C_BIG_MAP_LITERAL -> fprintf ppf "BIG_MAP_LITERAL" (* Crypto *) diff --git a/src/stages/common/PP.ml b/src/stages/common/PP.ml index b5da63ec4..559446668 100644 --- a/src/stages/common/PP.ml +++ b/src/stages/common/PP.ml @@ -127,7 +127,6 @@ let constant ppf : constant' -> unit = function | C_MAP_FIND_OPT -> fprintf ppf "MAP_FIND_OP" (* Big Maps *) | C_BIG_MAP -> fprintf ppf "BIG_MAP" - | C_BIG_MAP_ADD -> fprintf ppf "BIG_MAP_ADD" | C_BIG_MAP_EMPTY -> fprintf ppf "BIG_MAP_EMPTY" | C_BIG_MAP_LITERAL -> fprintf ppf "BIG_MAP_LITERAL" (* Crypto *) @@ -266,6 +265,7 @@ module Ast_PP_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set te -> Format.asprintf "set(%a)" f te | TC_map (k, v) -> Format.asprintf "Map (%a,%a)" f k f v | TC_big_map (k, v) -> Format.asprintf "Big Map (%a,%a)" f k f v + | TC_map_or_big_map (k, v) -> Format.asprintf "Map Or Big Map (%a,%a)" f k f v | TC_arrow (k, v) -> Format.asprintf "arrow (%a,%a)" f k f v | TC_contract te -> Format.asprintf "Contract (%a)" f te in diff --git a/src/stages/common/types.ml b/src/stages/common/types.ml index 5d62b62c7..8e3411527 100644 --- a/src/stages/common/types.ml +++ b/src/stages/common/types.ml @@ -53,6 +53,7 @@ module Ast_generic_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set of type_expression | TC_map of type_expression * type_expression | TC_big_map of type_expression * type_expression + | TC_map_or_big_map of type_expression * type_expression | TC_arrow of type_expression * type_expression @@ -66,6 +67,7 @@ module Ast_generic_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set x -> TC_set (f x) | TC_map (x , y) -> TC_map (f x , f y) | TC_big_map (x , y)-> TC_big_map (f x , f y) + | TC_map_or_big_map (x , y)-> TC_map_or_big_map (f x , f y) | TC_arrow (x, y) -> TC_arrow (f x, f y) let bind_map_type_operator f = function @@ -75,6 +77,7 @@ module Ast_generic_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set x -> let%bind x = f x in ok @@ TC_set x | TC_map (x , y) -> let%bind x = f x in let%bind y = f y in ok @@ TC_map (x , y) | TC_big_map (x , y)-> let%bind x = f x in let%bind y = f y in ok @@ TC_big_map (x , y) + | TC_map_or_big_map (x , y)-> let%bind x = f x in let%bind y = f y in ok @@ TC_map_or_big_map (x , y) | TC_arrow (x , y)-> let%bind x = f x in let%bind y = f y in ok @@ TC_arrow (x , y) let type_operator_name = function @@ -84,6 +87,7 @@ module Ast_generic_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set _ -> "TC_set" | TC_map _ -> "TC_map" | TC_big_map _ -> "TC_big_map" + | TC_map_or_big_map _ -> "TC_map_or_big_map" | TC_arrow _ -> "TC_arrow" let type_expression'_of_string = function @@ -122,6 +126,7 @@ module Ast_generic_type (PARAMETER : AST_PARAMETER_TYPE) = struct | TC_set x -> "TC_set" , [x] | TC_map (x , y) -> "TC_map" , [x ; y] | TC_big_map (x , y) -> "TC_big_map" , [x ; y] + | TC_map_or_big_map (x , y) -> "TC_map_or_big_map" , [x ; y] | TC_arrow (x , y) -> "TC_arrow" , [x ; y] let string_of_type_constant = function @@ -269,7 +274,6 @@ and constant' = | C_MAP_FIND_OPT (* Big Maps *) | C_BIG_MAP - | C_BIG_MAP_ADD | C_BIG_MAP_EMPTY | C_BIG_MAP_LITERAL (* Crypto *) From aac7dd3462de71b6e24db3ea021bb42bbe251121 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Fri, 27 Mar 2020 15:23:55 +0100 Subject: [PATCH 5/5] review 1 --- scripts/test_cli.sh | 2 +- src/bin/expect_tests/contract_tests.ml | 21 ++++++------------- src/passes/10-transpiler/transpiler.ml | 2 +- src/passes/10-transpiler/untranspiler.ml | 2 +- src/passes/8-typer-old/typer.ml | 6 +++--- .../9-self_ast_typed/no_nested_big_map.ml | 4 ++++ src/stages/3-ast_core/combinators.ml | 4 ++-- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/scripts/test_cli.sh b/scripts/test_cli.sh index 5bda10f9f..c41a4db8e 100755 --- a/scripts/test_cli.sh +++ b/scripts/test_cli.sh @@ -7,7 +7,7 @@ dry_run_output=$(./scripts/ligo_ci.sh dry-run src/test/contracts/website2.ligo m expected_compiled_parameter="(Right 1)"; expected_compiled_storage=1; -expected_dry_run_output="( list[] , 2 )"; +expected_dry_run_output="( LIST_EMPTY() , 2 )"; if [ "$compiled_storage" != "$expected_compiled_storage" ]; then echo "Expected $expected_compiled_storage as compile-storage output, got $compiled_storage instead"; diff --git a/src/bin/expect_tests/contract_tests.ml b/src/bin/expect_tests/contract_tests.ml index 913a89352..3419ad93b 100644 --- a/src/bin/expect_tests/contract_tests.ml +++ b/src/bin/expect_tests/contract_tests.ml @@ -13,7 +13,7 @@ let%expect_test _ = [%expect {| 1294 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ; - [%expect {| 3268 bytes |}] ; + [%expect {| 2974 bytes |}] ; run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ; [%expect {| 589 bytes |}] ; @@ -627,12 +627,7 @@ let%expect_test _ = IF { PUSH string "Maximum number of proposal reached" ; FAILWITH } { PUSH unit Unit } ; NIL operation ; - DIP 10 { DUP } ; - DIG 10 ; - DIP { DIP 4 { DUP } ; DIG 4 } ; - PAIR ; - DIP { DIP 9 { DUP } ; DIG 9 ; DIP { DUP } ; PAIR } ; - PAIR ; + DUP ; DIP { DIP 3 { DUP } ; DIG 3 } ; PAIR ; DIP 5 { DUP } ; @@ -691,12 +686,8 @@ let%expect_test _ = DIP { DUP } ; SWAP ; DIP { DUP } ; - PAIR ; - DIP { DIP 2 { DUP } ; DIG 2 } ; - PAIR ; - DIP 2 { DUP } ; - DIG 2 ; - DIP { DIP 13 { DUP } ; DIG 13 } ; + SWAP ; + DIP { DIP 12 { DUP } ; DIG 12 } ; MEM ; IF { DIP 2 { DUP } ; DIG 2 ; @@ -1126,7 +1117,7 @@ let%expect_test _ = let%expect_test _ = run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_toplevel.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return let rhs#654 = #P in let p = rhs#654.0 in let s = rhs#654.1 in ( LIST_EMPTY() : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} +ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, character 8. No free variable allowed in this lambda: variable 'store' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * string ))) : None return let rhs#702 = #P in let p = rhs#702.0 in let s = rhs#702.1 in ( LIST_EMPTY() : (TO_list(operation)) , store ) , NONE() : (TO_option(key_hash)) , 300000000mutez , \"un\")","location":"in file \"create_contract_toplevel.mligo\", line 4, character 35 to line 8, character 8"} If you're not sure how to fix this error, you can @@ -1139,7 +1130,7 @@ ligo: in file "create_contract_toplevel.mligo", line 4, character 35 to line 8, run_ligo_bad [ "compile-contract" ; bad_contract "create_contract_var.mligo" ; "main" ] ; [%expect {| -ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return let rhs#657 = #P in let p = rhs#657.0 in let s = rhs#657.1 in ( LIST_EMPTY() : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} +ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, character 5. No free variable allowed in this lambda: variable 'a' {"expression":"CREATE_CONTRACT(lambda (#P:Some(( nat * int ))) : None return let rhs#705 = #P in let p = rhs#705.0 in let s = rhs#705.1 in ( LIST_EMPTY() : (TO_list(operation)) , a ) , NONE() : (TO_option(key_hash)) , 300000000mutez , 1)","location":"in file \"create_contract_var.mligo\", line 6, character 35 to line 10, character 5"} If you're not sure how to fix this error, you can diff --git a/src/passes/10-transpiler/transpiler.ml b/src/passes/10-transpiler/transpiler.ml index 553ee4425..04ceeaf8d 100644 --- a/src/passes/10-transpiler/transpiler.ml +++ b/src/passes/10-transpiler/transpiler.ml @@ -142,7 +142,7 @@ let rec transpile_type (t:AST.type_expression) : type_value result = let%bind kv' = bind_map_pair transpile_type (key, value) in ok (T_big_map kv') | T_operator (TC_map_or_big_map (_,_)) -> - fail @@ corner_case ~loc:"transpiler" "TC_map_or_big_map should be resolve before transpilation" + fail @@ corner_case ~loc:"transpiler" "TC_map_or_big_map should have been resolved before transpilation" | T_operator (TC_list t) -> let%bind t' = transpile_type t in ok (T_list t') diff --git a/src/passes/10-transpiler/untranspiler.ml b/src/passes/10-transpiler/untranspiler.ml index f87cab0cd..b8762ecf1 100644 --- a/src/passes/10-transpiler/untranspiler.ml +++ b/src/passes/10-transpiler/untranspiler.ml @@ -185,7 +185,7 @@ let rec untranspile (v : value) (t : AST.type_expression) : AST.expression resul let%bind init = return @@ E_constant {cons_name=C_BIG_MAP_EMPTY;arguments=[]} in bind_fold_right_list aux init big_map' ) - | TC_map_or_big_map (_, _) -> fail @@ corner_case ~loc:"untranspiler" "should not be present in mini-c" + | TC_map_or_big_map (_, _) -> fail @@ corner_case ~loc:"untranspiler" "TC_map_or_big_map t should not be present in mini-c" | TC_list ty -> ( let%bind lst = trace_strong (wrong_mini_c_value "list" v) @@ diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index 4dc472468..73a91118a 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -588,11 +588,11 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let%bind key' = type_expression' e key in let tv_key = get_type_expression key' in let tv = match tv_opt with - Some (tv) -> tv + Some tv -> tv | None -> match cst with C_SET_ADD -> t_set tv_key () | C_CONS -> t_list tv_key () - | _ -> failwith "impossible" + | _ -> failwith "Only C_SET_ADD and C_CONS are possible because those were the two cases matched above" in let%bind set' = type_expression' e ~tv_opt:tv set in let tv_set = get_type_expression set' in @@ -605,7 +605,7 @@ and type_expression' : environment -> ?tv_opt:O.type_expression -> I.expression let tv_key = get_type_expression key' in let tv_val = get_type_expression val' in let tv = match tv_opt with - Some (tv) -> tv + Some tv -> tv | None -> t_map_or_big_map tv_key tv_val () in let%bind map' = type_expression' e ~tv_opt:tv map in diff --git a/src/passes/9-self_ast_typed/no_nested_big_map.ml b/src/passes/9-self_ast_typed/no_nested_big_map.ml index e1a130ce9..a0b2f869f 100644 --- a/src/passes/9-self_ast_typed/no_nested_big_map.ml +++ b/src/passes/9-self_ast_typed/no_nested_big_map.ml @@ -21,6 +21,10 @@ let rec check_no_nested_bigmap is_in_bigmap e = let%bind _ = check_no_nested_bigmap false key in let%bind _ = check_no_nested_bigmap true value in ok () + | T_operator (TC_map_or_big_map (key, value)) -> + let%bind _ = check_no_nested_bigmap false key in + let%bind _ = check_no_nested_bigmap true value in + ok () | T_operator (TC_contract t) | T_operator (TC_option t) | T_operator (TC_list t) diff --git a/src/stages/3-ast_core/combinators.ml b/src/stages/3-ast_core/combinators.ml index 2c5dbf56d..787b61438 100644 --- a/src/stages/3-ast_core/combinators.ml +++ b/src/stages/3-ast_core/combinators.ml @@ -251,10 +251,10 @@ let extract_record : expression -> (label * expression) list result = fun e -> let extract_map : expression -> (expression * expression) list result = fun e -> let rec aux e = match e.expression_content with - E_constant {cons_name=C_UPDATE; arguments=[k;v;map]} -> + E_constant {cons_name=C_UPDATE|C_MAP_ADD; arguments=[k;v;map]} -> let%bind map = aux map in ok @@ (k,v)::map - | E_constant {cons_name=C_MAP_EMPTY; arguments=[]} -> ok @@ [] + | E_constant {cons_name=C_MAP_EMPTY|C_BIG_MAP_EMPTY; arguments=[]} -> ok @@ [] | _ -> fail @@ bad_kind "map" e.location in aux e