diff --git a/src/lib_micheline/micheline.ml b/src/lib_micheline/micheline.ml index 0bdcce27fd09a15a326e5a5c8a68cc65b458a8f6..4fb227427d4e44a2c595bff9eced17b8dcb027e8 100644 --- a/src/lib_micheline/micheline.ml +++ b/src/lib_micheline/micheline.ml @@ -36,6 +36,8 @@ type ('l, 'p) node = type canonical_location = int +let dummy_location = -1 + type 'p canonical = Canonical of (canonical_location, 'p) node let location = function diff --git a/src/lib_micheline/micheline.mli b/src/lib_micheline/micheline.mli index c0afe3efbeb81b8efb359275f13d1db56750ef62..1e986513ae8b892dd7d05722c654cc06fb00476a 100644 --- a/src/lib_micheline/micheline.mli +++ b/src/lib_micheline/micheline.mli @@ -53,6 +53,9 @@ type 'p canonical (** Canonical integer locations that appear inside {!canonical} expressions. *) type canonical_location = int +(** A location that won't exist in any well-formed canonical value *) +val dummy_location : canonical_location + (** Compute the canonical form of an expression. Drops the concrete locations completely. *) val strip_locations : (_, 'p) node -> 'p canonical diff --git a/src/lib_protocol_environment/environment_V4.ml b/src/lib_protocol_environment/environment_V4.ml index be9ede42e8883d5acd98c3683e8f0842315ec4fe..9bee90461d724071a6e96a9fc564f0e12451731b 100644 --- a/src/lib_protocol_environment/environment_V4.ml +++ b/src/lib_protocol_environment/environment_V4.ml @@ -76,6 +76,7 @@ module type V4 = sig and type Pvss_secp256k1.Clear_share.t = Pvss_secp256k1.Clear_share.t and type Pvss_secp256k1.Public_key.t = Pvss_secp256k1.Public_key.t and type Pvss_secp256k1.Secret_key.t = Pvss_secp256k1.Secret_key.t + and type Micheline.canonical_location = Micheline.canonical_location and type 'a Micheline.canonical = 'a Micheline.canonical and type Z.t = Z.t and type ('a, 'b) Micheline.node = ('a, 'b) Micheline.node diff --git a/src/lib_protocol_environment/environment_V4.mli b/src/lib_protocol_environment/environment_V4.mli index 1b0ae6ee128ff135078dbcd4b0f3424a10d0a0d6..2764f6a9b6d11c488c3d6afaebda64b3c9f5f5f0 100644 --- a/src/lib_protocol_environment/environment_V4.mli +++ b/src/lib_protocol_environment/environment_V4.mli @@ -71,6 +71,7 @@ module type V4 = sig and type Pvss_secp256k1.Clear_share.t = Pvss_secp256k1.Clear_share.t and type Pvss_secp256k1.Public_key.t = Pvss_secp256k1.Public_key.t and type Pvss_secp256k1.Secret_key.t = Pvss_secp256k1.Secret_key.t + and type Micheline.canonical_location = Micheline.canonical_location and type 'a Micheline.canonical = 'a Micheline.canonical and type Z.t = Z.t and type ('a, 'b) Micheline.node = ('a, 'b) Micheline.node diff --git a/src/lib_protocol_environment/sigs/v4/micheline.mli b/src/lib_protocol_environment/sigs/v4/micheline.mli index 6eece374f7081ce068f25a496810f18b67b6c8a2..29f9ef5c47a8f18e00ec339b62c604847b26120d 100644 --- a/src/lib_protocol_environment/sigs/v4/micheline.mli +++ b/src/lib_protocol_environment/sigs/v4/micheline.mli @@ -34,7 +34,9 @@ type ('l, 'p) node = type 'p canonical -type canonical_location = int +type canonical_location + +val dummy_location : canonical_location val root : 'p canonical -> (canonical_location, 'p) node diff --git a/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml index e1107f5b59909f1ef3958976f7e0b9e25da3b57d..8f096f7a8aa13c87f44ad8ae0b012924b3942c0c 100644 --- a/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml @@ -670,7 +670,7 @@ let parse_ty ctxt node = ~allow_ticket:true node -let unparse_ty ctxt ty = Script_ir_translator.unparse_ty ctxt ty +let unparse_ty ctxt ty = Script_ir_translator.unparse_ty ~loc:(-1) ctxt ty module Parse_type_benchmark : Benchmark.S = struct include Parse_type_shared @@ -782,7 +782,7 @@ module Unparse_comparable_type_benchmark : Benchmark.S = struct match ty with | Ex_comparable_ty comp_ty -> Environment.wrap_tzresult - @@ Script_ir_translator.unparse_comparable_ty ctxt comp_ty + @@ Script_ir_translator.unparse_comparable_ty ~loc:() ctxt comp_ty >>? fun (_, ctxt') -> let consumed = Z.to_int @@ -791,7 +791,8 @@ module Unparse_comparable_type_benchmark : Benchmark.S = struct in let workload = Type_workload {nodes = size; consumed} in let closure () = - ignore (Script_ir_translator.unparse_comparable_ty ctxt comp_ty) + ignore + (Script_ir_translator.unparse_comparable_ty ~loc:() ctxt comp_ty) in ok (Generator.Plain {workload; closure}) in diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index 600f87df2069a3bc8f0c308696a720b16efa93df..fb7e31dc856b82a7983449a1c7d842513bc5987d 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -225,9 +225,7 @@ let () = expr) Data_encoding.( obj2 - (req - "location" - Tezos_micheline.Micheline_encoding.canonical_location_encoding) + (req "location" Script.location_encoding) (req "value" Script.expr_encoding)) (function Unexpected_error (loc, expr) -> Some (loc, expr) | _ -> None) (fun (loc, expr) -> Unexpected_error (loc, expr)) @@ -245,7 +243,7 @@ let pair ~loc a b = Micheline.Prim (loc, Script.D_Pair, [a; b], []) let nat ~loc i = Micheline.Int (loc, i) -let unit ~loc () = Micheline.Prim (loc, Script.D_Unit, [], []) +let unit ~loc = Micheline.Prim (loc, Script.D_Unit, [], []) let bytes ~loc b = Micheline.Bytes (loc, b) @@ -262,16 +260,12 @@ let callback ~loc ?entrypoint addr = (** Michelson type combinators: produce a Michelson node of the expected type, and a function to check another node is syntactically equivalent. *) - -type node = - (Micheline.canonical_location, Michelson_v1_primitives.prim) Micheline.node - -type type_eq_combinator = node * (node -> bool) +type type_eq_combinator = Script.node * (Script.node -> bool) (** [t_pair ~loc l] takes a list of types and respective equivalence check functions, and returns a type of n-ary pair of such types and a function checking syntactical equivalence with another node. *) -let t_pair ?(loc = 0) l : type_eq_combinator = +let t_pair ~loc l : type_eq_combinator = let (values, are_ty) = List.split l in let is_pair p = match p with @@ -288,26 +282,26 @@ let t_pair ?(loc = 0) l : type_eq_combinator = in (Micheline.Prim (loc, Script.T_pair, values, []), is_pair) -(** [t_unit ~loc ()] returns a Micheline node for the `unit` type, and +(** [t_unit ~loc] returns a Micheline node for the `unit` type, and a function checking another node is syntactically equivalent. *) -let t_unit ?(loc = 0) () : type_eq_combinator = +let t_unit ~loc : type_eq_combinator = let is_unit p = match p with Micheline.Prim (_, Script.T_unit, [], _) -> true | _ -> false in (Micheline.Prim (loc, Script.T_unit, [], []), is_unit) -(** [t_nat ~loc ()] returns a Micheline node for the `nat` type, and +(** [t_nat ~loc] returns a Micheline node for the `nat` type, and a function checking another node is syntactically equivalent. *) -let t_nat ?(loc = 0) () : type_eq_combinator = +let t_nat ~loc : type_eq_combinator = let is_nat p = match p with Micheline.Prim (_, Script.T_nat, [], _) -> true | _ -> false in (Micheline.Prim (loc, Script.T_nat, [], []), is_nat) -(** [t_address ~loc ()] returns a Micheline node for the `address` +(** [t_address ~loc] returns a Micheline node for the `address` type, and a function checking another node is syntactically equivalent. *) -let t_address ?(loc = 0) () : type_eq_combinator = +let t_address ~loc : type_eq_combinator = let is_address p = match p with | Micheline.Prim (_, Script.T_address, [], _) -> true @@ -319,7 +313,7 @@ let t_address ?(loc = 0) () : type_eq_combinator = type and its own syntactical equivalence checker, and returns a Micheline node for the type `contract c`, and a function checking another node is syntactically equivalent. *) -let t_contract ?(loc = 0) (a, is_a) : type_eq_combinator = +let t_contract ~loc (a, is_a) : type_eq_combinator = let is_contract c = match c with | Micheline.Prim (_, Script.T_contract, [a], _) -> is_a a @@ -333,7 +327,7 @@ let t_contract ?(loc = 0) (a, is_a) : type_eq_combinator = syntactically equivalent. The view type is defined by [TZIP4](https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-4/tzip-4.md). *) -let t_view ?loc a b : type_eq_combinator = t_pair ?loc [a; t_contract ?loc b] +let t_view ~loc a b : type_eq_combinator = t_pair ~loc [a; t_contract ~loc b] (** * Actions *) @@ -465,34 +459,37 @@ let action_encoding = getTotalSupply_encoding; ] -let transfer_type = t_pair [t_address (); t_address (); t_nat ()] +let transfer_type ~loc = + t_pair ~loc [t_address ~loc; t_address ~loc; t_nat ~loc] -let approve_type = t_pair [t_address (); t_nat ()] +let approve_type ~loc = t_pair ~loc [t_address ~loc; t_nat ~loc] -let getAllowance_type = t_view (t_pair [t_address (); t_address ()]) (t_nat ()) +let getAllowance_type ~loc = + t_view ~loc (t_pair ~loc [t_address ~loc; t_address ~loc]) (t_nat ~loc) -let getBalance_type = t_view (t_address ()) (t_nat ()) +let getBalance_type ~loc = t_view ~loc (t_address ~loc) (t_nat ~loc) -let getTotalSupply_type = t_view (t_unit ()) (t_nat ()) +let getTotalSupply_type ~loc = t_view ~loc (t_unit ~loc) (t_nat ~loc) let standard_entrypoints = + let loc = -1 in [ - ("transfer", transfer_type); - ("approve", approve_type); - ("getAllowance", getAllowance_type); - ("getBalance", getBalance_type); - ("getTotalSupply", getTotalSupply_type); + ("transfer", transfer_type ~loc); + ("approve", approve_type ~loc); + ("getAllowance", getAllowance_type ~loc); + ("getBalance", getBalance_type ~loc); + ("getTotalSupply", getTotalSupply_type ~loc); ] -let view_input ?(loc = 0) action = +let view_input ~loc action = match action with | Get_allowance (source, destination, _) -> pair ~loc (address ~loc source) (address ~loc destination) | Get_balance (addr, _) -> address ~loc addr - | Get_total_supply _ -> unit ~loc () - | _ -> unit ~loc () + | Get_total_supply _ -> unit ~loc + | _ -> unit ~loc -let action_to_expr ?(loc = 0) action = +let action_to_expr ~loc action = match action with | Transfer (source, destination, amount) -> pair @@ -501,13 +498,13 @@ let action_to_expr ?(loc = 0) action = (pair ~loc (address ~loc destination) (nat ~loc amount)) | Approve (addr, amount) -> pair ~loc (address ~loc addr) (nat ~loc amount) | Get_allowance (_, _, (cb, entrypoint)) -> - let input = view_input action in + let input = view_input ~loc action in pair ~loc input (callback ~loc ?entrypoint cb) | Get_balance (_, (cb, entrypoint)) -> - let input = view_input action in + let input = view_input ~loc action in pair ~loc input (callback ~loc ?entrypoint cb) | Get_total_supply (cb, entrypoint) -> - let input = view_input action in + let input = view_input ~loc action in pair ~loc input (callback ~loc ?entrypoint cb) let parse_address error = function @@ -723,7 +720,7 @@ let contract_has_fa12_interface : let translate_action_to_argument action = let entrypoint = action_to_entrypoint action in - let expr = Micheline.strip_locations (action_to_expr action) in + let expr = Micheline.strip_locations (action_to_expr ~loc:() action) in (entrypoint, Format.asprintf "%a" Michelson_v1_printer.print_expr expr) let parse_error = @@ -860,7 +857,7 @@ let build_transaction_operation ?(tez_amount = Tez.zero) ?fee ?gas_limit ?storage_limit token action = let entrypoint = action_to_entrypoint action in let parameters = - Script.lazy_expr (Micheline.strip_locations (action_to_expr action)) + Script.lazy_expr (Micheline.strip_locations (action_to_expr ~loc:() action)) in let operation = Transaction @@ -956,7 +953,7 @@ let run_view_action (cctxt : #Protocol_client_context.full) ~chain ~block is_viewable_action action >>=? fun () -> contract_has_fa12_interface cctxt ~chain ~block ~contract () >>=? fun () -> let entrypoint = action_to_entrypoint action in - let input = Micheline.strip_locations (view_input action) in + let input = Micheline.strip_locations (view_input ~loc:() action) in Chain_services.chain_id cctxt ~chain () >>=? fun chain_id -> Plugin.RPC.Scripts.run_view cctxt diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index c712af89a2dd38954ac4274dab0170c72fa0b9e1..8022bd2d79860fbbf872c395160ca8c6fab566c3 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -54,9 +54,13 @@ val print_action : Format.formatter -> action -> unit val action_encoding : action Data_encoding.encoding -val action_to_expr : ?loc:Script.location -> action -> Script.node +val action_to_expr : + loc:'loc -> action -> ('loc, Script.prim) Tezos_micheline.Micheline.node -val action_of_expr : entrypoint:string -> Script.node -> action tzresult +val action_of_expr : + entrypoint:string -> + (_, Script.prim) Tezos_micheline.Micheline.node -> + action tzresult (** [convert_wrapped_parameter_into_action ccctx ~chain ~block ~contract parameter] converts a wrapped FA1.2 contract [parameter] diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 8a9dd286262b82079f08323d75161979041a4437..0a7429d36642d4796e40b4f71f0545b17a392dfa 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -640,11 +640,11 @@ let action_to_expr_generic ~loc = function let action_to_expr_legacy ~loc = function | Transfer {amount; destination; entrypoint; parameter_type; parameter} -> - if parameter <> Tezos_micheline.Micheline.strip_locations (unit ~loc:0) + if parameter <> Tezos_micheline.Micheline.strip_locations (unit ~loc:()) then Error_monad.error @@ Unsupported_feature_generic_call parameter else if parameter_type - <> Tezos_micheline.Micheline.strip_locations (unit_t ~loc:0) + <> Tezos_micheline.Micheline.strip_locations (unit_t ~loc:()) then Error_monad.error @@ Unsupported_feature_generic_call_ty parameter_type else @@ -739,9 +739,9 @@ let action_of_expr_not_generic e = Data_encoding.Binary.of_bytes_exn Contract.encoding s; entrypoint = "default"; parameter_type = - Tezos_micheline.Micheline.strip_locations @@ unit_t ~loc:0; + Tezos_micheline.Micheline.strip_locations @@ unit_t ~loc:(); parameter = - Tezos_micheline.Micheline.strip_locations @@ unit ~loc:0; + Tezos_micheline.Micheline.strip_locations @@ unit ~loc:(); }) | Tezos_micheline.Micheline.Prim ( _, @@ -876,7 +876,7 @@ let multisig_create_param ~counter ~generic ~action ~optional_signatures () : return @@ some ~loc (String (loc, Signature.to_b58check signature))) optional_signatures >>=? fun l -> - Lwt.return @@ action_to_expr ~loc:0 ~generic action >>=? fun expr -> + Lwt.return @@ action_to_expr ~loc ~generic action >>=? fun expr -> return @@ strip_locations @@ pair ~loc (pair ~loc (int ~loc counter) expr) (Seq (loc, l)) @@ -994,7 +994,7 @@ let check_action (cctxt : #Protocol_client_context.full) ~action ~balance ?gas return_unit | Lambda code -> let action_t = - Tezos_micheline.Micheline.strip_locations (lambda_action_t ~loc:0) + Tezos_micheline.Micheline.strip_locations (lambda_action_t ~loc:()) in trace (Ill_typed_lambda (code, action_t)) @@ Plugin.RPC.Scripts.typecheck_data diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index aafd25cb566e48004a29f4d0b4872f125b6a22ea..2bac75ecee32896947cc0f07112c9e6ab6fa4916 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1239,50 +1239,56 @@ module RPC = struct open Script_ir_annot open Script_typed_ir - let rec unparse_comparable_ty : type a. a comparable_ty -> Script.node = - function - | Unit_key meta -> Prim (-1, T_unit, [], unparse_type_annot meta.annot) - | Never_key meta -> Prim (-1, T_never, [], unparse_type_annot meta.annot) - | Int_key meta -> Prim (-1, T_int, [], unparse_type_annot meta.annot) - | Nat_key meta -> Prim (-1, T_nat, [], unparse_type_annot meta.annot) + let rec unparse_comparable_ty : + type a loc. + loc:loc -> a comparable_ty -> (loc, Script.prim) Micheline.node = + fun ~loc -> function + | Unit_key meta -> Prim (loc, T_unit, [], unparse_type_annot meta.annot) + | Never_key meta -> + Prim (loc, T_never, [], unparse_type_annot meta.annot) + | Int_key meta -> Prim (loc, T_int, [], unparse_type_annot meta.annot) + | Nat_key meta -> Prim (loc, T_nat, [], unparse_type_annot meta.annot) | Signature_key meta -> - Prim (-1, T_signature, [], unparse_type_annot meta.annot) + Prim (loc, T_signature, [], unparse_type_annot meta.annot) | String_key meta -> - Prim (-1, T_string, [], unparse_type_annot meta.annot) - | Bytes_key meta -> Prim (-1, T_bytes, [], unparse_type_annot meta.annot) - | Mutez_key meta -> Prim (-1, T_mutez, [], unparse_type_annot meta.annot) - | Bool_key meta -> Prim (-1, T_bool, [], unparse_type_annot meta.annot) + Prim (loc, T_string, [], unparse_type_annot meta.annot) + | Bytes_key meta -> + Prim (loc, T_bytes, [], unparse_type_annot meta.annot) + | Mutez_key meta -> + Prim (loc, T_mutez, [], unparse_type_annot meta.annot) + | Bool_key meta -> Prim (loc, T_bool, [], unparse_type_annot meta.annot) | Key_hash_key meta -> - Prim (-1, T_key_hash, [], unparse_type_annot meta.annot) - | Key_key meta -> Prim (-1, T_key, [], unparse_type_annot meta.annot) + Prim (loc, T_key_hash, [], unparse_type_annot meta.annot) + | Key_key meta -> Prim (loc, T_key, [], unparse_type_annot meta.annot) | Timestamp_key meta -> - Prim (-1, T_timestamp, [], unparse_type_annot meta.annot) + Prim (loc, T_timestamp, [], unparse_type_annot meta.annot) | Address_key meta -> - Prim (-1, T_address, [], unparse_type_annot meta.annot) + Prim (loc, T_address, [], unparse_type_annot meta.annot) | Chain_id_key meta -> - Prim (-1, T_chain_id, [], unparse_type_annot meta.annot) + Prim (loc, T_chain_id, [], unparse_type_annot meta.annot) | Pair_key ((l, al), (r, ar), meta) -> - let tl = add_field_annot al None (unparse_comparable_ty l) in - let tr = add_field_annot ar None (unparse_comparable_ty r) in - Prim (-1, T_pair, [tl; tr], unparse_type_annot meta.annot) + let tl = add_field_annot al None (unparse_comparable_ty ~loc l) in + let tr = add_field_annot ar None (unparse_comparable_ty ~loc r) in + Prim (loc, T_pair, [tl; tr], unparse_type_annot meta.annot) | Union_key ((l, al), (r, ar), meta) -> - let tl = add_field_annot al None (unparse_comparable_ty l) in - let tr = add_field_annot ar None (unparse_comparable_ty r) in - Prim (-1, T_or, [tl; tr], unparse_type_annot meta.annot) + let tl = add_field_annot al None (unparse_comparable_ty ~loc l) in + let tr = add_field_annot ar None (unparse_comparable_ty ~loc r) in + Prim (loc, T_or, [tl; tr], unparse_type_annot meta.annot) | Option_key (t, meta) -> Prim - ( -1, + ( loc, T_option, - [unparse_comparable_ty t], + [unparse_comparable_ty ~loc t], unparse_type_annot meta.annot ) - let unparse_memo_size memo_size = + let unparse_memo_size ~loc memo_size = let z = Alpha_context.Sapling.Memo_size.unparse_to_z memo_size in - Int (-1, z) + Int (loc, z) - let rec unparse_ty : type a. a ty -> Script.node = - fun ty -> - let return (name, args, annot) = Prim (-1, name, args, annot) in + let rec unparse_ty : + type a loc. loc:loc -> a ty -> (loc, Script.prim) Micheline.node = + fun ~loc ty -> + let return (name, args, annot) = Prim (loc, name, args, annot) in match ty with | Unit_t meta -> return (T_unit, [], unparse_type_annot meta.annot) | Int_t meta -> return (T_int, [], unparse_type_annot meta.annot) @@ -1311,56 +1317,56 @@ module RPC = struct | Bls12_381_fr_t meta -> return (T_bls12_381_fr, [], unparse_type_annot meta.annot) | Contract_t (ut, meta) -> - let t = unparse_ty ut in + let t = unparse_ty ~loc ut in return (T_contract, [t], unparse_type_annot meta.annot) | Pair_t ((utl, l_field, l_var), (utr, r_field, r_var), meta) -> let annot = unparse_type_annot meta.annot in - let utl = unparse_ty utl in + let utl = unparse_ty ~loc utl in let tl = add_field_annot l_field l_var utl in - let utr = unparse_ty utr in + let utr = unparse_ty ~loc utr in let tr = add_field_annot r_field r_var utr in return (T_pair, [tl; tr], annot) | Union_t ((utl, l_field), (utr, r_field), meta) -> let annot = unparse_type_annot meta.annot in - let utl = unparse_ty utl in + let utl = unparse_ty ~loc utl in let tl = add_field_annot l_field None utl in - let utr = unparse_ty utr in + let utr = unparse_ty ~loc utr in let tr = add_field_annot r_field None utr in return (T_or, [tl; tr], annot) | Lambda_t (uta, utr, meta) -> - let ta = unparse_ty uta in - let tr = unparse_ty utr in + let ta = unparse_ty ~loc uta in + let tr = unparse_ty ~loc utr in return (T_lambda, [ta; tr], unparse_type_annot meta.annot) | Option_t (ut, meta) -> let annot = unparse_type_annot meta.annot in - let ut = unparse_ty ut in + let ut = unparse_ty ~loc ut in return (T_option, [ut], annot) | List_t (ut, meta) -> - let t = unparse_ty ut in + let t = unparse_ty ~loc ut in return (T_list, [t], unparse_type_annot meta.annot) | Ticket_t (ut, meta) -> - let t = unparse_comparable_ty ut in + let t = unparse_comparable_ty ~loc ut in return (T_ticket, [t], unparse_type_annot meta.annot) | Set_t (ut, meta) -> - let t = unparse_comparable_ty ut in + let t = unparse_comparable_ty ~loc ut in return (T_set, [t], unparse_type_annot meta.annot) | Map_t (uta, utr, meta) -> - let ta = unparse_comparable_ty uta in - let tr = unparse_ty utr in + let ta = unparse_comparable_ty ~loc uta in + let tr = unparse_ty ~loc utr in return (T_map, [ta; tr], unparse_type_annot meta.annot) | Big_map_t (uta, utr, meta) -> - let ta = unparse_comparable_ty uta in - let tr = unparse_ty utr in + let ta = unparse_comparable_ty ~loc uta in + let tr = unparse_ty ~loc utr in return (T_big_map, [ta; tr], unparse_type_annot meta.annot) | Sapling_transaction_t (memo_size, meta) -> return ( T_sapling_transaction, - [unparse_memo_size memo_size], + [unparse_memo_size ~loc memo_size], unparse_type_annot meta.annot ) | Sapling_state_t (memo_size, meta) -> return ( T_sapling_state, - [unparse_memo_size memo_size], + [unparse_memo_size ~loc memo_size], unparse_type_annot meta.annot ) | Chest_t meta -> return (T_chest, [], unparse_type_annot meta.annot) | Chest_key_t meta -> @@ -1567,7 +1573,7 @@ module RPC = struct arg_type entrypoint ) >>? fun (_f, Ex_ty ty) -> - unparse_ty ctxt ty >|? fun (ty_node, _) -> + unparse_ty ~loc:() ctxt ty >|? fun (ty_node, _) -> Micheline.strip_locations ty_node ) in Registration.register0 @@ -1916,7 +1922,7 @@ module RPC = struct ~allow_ticket:true (Micheline.root typ) >>?= fun (Ex_ty typ, _ctxt) -> - let normalized = Unparse_types.unparse_ty typ in + let normalized = Unparse_types.unparse_ty ~loc:() typ in return @@ Micheline.strip_locations normalized) ; Registration.register0 ~chunked:true S.run_operation run_operation_service ; Registration.register0 diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 72600ff002556cc21b095c0016c7609a70bf83c0..134ddda22336803439d0d7a0a843f45c052192b5 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -647,7 +647,11 @@ module Script : sig val lazy_expr : expr -> lazy_expr - type node = (location, prim) Micheline.node + type 'location michelson_node = ('location, prim) Micheline.node + + type unlocated_michelson_node = unit michelson_node + + type node = location michelson_node type t = {code : lazy_expr; storage : lazy_expr} @@ -677,7 +681,7 @@ module Script : sig val unit_parameter : lazy_expr - val strip_locations_cost : node -> Gas.cost + val strip_locations_cost : _ michelson_node -> Gas.cost val strip_annotations_cost : node -> Gas.cost @@ -912,11 +916,11 @@ module Global_constants_storage : sig continuation in `f`. *) val bottom_up_fold_cps : 'accumulator -> - Script.node -> - ('accumulator -> Script.node -> 'return) -> + 'loc Script.michelson_node -> + ('accumulator -> 'loc Script.michelson_node -> 'return) -> ('accumulator -> - Script_repr.node -> - ('accumulator -> Script.node -> 'return) -> + 'loc Script.michelson_node -> + ('accumulator -> 'loc Script.michelson_node -> 'return) -> 'return) -> 'return diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index f9c029c3502452652a2008bd7b2eb2c3a2274147..d8037c0709becfeae0c634db2a6ae2caf5ca0b75 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -368,7 +368,7 @@ let[@coq_axiom_with_reason "gadt"] register () = entrypoint ) |> function | Ok (_f, Ex_ty ty) -> - unparse_ty ctxt ty >|? fun (ty_node, _) -> + unparse_ty ~loc:() ctxt ty >|? fun (ty_node, _) -> Some (Micheline.strip_locations ty_node) | Error _ -> Result.return_none)) ; opt_register1 ~chunked:true S.list_entrypoints (fun ctxt v () () -> diff --git a/src/proto_alpha/lib_protocol/global_constants_storage.ml b/src/proto_alpha/lib_protocol/global_constants_storage.ml index 0db6ec9a48cc7252475a54fb69ae10719873bd13..429b454d44f180813cc8c410dd63f0b6f56a649e 100644 --- a/src/proto_alpha/lib_protocol/global_constants_storage.ml +++ b/src/proto_alpha/lib_protocol/global_constants_storage.ml @@ -232,13 +232,13 @@ let check_depth node = match node with | Int _ | String _ | Bytes _ | Prim (_, _, [], _) | Seq (_, []) -> (k [@tailcall]) (depth + 1) - | Prim (_, _, hd :: tl, _) | Seq (_, hd :: tl) -> + | Prim (loc, _, hd :: tl, _) | Seq (loc, hd :: tl) -> (advance [@tailcall]) hd (depth + 1) (fun dhd -> (advance [@tailcall]) (* Because [depth] doesn't care about the content of the expression, we can safely throw away information about primitives and replace them with the [Seq] constructor.*) - (Seq (-1, tl)) + (Seq (loc, tl)) depth (fun dtl -> (k [@tailcall]) (Compare.Int.max dhd dtl))) in diff --git a/src/proto_alpha/lib_protocol/global_constants_storage.mli b/src/proto_alpha/lib_protocol/global_constants_storage.mli index 6c4116c15568c1f4999d75e3481ea1636bc02f2b..096143c3c2af6aa0fe32057859cc98513c336712 100644 --- a/src/proto_alpha/lib_protocol/global_constants_storage.mli +++ b/src/proto_alpha/lib_protocol/global_constants_storage.mli @@ -130,11 +130,11 @@ module Internal_for_tests : sig *) val bottom_up_fold_cps : 'accumulator -> - Script_repr.node -> - ('accumulator -> Script_repr.node -> 'return) -> + 'loc Script_repr.michelson_node -> + ('accumulator -> 'loc Script_repr.michelson_node -> 'return) -> ('accumulator -> - Script_repr.node -> - ('accumulator -> Script_repr.node -> 'return) -> + 'loc Script_repr.michelson_node -> + ('accumulator -> 'loc Script_repr.michelson_node -> 'return) -> 'return) -> 'return diff --git a/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml b/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml index c9fe5a9cde7a29a396c7508808b69c195d46fd64..c1434b14ec1462e2a9a8fc17e0d9a66ddfe7babc 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml +++ b/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml @@ -549,8 +549,8 @@ let prims_of_strings expr = (Invalid_primitive_name (expr, loc)) (prim_of_string prim) >>? fun prim -> - List.map_e convert args >|? fun args -> Prim (0, prim, args, annot) - | Seq (_, args) -> List.map_e convert args >|? fun args -> Seq (0, args) + List.map_e convert args >|? fun args -> Prim (loc, prim, args, annot) + | Seq (loc, args) -> List.map_e convert args >|? fun args -> Seq (loc, args) in convert (root expr) >|? fun expr -> strip_locations expr [@@coq_axiom_with_reason @@ -559,13 +559,13 @@ let prims_of_strings expr = let strings_of_prims expr = let rec convert = function | (Int _ | String _ | Bytes _) as expr -> expr - | Prim (_, prim, args, annot) -> + | Prim (loc, prim, args, annot) -> let prim = string_of_prim prim in let args = List.map convert args in - Prim (0, prim, args, annot) - | Seq (_, args) -> + Prim (loc, prim, args, annot) + | Seq (loc, args) -> let args = List.map convert args in - Seq (0, args) + Seq (loc, args) in strip_locations (convert (root expr)) [@@coq_axiom_with_reason diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index c4d1081e1022b05589d2024faaf4a6a6a411450b..c4181caf593866f5ae3c3b516dacb449d5d39591 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -457,7 +457,8 @@ let apply ctxt gas capture_ty capture lam = let (Item_t (full_arg_ty, _, _)) = descr.kbef in let ctxt = update_context gas ctxt in unparse_data ctxt Optimized capture_ty capture >>=? fun (const_expr, ctxt) -> - unparse_ty ctxt capture_ty >>?= fun (ty_expr, ctxt) -> + let loc = Micheline.dummy_location in + unparse_ty ~loc ctxt capture_ty >>?= fun (ty_expr, ctxt) -> match full_arg_ty with | Pair_t ((capture_ty, _, _), (arg_ty, _, _), _) -> let arg_stack_ty = Item_t (arg_ty, Bot_t, None) in @@ -479,10 +480,10 @@ let apply ctxt gas capture_ty capture lam = in let full_expr = Micheline.Seq - ( 0, + ( loc, [ - Prim (0, I_PUSH, [ty_expr; const_expr], []); - Prim (0, I_PAIR, [], []); + Prim (loc, I_PUSH, [ty_expr; const_expr], []); + Prim (loc, I_PAIR, [], []); expr; ] ) in @@ -538,18 +539,19 @@ let transfer (ctxt, sc) gas amount tp p destination entrypoint = let create_contract (ctxt, sc) gas storage_type param_type code views root_name delegate credit init = let ctxt = update_context gas ctxt in - unparse_ty ctxt param_type >>?= fun (unparsed_param_type, ctxt) -> + let loc = Micheline.dummy_location in + unparse_ty ~loc ctxt param_type >>?= fun (unparsed_param_type, ctxt) -> let unparsed_param_type = Script_ir_translator.add_field_annot root_name None unparsed_param_type in - unparse_ty ctxt storage_type >>?= fun (unparsed_storage_type, ctxt) -> + unparse_ty ~loc ctxt storage_type >>?= fun (unparsed_storage_type, ctxt) -> let open Micheline in let view name {input_ty; output_ty; view_code} views = Prim - ( 0, + ( loc, K_view, [ - String (0, Script_string.to_string name); + String (loc, Script_string.to_string name); input_ty; output_ty; view_code; @@ -561,11 +563,11 @@ let create_contract (ctxt, sc) gas storage_type param_type code views root_name let code = strip_locations (Seq - ( 0, + ( loc, [ - Prim (0, K_parameter, [unparsed_param_type], []); - Prim (0, K_storage, [unparsed_storage_type], []); - Prim (0, K_code, [code], []); + Prim (loc, K_parameter, [unparsed_param_type], []); + Prim (loc, K_storage, [unparsed_storage_type], []); + Prim (loc, K_code, [code], []); ] @ views )) in @@ -835,7 +837,7 @@ type ('a, 'b) ifailwith_type = logger option -> outdated_context * step_constants -> local_gas_counter -> - int -> + Script.location -> 'a ty -> 'a -> ('b, error trace) result Lwt.t diff --git a/src/proto_alpha/lib_protocol/script_ir_annot.ml b/src/proto_alpha/lib_protocol/script_ir_annot.ml index 48cde7e769aba22c371095ac002ac12d58ebe8e5..1c3436c23525dd246161a94d9be39941ad3867cf 100644 --- a/src/proto_alpha/lib_protocol/script_ir_annot.ml +++ b/src/proto_alpha/lib_protocol/script_ir_annot.ml @@ -280,14 +280,15 @@ let get_two_annot loc = function | [a; b] -> ok (a, b) | _ -> error (Unexpected_annotation loc) -let parse_type_annot : int -> string list -> type_annot option tzresult = +let parse_type_annot : + Script.location -> string list -> type_annot option tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc vars >>? fun () -> error_unexpected_annot loc fields >>? fun () -> get_one_annot loc types let parse_composed_type_annot : - int -> + Script.location -> string list -> (type_annot option * field_annot option * field_annot option) tzresult = fun loc annot -> @@ -296,7 +297,8 @@ let parse_composed_type_annot : get_one_annot loc types >>? fun t -> get_two_annot loc fields >|? fun (f1, f2) -> (t, f1, f2) -let parse_field_annot : int -> string list -> field_annot option tzresult = +let parse_field_annot : + Script.location -> string list -> field_annot option tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc vars >>? fun () -> @@ -329,8 +331,10 @@ let check_correct_field : else error (Inconsistent_field_annotations ("%" ^ s1, "%" ^ s2)) let parse_var_annot : - int -> ?default:var_annot option -> string list -> var_annot option tzresult - = + Script.location -> + ?default:var_annot option -> + string list -> + var_annot option tzresult = fun loc ?default annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> @@ -364,7 +368,7 @@ let common_prefix v1 v2 = | (_, _) -> None let parse_constr_annot : - int -> + Script.location -> ?if_special_first:field_annot option -> ?if_special_second:field_annot option -> string list -> @@ -395,7 +399,9 @@ let parse_constr_annot : (v, t, f1, f2) let parse_two_var_annot : - int -> string list -> (var_annot option * var_annot option) tzresult = + Script.location -> + string list -> + (var_annot option * var_annot option) tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc types >>? fun () -> @@ -415,7 +421,7 @@ let var_annot_from_special : | None -> value_annot let parse_destr_annot : - int -> + Script.location -> string list -> default_accessor:field_annot option -> field_name:field_annot option -> @@ -435,7 +441,7 @@ let parse_destr_annot : (v, f) let parse_unpair_annot : - int -> + Script.location -> string list -> field_name_car:field_annot option -> field_name_cdr:field_annot option -> @@ -482,7 +488,7 @@ let parse_unpair_annot : (vcar, vcdr, fcar, fcdr) let parse_entrypoint_annot : - int -> + Script.location -> ?default:var_annot option -> string list -> (var_annot option * field_annot option) tzresult = @@ -495,7 +501,9 @@ let parse_entrypoint_annot : | None -> ( match default with Some a -> (a, f) | None -> (None, f)) let parse_var_type_annot : - int -> string list -> (var_annot option * type_annot option) tzresult = + Script.location -> + string list -> + (var_annot option * type_annot option) tzresult = fun loc annot -> parse_annots loc annot >>? classify_annot loc >>? fun (vars, types, fields) -> error_unexpected_annot loc fields >>? fun () -> diff --git a/src/proto_alpha/lib_protocol/script_ir_annot.mli b/src/proto_alpha/lib_protocol/script_ir_annot.mli index 367d3cf339b39397d79ed1c580c9d10d72577c8a..9a9008de146929a66acfa76c7244c175edb7aca3 100644 --- a/src/proto_alpha/lib_protocol/script_ir_annot.mli +++ b/src/proto_alpha/lib_protocol/script_ir_annot.mli @@ -128,18 +128,20 @@ val merge_field_annot : val merge_var_annot : var_annot option -> var_annot option -> var_annot option (** @return an error {!Unexpected_annotation} in the monad the list is not empty. *) -val error_unexpected_annot : int -> 'a list -> unit tzresult +val error_unexpected_annot : Script.location -> 'a list -> unit tzresult (** Parse a type annotation only. *) -val parse_type_annot : int -> string list -> type_annot option tzresult +val parse_type_annot : + Script.location -> string list -> type_annot option tzresult (** Parse a field annotation only. *) -val parse_field_annot : int -> string list -> field_annot option tzresult +val parse_field_annot : + Script.location -> string list -> field_annot option tzresult (** Parse an annotation for composed types, of the form [:ty_name %field1 %field2] in any order. *) val parse_composed_type_annot : - int -> + Script.location -> string list -> (type_annot option * field_annot option * field_annot option) tzresult @@ -155,12 +157,15 @@ val check_correct_field : (** Parse a variable annotation, replaced by a default value if [None]. *) val parse_var_annot : - int -> ?default:var_annot option -> string list -> var_annot option tzresult + Script.location -> + ?default:var_annot option -> + string list -> + var_annot option tzresult val is_allowed_char : char -> bool val parse_constr_annot : - int -> + Script.location -> ?if_special_first:field_annot option -> ?if_special_second:field_annot option -> string list -> @@ -171,10 +176,12 @@ val parse_constr_annot : tzresult val parse_two_var_annot : - int -> string list -> (var_annot option * var_annot option) tzresult + Script.location -> + string list -> + (var_annot option * var_annot option) tzresult val parse_destr_annot : - int -> + Script.location -> string list -> default_accessor:field_annot option -> field_name:field_annot option -> @@ -183,7 +190,7 @@ val parse_destr_annot : (var_annot option * field_annot option) tzresult val parse_unpair_annot : - int -> + Script.location -> string list -> field_name_car:field_annot option -> field_name_cdr:field_annot option -> @@ -197,10 +204,12 @@ val parse_unpair_annot : tzresult val parse_entrypoint_annot : - int -> + Script.location -> ?default:var_annot option -> string list -> (var_annot option * field_annot option) tzresult val parse_var_type_annot : - int -> string list -> (var_annot option * type_annot option) tzresult + Script.location -> + string list -> + (var_annot option * type_annot option) tzresult diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 50e0a90ac161249e97b23520ae95b19475684314..992d1c3fb7033ca803d5f59a24accbaef0d2d0c3 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -106,7 +106,7 @@ type tc_context = type unparsing_mode = Optimized | Readable | Optimized_legacy type type_logger = - int -> + Script.location -> (Script.expr * Script.annot) list -> (Script.expr * Script.annot) list -> unit @@ -203,51 +203,63 @@ let add_field_annot a var = function | expr -> expr let rec unparse_comparable_ty_uncarbonated : - type a. a comparable_ty -> Script.node = function - | Unit_key meta -> Prim (-1, T_unit, [], unparse_type_annot meta.annot) - | Never_key meta -> Prim (-1, T_never, [], unparse_type_annot meta.annot) - | Int_key meta -> Prim (-1, T_int, [], unparse_type_annot meta.annot) - | Nat_key meta -> Prim (-1, T_nat, [], unparse_type_annot meta.annot) + type a loc. loc:loc -> a comparable_ty -> loc Script.michelson_node = + fun ~loc -> function + | Unit_key meta -> Prim (loc, T_unit, [], unparse_type_annot meta.annot) + | Never_key meta -> Prim (loc, T_never, [], unparse_type_annot meta.annot) + | Int_key meta -> Prim (loc, T_int, [], unparse_type_annot meta.annot) + | Nat_key meta -> Prim (loc, T_nat, [], unparse_type_annot meta.annot) | Signature_key meta -> - Prim (-1, T_signature, [], unparse_type_annot meta.annot) - | String_key meta -> Prim (-1, T_string, [], unparse_type_annot meta.annot) - | Bytes_key meta -> Prim (-1, T_bytes, [], unparse_type_annot meta.annot) - | Mutez_key meta -> Prim (-1, T_mutez, [], unparse_type_annot meta.annot) - | Bool_key meta -> Prim (-1, T_bool, [], unparse_type_annot meta.annot) - | Key_hash_key meta -> Prim (-1, T_key_hash, [], unparse_type_annot meta.annot) - | Key_key meta -> Prim (-1, T_key, [], unparse_type_annot meta.annot) + Prim (loc, T_signature, [], unparse_type_annot meta.annot) + | String_key meta -> Prim (loc, T_string, [], unparse_type_annot meta.annot) + | Bytes_key meta -> Prim (loc, T_bytes, [], unparse_type_annot meta.annot) + | Mutez_key meta -> Prim (loc, T_mutez, [], unparse_type_annot meta.annot) + | Bool_key meta -> Prim (loc, T_bool, [], unparse_type_annot meta.annot) + | Key_hash_key meta -> + Prim (loc, T_key_hash, [], unparse_type_annot meta.annot) + | Key_key meta -> Prim (loc, T_key, [], unparse_type_annot meta.annot) | Timestamp_key meta -> - Prim (-1, T_timestamp, [], unparse_type_annot meta.annot) - | Address_key meta -> Prim (-1, T_address, [], unparse_type_annot meta.annot) - | Chain_id_key meta -> Prim (-1, T_chain_id, [], unparse_type_annot meta.annot) + Prim (loc, T_timestamp, [], unparse_type_annot meta.annot) + | Address_key meta -> Prim (loc, T_address, [], unparse_type_annot meta.annot) + | Chain_id_key meta -> + Prim (loc, T_chain_id, [], unparse_type_annot meta.annot) | Pair_key ((l, al), (r, ar), meta) -> ( - let tl = add_field_annot al None (unparse_comparable_ty_uncarbonated l) in - let tr = add_field_annot ar None (unparse_comparable_ty_uncarbonated r) in + let tl = + add_field_annot al None (unparse_comparable_ty_uncarbonated ~loc l) + in + let tr = + add_field_annot ar None (unparse_comparable_ty_uncarbonated ~loc r) + in (* Fold [pair a1 (pair ... (pair an-1 an))] into [pair a1 ... an] *) (* Note that the folding does not happen if the pair on the right has a field annotation because this annotation would be lost *) match tr with | Prim (_, T_pair, ts, []) -> - Prim (-1, T_pair, tl :: ts, unparse_type_annot meta.annot) - | _ -> Prim (-1, T_pair, [tl; tr], unparse_type_annot meta.annot)) + Prim (loc, T_pair, tl :: ts, unparse_type_annot meta.annot) + | _ -> Prim (loc, T_pair, [tl; tr], unparse_type_annot meta.annot)) | Union_key ((l, al), (r, ar), meta) -> - let tl = add_field_annot al None (unparse_comparable_ty_uncarbonated l) in - let tr = add_field_annot ar None (unparse_comparable_ty_uncarbonated r) in - Prim (-1, T_or, [tl; tr], unparse_type_annot meta.annot) + let tl = + add_field_annot al None (unparse_comparable_ty_uncarbonated ~loc l) + in + let tr = + add_field_annot ar None (unparse_comparable_ty_uncarbonated ~loc r) + in + Prim (loc, T_or, [tl; tr], unparse_type_annot meta.annot) | Option_key (t, meta) -> Prim - ( -1, + ( loc, T_option, - [unparse_comparable_ty_uncarbonated t], + [unparse_comparable_ty_uncarbonated ~loc t], unparse_type_annot meta.annot ) -let unparse_memo_size memo_size = +let unparse_memo_size ~loc memo_size = let z = Sapling.Memo_size.unparse_to_z memo_size in - Int (-1, z) + Int (loc, z) -let rec unparse_ty_uncarbonated : type a. a ty -> Script.node = - fun ty -> - let prim (name, args, annot) = Prim (-1, name, args, annot) in +let rec unparse_ty_uncarbonated : + type a loc. loc:loc -> a ty -> loc Script.michelson_node = + fun ~loc ty -> + let prim (name, args, annot) = Prim (loc, name, args, annot) in match ty with | Unit_t meta -> prim (T_unit, [], unparse_type_annot meta.annot) | Int_t meta -> prim (T_int, [], unparse_type_annot meta.annot) @@ -271,13 +283,13 @@ let rec unparse_ty_uncarbonated : type a. a ty -> Script.node = | Bls12_381_fr_t meta -> prim (T_bls12_381_fr, [], unparse_type_annot meta.annot) | Contract_t (ut, meta) -> - let t = unparse_ty_uncarbonated ut in + let t = unparse_ty_uncarbonated ~loc ut in prim (T_contract, [t], unparse_type_annot meta.annot) | Pair_t ((utl, l_field, l_var), (utr, r_field, r_var), meta) -> let annot = unparse_type_annot meta.annot in - let utl = unparse_ty_uncarbonated utl in + let utl = unparse_ty_uncarbonated ~loc utl in let tl = add_field_annot l_field l_var utl in - let utr = unparse_ty_uncarbonated utr in + let utr = unparse_ty_uncarbonated ~loc utr in let tr = add_field_annot r_field r_var utr in (* Fold [pair a1 (pair ... (pair an-1 an))] into [pair a1 ... an] *) (* Note that the folding does not happen if the pair on the right has an @@ -288,56 +300,56 @@ let rec unparse_ty_uncarbonated : type a. a ty -> Script.node = | _ -> (T_pair, [tl; tr], annot)) | Union_t ((utl, l_field), (utr, r_field), meta) -> let annot = unparse_type_annot meta.annot in - let utl = unparse_ty_uncarbonated utl in + let utl = unparse_ty_uncarbonated ~loc utl in let tl = add_field_annot l_field None utl in - let utr = unparse_ty_uncarbonated utr in + let utr = unparse_ty_uncarbonated ~loc utr in let tr = add_field_annot r_field None utr in prim (T_or, [tl; tr], annot) | Lambda_t (uta, utr, meta) -> - let ta = unparse_ty_uncarbonated uta in - let tr = unparse_ty_uncarbonated utr in + let ta = unparse_ty_uncarbonated ~loc uta in + let tr = unparse_ty_uncarbonated ~loc utr in prim (T_lambda, [ta; tr], unparse_type_annot meta.annot) | Option_t (ut, meta) -> let annot = unparse_type_annot meta.annot in - let ut = unparse_ty_uncarbonated ut in + let ut = unparse_ty_uncarbonated ~loc ut in prim (T_option, [ut], annot) | List_t (ut, meta) -> - let t = unparse_ty_uncarbonated ut in + let t = unparse_ty_uncarbonated ~loc ut in prim (T_list, [t], unparse_type_annot meta.annot) | Ticket_t (ut, meta) -> - let t = unparse_comparable_ty_uncarbonated ut in + let t = unparse_comparable_ty_uncarbonated ~loc ut in prim (T_ticket, [t], unparse_type_annot meta.annot) | Set_t (ut, meta) -> - let t = unparse_comparable_ty_uncarbonated ut in + let t = unparse_comparable_ty_uncarbonated ~loc ut in prim (T_set, [t], unparse_type_annot meta.annot) | Map_t (uta, utr, meta) -> - let ta = unparse_comparable_ty_uncarbonated uta in - let tr = unparse_ty_uncarbonated utr in + let ta = unparse_comparable_ty_uncarbonated ~loc uta in + let tr = unparse_ty_uncarbonated ~loc utr in prim (T_map, [ta; tr], unparse_type_annot meta.annot) | Big_map_t (uta, utr, meta) -> - let ta = unparse_comparable_ty_uncarbonated uta in - let tr = unparse_ty_uncarbonated utr in + let ta = unparse_comparable_ty_uncarbonated ~loc uta in + let tr = unparse_ty_uncarbonated ~loc utr in prim (T_big_map, [ta; tr], unparse_type_annot meta.annot) | Sapling_transaction_t (memo_size, meta) -> prim ( T_sapling_transaction, - [unparse_memo_size memo_size], + [unparse_memo_size ~loc memo_size], unparse_type_annot meta.annot ) | Sapling_state_t (memo_size, meta) -> prim ( T_sapling_state, - [unparse_memo_size memo_size], + [unparse_memo_size ~loc memo_size], unparse_type_annot meta.annot ) | Chest_key_t meta -> prim (T_chest_key, [], unparse_type_annot meta.annot) | Chest_t meta -> prim (T_chest, [], unparse_type_annot meta.annot) -let unparse_ty ctxt ty = +let unparse_ty ~loc ctxt ty = Gas.consume ctxt (Unparse_costs.unparse_type ty) >|? fun ctxt -> - (unparse_ty_uncarbonated ty, ctxt) + (unparse_ty_uncarbonated ~loc ty, ctxt) -let unparse_comparable_ty ctxt comp_ty = +let unparse_comparable_ty ~loc ctxt comp_ty = Gas.consume ctxt (Unparse_costs.unparse_comparable_type comp_ty) - >|? fun ctxt -> (unparse_comparable_ty_uncarbonated comp_ty, ctxt) + >|? fun ctxt -> (unparse_comparable_ty_uncarbonated ~loc comp_ty, ctxt) let[@coq_struct "function_parameter"] rec strip_var_annots = function | (Int _ | String _ | Bytes _) as atom -> atom @@ -356,7 +368,7 @@ let serialize_ty_for_error ty = It is hence OK to use them in errors that are not caught in the validation (only once in apply). *) - let ty = unparse_ty_uncarbonated ty in + let ty = unparse_ty_uncarbonated ~loc:() ty in Micheline.strip_locations (strip_var_annots ty) let[@coq_axiom_with_reason "gadt"] rec comparable_ty_of_ty : @@ -401,7 +413,7 @@ let rec unparse_stack_uncarbonated : type a s. (a, s) stack_ty -> (Script.expr * Script.annot) list = function | Bot_t -> [] | Item_t (ty, rest, annot) -> - let uty = unparse_ty_uncarbonated ty in + let uty = unparse_ty_uncarbonated ~loc:() ty in let urest = unparse_stack_uncarbonated rest in (strip_locations uty, unparse_var_annot annot) :: urest @@ -444,30 +456,31 @@ let name_of_ty : type a. a ty -> type_annot option = function | Chest_key_t meta -> meta.annot | Chest_t meta -> meta.annot -let unparse_unit ctxt () = ok (Prim (-1, D_Unit, [], []), ctxt) +let unparse_unit ~loc ctxt () = ok (Prim (loc, D_Unit, [], []), ctxt) -let unparse_int ctxt v = ok (Int (-1, Script_int.to_zint v), ctxt) +let unparse_int ~loc ctxt v = ok (Int (loc, Script_int.to_zint v), ctxt) -let unparse_nat ctxt v = ok (Int (-1, Script_int.to_zint v), ctxt) +let unparse_nat ~loc ctxt v = ok (Int (loc, Script_int.to_zint v), ctxt) -let unparse_string ctxt s = ok (String (-1, Script_string.to_string s), ctxt) +let unparse_string ~loc ctxt s = + ok (String (loc, Script_string.to_string s), ctxt) -let unparse_bytes ctxt s = ok (Bytes (-1, s), ctxt) +let unparse_bytes ~loc ctxt s = ok (Bytes (loc, s), ctxt) -let unparse_bool ctxt b = - ok (Prim (-1, (if b then D_True else D_False), [], []), ctxt) +let unparse_bool ~loc ctxt b = + ok (Prim (loc, (if b then D_True else D_False), [], []), ctxt) -let unparse_timestamp ctxt mode t = +let unparse_timestamp ~loc ctxt mode t = match mode with | Optimized | Optimized_legacy -> - ok (Int (-1, Script_timestamp.to_zint t), ctxt) + ok (Int (loc, Script_timestamp.to_zint t), ctxt) | Readable -> ( Gas.consume ctxt Unparse_costs.timestamp_readable >>? fun ctxt -> match Script_timestamp.to_notation t with - | None -> ok (Int (-1, Script_timestamp.to_zint t), ctxt) - | Some s -> ok (String (-1, s), ctxt)) + | None -> ok (Int (loc, Script_timestamp.to_zint t), ctxt) + | Some s -> ok (String (loc, s), ctxt)) -let unparse_address ctxt mode (c, entrypoint) = +let unparse_address ~loc ctxt mode (c, entrypoint) = Gas.consume ctxt Unparse_costs.contract >>? fun ctxt -> (match entrypoint with (* given parse_address, this should not happen *) @@ -482,92 +495,93 @@ let unparse_address ctxt mode (c, entrypoint) = Data_encoding.(tup2 Contract.encoding Variable.string) (c, entrypoint) in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) | Readable -> let notation = match entrypoint with | "default" -> Contract.to_b58check c | entrypoint -> Contract.to_b58check c ^ "%" ^ entrypoint in - (String (-1, notation), ctxt) + (String (loc, notation), ctxt) -let unparse_contract ctxt mode (_, address) = unparse_address ctxt mode address +let unparse_contract ~loc ctxt mode (_, address) = + unparse_address ~loc ctxt mode address -let unparse_signature ctxt mode s = +let unparse_signature ~loc ctxt mode s = match mode with | Optimized | Optimized_legacy -> Gas.consume ctxt Unparse_costs.signature_optimized >|? fun ctxt -> let bytes = Data_encoding.Binary.to_bytes_exn Signature.encoding s in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) | Readable -> Gas.consume ctxt Unparse_costs.signature_readable >|? fun ctxt -> - (String (-1, Signature.to_b58check s), ctxt) + (String (loc, Signature.to_b58check s), ctxt) -let unparse_mutez ctxt v = ok (Int (-1, Z.of_int64 (Tez.to_mutez v)), ctxt) +let unparse_mutez ~loc ctxt v = ok (Int (loc, Z.of_int64 (Tez.to_mutez v)), ctxt) -let unparse_key ctxt mode k = +let unparse_key ~loc ctxt mode k = match mode with | Optimized | Optimized_legacy -> Gas.consume ctxt Unparse_costs.public_key_optimized >|? fun ctxt -> let bytes = Data_encoding.Binary.to_bytes_exn Signature.Public_key.encoding k in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) | Readable -> Gas.consume ctxt Unparse_costs.public_key_readable >|? fun ctxt -> - (String (-1, Signature.Public_key.to_b58check k), ctxt) + (String (loc, Signature.Public_key.to_b58check k), ctxt) -let unparse_key_hash ctxt mode k = +let unparse_key_hash ~loc ctxt mode k = match mode with | Optimized | Optimized_legacy -> Gas.consume ctxt Unparse_costs.key_hash_optimized >|? fun ctxt -> let bytes = Data_encoding.Binary.to_bytes_exn Signature.Public_key_hash.encoding k in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) | Readable -> Gas.consume ctxt Unparse_costs.key_hash_readable >|? fun ctxt -> - (String (-1, Signature.Public_key_hash.to_b58check k), ctxt) + (String (loc, Signature.Public_key_hash.to_b58check k), ctxt) -let unparse_operation ctxt (op, _big_map_diff) = +let unparse_operation ~loc ctxt (op, _big_map_diff) = let bytes = Data_encoding.Binary.to_bytes_exn Operation.internal_operation_encoding op in Gas.consume ctxt (Unparse_costs.operation bytes) >|? fun ctxt -> - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) -let unparse_chain_id ctxt mode chain_id = +let unparse_chain_id ~loc ctxt mode chain_id = match mode with | Optimized | Optimized_legacy -> Gas.consume ctxt Unparse_costs.chain_id_optimized >|? fun ctxt -> let bytes = Data_encoding.Binary.to_bytes_exn Chain_id.encoding chain_id in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) | Readable -> Gas.consume ctxt Unparse_costs.chain_id_readable >|? fun ctxt -> - (String (-1, Chain_id.to_b58check chain_id), ctxt) + (String (loc, Chain_id.to_b58check chain_id), ctxt) -let unparse_bls12_381_g1 ctxt x = +let unparse_bls12_381_g1 ~loc ctxt x = Gas.consume ctxt Unparse_costs.bls12_381_g1 >|? fun ctxt -> let bytes = Bls12_381.G1.to_bytes x in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) -let unparse_bls12_381_g2 ctxt x = +let unparse_bls12_381_g2 ~loc ctxt x = Gas.consume ctxt Unparse_costs.bls12_381_g2 >|? fun ctxt -> let bytes = Bls12_381.G2.to_bytes x in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) -let unparse_bls12_381_fr ctxt x = +let unparse_bls12_381_fr ~loc ctxt x = Gas.consume ctxt Unparse_costs.bls12_381_fr >|? fun ctxt -> let bytes = Bls12_381.Fr.to_bytes x in - (Bytes (-1, bytes), ctxt) + (Bytes (loc, bytes), ctxt) -let unparse_with_data_encoding ctxt s unparse_cost encoding = +let unparse_with_data_encoding ~loc ctxt s unparse_cost encoding = Lwt.return ( Gas.consume ctxt unparse_cost >|? fun ctxt -> let bytes = Data_encoding.Binary.to_bytes_exn encoding s in - (Bytes (-1, bytes), ctxt) ) + (Bytes (loc, bytes), ctxt) ) (* -- Unparsing data of complex types -- *) @@ -575,7 +589,7 @@ type ('ty, 'depth) comb_witness = | Comb_Pair : ('t, 'd) comb_witness -> (_ * 't, unit -> 'd) comb_witness | Comb_Any : (_, _) comb_witness -let unparse_pair (type r) unparse_l unparse_r ctxt mode +let unparse_pair (type r) ~loc unparse_l unparse_r ctxt mode (r_comb_witness : (r, unit -> unit -> _) comb_witness) (l, (r : r)) = unparse_l ctxt l >>=? fun (l, ctxt) -> unparse_r ctxt r >|=? fun (r, ctxt) -> @@ -594,35 +608,35 @@ let unparse_pair (type r) unparse_l unparse_r ctxt mode match (mode, r_comb_witness, r) with | (Optimized, Comb_Pair _, Micheline.Seq (_, r)) -> (* Optimized case n > 4 *) - Micheline.Seq (-1, l :: r) + Micheline.Seq (loc, l :: r) | ( Optimized, Comb_Pair (Comb_Pair _), Prim (_, D_Pair, [x2; Prim (_, D_Pair, [x3; x4], [])], []) ) -> (* Optimized case n = 4 *) - Micheline.Seq (-1, [l; x2; x3; x4]) + Micheline.Seq (loc, [l; x2; x3; x4]) | (Readable, Comb_Pair _, Prim (_, D_Pair, xs, [])) -> (* Readable case n > 2 *) - Prim (-1, D_Pair, l :: xs, []) + Prim (loc, D_Pair, l :: xs, []) | _ -> (* The remaining cases are: - Optimized n = 2, - Optimized n = 3, and - Readable n = 2, - Optimized_legacy, any n *) - Prim (-1, D_Pair, [l; r], []) + Prim (loc, D_Pair, [l; r], []) in (res, ctxt) -let unparse_union unparse_l unparse_r ctxt = function +let unparse_union ~loc unparse_l unparse_r ctxt = function | L l -> - unparse_l ctxt l >|=? fun (l, ctxt) -> (Prim (-1, D_Left, [l], []), ctxt) + unparse_l ctxt l >|=? fun (l, ctxt) -> (Prim (loc, D_Left, [l], []), ctxt) | R r -> - unparse_r ctxt r >|=? fun (r, ctxt) -> (Prim (-1, D_Right, [r], []), ctxt) + unparse_r ctxt r >|=? fun (r, ctxt) -> (Prim (loc, D_Right, [r], []), ctxt) -let unparse_option unparse_v ctxt = function +let unparse_option ~loc unparse_v ctxt = function | Some v -> - unparse_v ctxt v >|=? fun (v, ctxt) -> (Prim (-1, D_Some, [v], []), ctxt) - | None -> return (Prim (-1, D_None, [], []), ctxt) + unparse_v ctxt v >|=? fun (v, ctxt) -> (Prim (loc, D_Some, [v], []), ctxt) + | None -> return (Prim (loc, D_None, [], []), ctxt) (* -- Unparsing data of comparable types -- *) @@ -633,13 +647,14 @@ let comparable_comb_witness2 : | _ -> Comb_Any let[@coq_axiom_with_reason "gadt"] rec unparse_comparable_data : - type a. + type a loc. + loc:loc -> context -> unparsing_mode -> a comparable_ty -> a -> - (Script.node * context) tzresult Lwt.t = - fun ctxt mode ty a -> + (loc Script.michelson_node * context) tzresult Lwt.t = + fun ~loc ctxt mode ty a -> (* No need for stack_depth here. Unlike [unparse_data], [unparse_comparable_data] doesn't call [unparse_code]. The stack depth is bounded by the type depth, currently bounded @@ -650,32 +665,33 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_comparable_data : >>?= fun ctxt -> match (ty, a) with - | (Unit_key _, v) -> Lwt.return @@ unparse_unit ctxt v - | (Int_key _, v) -> Lwt.return @@ unparse_int ctxt v - | (Nat_key _, v) -> Lwt.return @@ unparse_nat ctxt v - | (String_key _, s) -> Lwt.return @@ unparse_string ctxt s - | (Bytes_key _, s) -> Lwt.return @@ unparse_bytes ctxt s - | (Bool_key _, b) -> Lwt.return @@ unparse_bool ctxt b - | (Timestamp_key _, t) -> Lwt.return @@ unparse_timestamp ctxt mode t - | (Address_key _, address) -> Lwt.return @@ unparse_address ctxt mode address - | (Signature_key _, s) -> Lwt.return @@ unparse_signature ctxt mode s - | (Mutez_key _, v) -> Lwt.return @@ unparse_mutez ctxt v - | (Key_key _, k) -> Lwt.return @@ unparse_key ctxt mode k - | (Key_hash_key _, k) -> Lwt.return @@ unparse_key_hash ctxt mode k + | (Unit_key _, v) -> Lwt.return @@ unparse_unit ~loc ctxt v + | (Int_key _, v) -> Lwt.return @@ unparse_int ~loc ctxt v + | (Nat_key _, v) -> Lwt.return @@ unparse_nat ~loc ctxt v + | (String_key _, s) -> Lwt.return @@ unparse_string ~loc ctxt s + | (Bytes_key _, s) -> Lwt.return @@ unparse_bytes ~loc ctxt s + | (Bool_key _, b) -> Lwt.return @@ unparse_bool ~loc ctxt b + | (Timestamp_key _, t) -> Lwt.return @@ unparse_timestamp ~loc ctxt mode t + | (Address_key _, address) -> + Lwt.return @@ unparse_address ~loc ctxt mode address + | (Signature_key _, s) -> Lwt.return @@ unparse_signature ~loc ctxt mode s + | (Mutez_key _, v) -> Lwt.return @@ unparse_mutez ~loc ctxt v + | (Key_key _, k) -> Lwt.return @@ unparse_key ~loc ctxt mode k + | (Key_hash_key _, k) -> Lwt.return @@ unparse_key_hash ~loc ctxt mode k | (Chain_id_key _, chain_id) -> - Lwt.return @@ unparse_chain_id ctxt mode chain_id + Lwt.return @@ unparse_chain_id ~loc ctxt mode chain_id | (Pair_key ((tl, _), (tr, _), _), pair) -> let r_witness = comparable_comb_witness2 tr in - let unparse_l ctxt v = unparse_comparable_data ctxt mode tl v in - let unparse_r ctxt v = unparse_comparable_data ctxt mode tr v in - unparse_pair unparse_l unparse_r ctxt mode r_witness pair + let unparse_l ctxt v = unparse_comparable_data ~loc ctxt mode tl v in + let unparse_r ctxt v = unparse_comparable_data ~loc ctxt mode tr v in + unparse_pair ~loc unparse_l unparse_r ctxt mode r_witness pair | (Union_key ((tl, _), (tr, _), _), v) -> - let unparse_l ctxt v = unparse_comparable_data ctxt mode tl v in - let unparse_r ctxt v = unparse_comparable_data ctxt mode tr v in - unparse_union unparse_l unparse_r ctxt v + let unparse_l ctxt v = unparse_comparable_data ~loc ctxt mode tl v in + let unparse_r ctxt v = unparse_comparable_data ~loc ctxt mode tr v in + unparse_union ~loc unparse_l unparse_r ctxt v | (Option_key (t, _), v) -> - let unparse_v ctxt v = unparse_comparable_data ctxt mode t v in - unparse_option unparse_v ctxt v + let unparse_v ctxt v = unparse_comparable_data ~loc ctxt mode t v in + unparse_option ~loc unparse_v ctxt v | (Never_key _, _) -> . let pack_node unparsed ctxt = @@ -690,8 +706,8 @@ let pack_node unparsed ctxt = (bytes, ctxt) let pack_comparable_data ctxt typ data ~mode = - unparse_comparable_data ctxt mode typ data >>=? fun (unparsed, ctxt) -> - Lwt.return @@ pack_node unparsed ctxt + unparse_comparable_data ~loc:() ctxt mode typ data + >>=? fun (unparsed, ctxt) -> Lwt.return @@ pack_node unparsed ctxt let hash_bytes ctxt bytes = Gas.consume ctxt (Michelson_v1_gas.Cost_of.Interpreter.blake2b bytes) @@ -1219,7 +1235,7 @@ let merge_branches : type a s b u c v. legacy:bool -> context -> - int -> + Script.location -> (a, s) judgement -> (b, u) judgement -> (a, s, b, u, c, v) branch -> @@ -1982,21 +1998,23 @@ let find_entrypoint (type full) (full : full ty) ~root_name entrypoint = | None -> false | Some (Field_annot l) -> Compare.String.(l = entrypoint) in + let loc = Micheline.dummy_location in let rec find_entrypoint : type t. t ty -> string -> ((Script.node -> Script.node) * ex_ty) option = fun t entrypoint -> match t with | Union_t ((tl, al), (tr, ar), _) -> ( if annot_is_entrypoint entrypoint al then - Some ((fun e -> Prim (0, D_Left, [e], [])), Ex_ty tl) + Some ((fun e -> Prim (loc, D_Left, [e], [])), Ex_ty tl) else if annot_is_entrypoint entrypoint ar then - Some ((fun e -> Prim (0, D_Right, [e], [])), Ex_ty tr) + Some ((fun e -> Prim (loc, D_Right, [e], [])), Ex_ty tr) else match find_entrypoint tl entrypoint with - | Some (f, t) -> Some ((fun e -> Prim (0, D_Left, [f e], [])), t) + | Some (f, t) -> Some ((fun e -> Prim (loc, D_Left, [f e], [])), t) | None -> ( match find_entrypoint tr entrypoint with - | Some (f, t) -> Some ((fun e -> Prim (0, D_Right, [f e], [])), t) + | Some (f, t) -> + Some ((fun e -> Prim (loc, D_Right, [f e], [])), t) | None -> None)) | _ -> None in @@ -4031,7 +4049,7 @@ and[@coq_axiom_with_reason "gadt"] parse_instr : tc_context ctxt ~legacy - (Seq (-1, tl)) + (Seq (Micheline.dummy_location, tl)) middle >|=? fun (judgement, ctxt) -> let judgement = @@ -5865,7 +5883,7 @@ let list_entrypoints (type full) (full : full ty) ctxt ~root_name = else if Entrypoints_map.mem name all then ok (List.rev path :: unreachables, all) else - unparse_ty ctxt ty >>? fun (unparsed_ty, _) -> + unparse_ty ~loc:() ctxt ty >>? fun (unparsed_ty, _) -> ok ( unreachables, Entrypoints_map.add name (List.rev path, unparsed_ty) all ) @@ -5875,8 +5893,11 @@ let list_entrypoints (type full) (full : full ty) ctxt ~root_name = t ty -> prim list -> bool -> - prim list list * (prim list * Script.node) Entrypoints_map.t -> - (prim list list * (prim list * Script.node) Entrypoints_map.t) tzresult = + prim list list + * (prim list * Script.unlocated_michelson_node) Entrypoints_map.t -> + (prim list list + * (prim list * Script.unlocated_michelson_node) Entrypoints_map.t) + tzresult = fun t path reachable acc -> match t with | Union_t ((tl, al), (tr, ar), _) -> @@ -5895,7 +5916,7 @@ let list_entrypoints (type full) (full : full ty) ctxt ~root_name = acc | _ -> ok acc in - unparse_ty ctxt full >>? fun (unparsed_full, _) -> + unparse_ty ~loc:() ctxt full >>? fun (unparsed_full, _) -> let (init, reachable) = match root_name with | None | Some (Field_annot "") -> (Entrypoints_map.empty, false) @@ -5930,39 +5951,42 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : fail Unparsing_too_many_recursive_calls else unparse_data ctxt ~stack_depth:(stack_depth + 1) mode ty a in + let loc = Micheline.dummy_location in match (ty, a) with - | (Unit_t _, v) -> Lwt.return @@ unparse_unit ctxt v - | (Int_t _, v) -> Lwt.return @@ unparse_int ctxt v - | (Nat_t _, v) -> Lwt.return @@ unparse_nat ctxt v - | (String_t _, s) -> Lwt.return @@ unparse_string ctxt s - | (Bytes_t _, s) -> Lwt.return @@ unparse_bytes ctxt s - | (Bool_t _, b) -> Lwt.return @@ unparse_bool ctxt b - | (Timestamp_t _, t) -> Lwt.return @@ unparse_timestamp ctxt mode t - | (Address_t _, address) -> Lwt.return @@ unparse_address ctxt mode address + | (Unit_t _, v) -> Lwt.return @@ unparse_unit ~loc ctxt v + | (Int_t _, v) -> Lwt.return @@ unparse_int ~loc ctxt v + | (Nat_t _, v) -> Lwt.return @@ unparse_nat ~loc ctxt v + | (String_t _, s) -> Lwt.return @@ unparse_string ~loc ctxt s + | (Bytes_t _, s) -> Lwt.return @@ unparse_bytes ~loc ctxt s + | (Bool_t _, b) -> Lwt.return @@ unparse_bool ~loc ctxt b + | (Timestamp_t _, t) -> Lwt.return @@ unparse_timestamp ~loc ctxt mode t + | (Address_t _, address) -> + Lwt.return @@ unparse_address ~loc ctxt mode address | (Contract_t _, contract) -> - Lwt.return @@ unparse_contract ctxt mode contract - | (Signature_t _, s) -> Lwt.return @@ unparse_signature ctxt mode s - | (Mutez_t _, v) -> Lwt.return @@ unparse_mutez ctxt v - | (Key_t _, k) -> Lwt.return @@ unparse_key ctxt mode k - | (Key_hash_t _, k) -> Lwt.return @@ unparse_key_hash ctxt mode k - | (Operation_t _, operation) -> Lwt.return @@ unparse_operation ctxt operation + Lwt.return @@ unparse_contract ~loc ctxt mode contract + | (Signature_t _, s) -> Lwt.return @@ unparse_signature ~loc ctxt mode s + | (Mutez_t _, v) -> Lwt.return @@ unparse_mutez ~loc ctxt v + | (Key_t _, k) -> Lwt.return @@ unparse_key ~loc ctxt mode k + | (Key_hash_t _, k) -> Lwt.return @@ unparse_key_hash ~loc ctxt mode k + | (Operation_t _, operation) -> + Lwt.return @@ unparse_operation ~loc ctxt operation | (Chain_id_t _, chain_id) -> - Lwt.return @@ unparse_chain_id ctxt mode chain_id - | (Bls12_381_g1_t _, x) -> Lwt.return @@ unparse_bls12_381_g1 ctxt x - | (Bls12_381_g2_t _, x) -> Lwt.return @@ unparse_bls12_381_g2 ctxt x - | (Bls12_381_fr_t _, x) -> Lwt.return @@ unparse_bls12_381_fr ctxt x + Lwt.return @@ unparse_chain_id ~loc ctxt mode chain_id + | (Bls12_381_g1_t _, x) -> Lwt.return @@ unparse_bls12_381_g1 ~loc ctxt x + | (Bls12_381_g2_t _, x) -> Lwt.return @@ unparse_bls12_381_g2 ~loc ctxt x + | (Bls12_381_fr_t _, x) -> Lwt.return @@ unparse_bls12_381_fr ~loc ctxt x | (Pair_t ((tl, _, _), (tr, _, _), _), pair) -> let r_witness = comb_witness2 tr in let unparse_l ctxt v = non_terminal_recursion ctxt mode tl v in let unparse_r ctxt v = non_terminal_recursion ctxt mode tr v in - unparse_pair unparse_l unparse_r ctxt mode r_witness pair + unparse_pair ~loc unparse_l unparse_r ctxt mode r_witness pair | (Union_t ((tl, _), (tr, _), _), v) -> let unparse_l ctxt v = non_terminal_recursion ctxt mode tl v in let unparse_r ctxt v = non_terminal_recursion ctxt mode tr v in - unparse_union unparse_l unparse_r ctxt v + unparse_union ~loc unparse_l unparse_r ctxt v | (Option_t (t, _), v) -> let unparse_v ctxt v = non_terminal_recursion ctxt mode t v in - unparse_option unparse_v ctxt v + unparse_option ~loc unparse_v ctxt v | (List_t (t, _), items) -> List.fold_left_es (fun (l, ctxt) element -> @@ -5970,12 +5994,10 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : >|=? fun (unparsed, ctxt) -> (unparsed :: l, ctxt)) ([], ctxt) items.elements - >|=? fun (items, ctxt) -> (Micheline.Seq (-1, List.rev items), ctxt) + >|=? fun (items, ctxt) -> (Micheline.Seq (loc, List.rev items), ctxt) | (Ticket_t (t, _), {ticketer; contents; amount}) -> - (let fake_loc = -1 in - (* ideally we would like to allow a little overhead here because it is only used for unparsing *) - opened_ticket_type fake_loc t) - >>?= fun opened_ticket_ty -> + (* ideally we would like to allow a little overhead here because it is only used for unparsing *) + opened_ticket_type loc t >>?= fun opened_ticket_ty -> let t = ty_of_comparable_ty opened_ticket_ty in (unparse_data [@tailcall]) ctxt @@ -5986,18 +6008,18 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : | (Set_t (t, _), set) -> List.fold_left_es (fun (l, ctxt) item -> - unparse_comparable_data ctxt mode t item >|=? fun (item, ctxt) -> + unparse_comparable_data ~loc ctxt mode t item >|=? fun (item, ctxt) -> (item :: l, ctxt)) ([], ctxt) (Script_set.fold (fun e acc -> e :: acc) set []) - >|=? fun (items, ctxt) -> (Micheline.Seq (-1, items), ctxt) + >|=? fun (items, ctxt) -> (Micheline.Seq (loc, items), ctxt) | (Map_t (kt, vt, _), map) -> let items = Script_map.fold (fun k v acc -> (k, v) :: acc) map [] in unparse_items ctxt ~stack_depth:(stack_depth + 1) mode kt vt items - >|=? fun (items, ctxt) -> (Micheline.Seq (-1, items), ctxt) + >|=? fun (items, ctxt) -> (Micheline.Seq (loc, items), ctxt) | (Big_map_t (_kt, _vt, _), {id = Some id; diff = {size; _}; _}) when Compare.Int.( = ) size 0 -> - return (Micheline.Int (-1, Big_map.Id.unparse_to_z id), ctxt) + return (Micheline.Int (loc, Big_map.Id.unparse_to_z id), ctxt) | (Big_map_t (kt, vt, _), {id = Some id; diff = {map; _}; _}) -> let items = Big_map_overlay.fold (fun _ (k, v) acc -> (k, v) :: acc) map [] @@ -6014,13 +6036,13 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : in (* this can't fail if the original type is well-formed because [option vt] is always strictly smaller than [big_map kt vt] *) - option_t (-1) vt ~annot:None >>?= fun vt -> + option_t loc vt ~annot:None >>?= fun vt -> unparse_items ctxt ~stack_depth:(stack_depth + 1) mode kt vt items >|=? fun (items, ctxt) -> ( Micheline.Prim - ( -1, + ( loc, D_Pair, - [Int (-1, Big_map.Id.unparse_to_z id); Seq (-1, items)], + [Int (loc, Big_map.Id.unparse_to_z id); Seq (loc, items)], [] ), ctxt ) | (Big_map_t (kt, vt, _), {id = None; diff = {map; _}; _}) -> @@ -6038,7 +6060,7 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : items in unparse_items ctxt ~stack_depth:(stack_depth + 1) mode kt vt items - >|=? fun (items, ctxt) -> (Micheline.Seq (-1, items), ctxt) + >|=? fun (items, ctxt) -> (Micheline.Seq (loc, items), ctxt) | (Lambda_t _, Lam (_, original_code)) -> unparse_code ctxt ~stack_depth:(stack_depth + 1) mode original_code | (Never_t _, _) -> . @@ -6048,37 +6070,39 @@ let[@coq_axiom_with_reason "gadt"] rec unparse_data : let bytes = Data_encoding.Binary.to_bytes_exn Sapling.transaction_encoding s in - (Bytes (-1, bytes), ctxt) ) + (Bytes (loc, bytes), ctxt) ) | (Sapling_state_t _, {id; diff; _}) -> Lwt.return ( Gas.consume ctxt (Unparse_costs.sapling_diff diff) >|? fun ctxt -> ( (match diff with | {commitments_and_ciphertexts = []; nullifiers = []} -> ( match id with - | None -> Micheline.Seq (-1, []) + | None -> Micheline.Seq (loc, []) | Some id -> let id = Sapling.Id.unparse_to_z id in - Micheline.Int (-1, id)) + Micheline.Int (loc, id)) | diff -> ( let diff_bytes = Data_encoding.Binary.to_bytes_exn Sapling.diff_encoding diff in - let unparsed_diff = Bytes (-1, diff_bytes) in + let unparsed_diff = Bytes (loc, diff_bytes) in match id with | None -> unparsed_diff | Some id -> let id = Sapling.Id.unparse_to_z id in Micheline.Prim - (-1, D_Pair, [Int (-1, id); unparsed_diff], []))), + (loc, D_Pair, [Int (loc, id); unparsed_diff], []))), ctxt ) ) | (Chest_key_t _, s) -> unparse_with_data_encoding + ~loc ctxt s Unparse_costs.chest_key Timelock.chest_key_encoding | (Chest_t _, s) -> unparse_with_data_encoding + ~loc ctxt s (Unparse_costs.chest ~plaintext_size:(Timelock.get_plaintext_size s)) @@ -6096,9 +6120,10 @@ and unparse_items : fun ctxt ~stack_depth mode kt vt items -> List.fold_left_es (fun (l, ctxt) (k, v) -> - unparse_comparable_data ctxt mode kt k >>=? fun (key, ctxt) -> + let loc = Micheline.dummy_location in + unparse_comparable_data ~loc ctxt mode kt k >>=? fun (key, ctxt) -> unparse_data ctxt ~stack_depth:(stack_depth + 1) mode vt v - >|=? fun (value, ctxt) -> (Prim (-1, D_Elt, [key; value], []) :: l, ctxt)) + >|=? fun (value, ctxt) -> (Prim (loc, D_Elt, [key; value], []) :: l, ctxt)) ([], ctxt) items @@ -6162,45 +6187,46 @@ let unparse_script ctxt mode unparse_data ctxt ~stack_depth:0 mode storage_type storage >>=? fun (storage, ctxt) -> Lwt.return - ( unparse_ty ctxt arg_type >>? fun (arg_type, ctxt) -> - unparse_ty ctxt storage_type >>? fun (storage_type, ctxt) -> - let arg_type = add_field_annot root_name None arg_type in - let open Micheline in - let view name {input_ty; output_ty; view_code} views = - Prim - ( -1, - K_view, - [ - String (-1, Script_string.to_string name); - input_ty; - output_ty; - view_code; - ], - [] ) - :: views - in - let views = SMap.fold view views [] |> List.rev in - let code = - Seq - ( -1, - [ - Prim (-1, K_parameter, [arg_type], []); - Prim (-1, K_storage, [storage_type], []); - Prim (-1, K_code, [code], []); - ] - @ views ) - in - Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> - Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> - Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> - Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> - Gas.consume ctxt (Script.strip_locations_cost code) >>? fun ctxt -> - Gas.consume ctxt (Script.strip_locations_cost storage) >|? fun ctxt -> - ( { - code = lazy_expr (strip_locations code); - storage = lazy_expr (strip_locations storage); - }, - ctxt ) ) + (let loc = Micheline.dummy_location in + unparse_ty ~loc ctxt arg_type >>? fun (arg_type, ctxt) -> + unparse_ty ~loc ctxt storage_type >>? fun (storage_type, ctxt) -> + let arg_type = add_field_annot root_name None arg_type in + let open Micheline in + let view name {input_ty; output_ty; view_code} views = + Prim + ( loc, + K_view, + [ + String (loc, Script_string.to_string name); + input_ty; + output_ty; + view_code; + ], + [] ) + :: views + in + let views = SMap.fold view views [] |> List.rev in + let code = + Seq + ( loc, + [ + Prim (loc, K_parameter, [arg_type], []); + Prim (loc, K_storage, [storage_type], []); + Prim (loc, K_code, [code], []); + ] + @ views ) + in + Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> + Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> + Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> + Gas.consume ctxt Unparse_costs.unparse_instr_cycle >>? fun ctxt -> + Gas.consume ctxt (Script.strip_locations_cost code) >>? fun ctxt -> + Gas.consume ctxt (Script.strip_locations_cost storage) >|? fun ctxt -> + ( { + code = lazy_expr (strip_locations code); + storage = lazy_expr (strip_locations storage); + }, + ctxt )) let pack_data_with_mode ctxt typ data ~mode = unparse_data ~stack_depth:0 ctxt mode typ data >>=? fun (unparsed, ctxt) -> @@ -6302,9 +6328,9 @@ let diff_of_big_map ctxt mode ~temporary ~ids_to_copy | None -> Big_map.fresh ~temporary ctxt >>=? fun (ctxt, id) -> Lwt.return - (let kt = unparse_comparable_ty_uncarbonated key_type in + (let kt = unparse_comparable_ty_uncarbonated ~loc:() key_type in Gas.consume ctxt (Script.strip_locations_cost kt) >>? fun ctxt -> - unparse_ty ctxt value_type >>? fun (kv, ctxt) -> + unparse_ty ~loc:() ctxt value_type >>? fun (kv, ctxt) -> Gas.consume ctxt (Script.strip_locations_cost kv) >|? fun ctxt -> let key_type = Micheline.strip_locations kt in let value_type = Micheline.strip_locations kv in @@ -6319,7 +6345,7 @@ let diff_of_big_map ctxt mode ~temporary ~ids_to_copy List.fold_left_es (fun (acc, ctxt) (key_hash, key, value) -> Gas.consume ctxt Typecheck_costs.parse_instr_cycle >>?= fun ctxt -> - unparse_comparable_data ctxt mode key_type key + unparse_comparable_data ~loc:() ctxt mode key_type key >>=? fun (key_node, ctxt) -> Gas.consume ctxt (Script.strip_locations_cost key_node) >>?= fun ctxt -> let key = Micheline.strip_locations key_node in diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.mli b/src/proto_alpha/lib_protocol/script_ir_translator.mli index f89e77c0e2a8ca815d295d251b930ffe0d58d846..031ff5561bd15788184a3b35acdf3f40978640f3 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.mli +++ b/src/proto_alpha/lib_protocol/script_ir_translator.mli @@ -204,7 +204,7 @@ end (** {2 High-level Michelson Data Types} *) type type_logger = - int -> + Script.location -> (Script.expr * Script.annot) list -> (Script.expr * Script.annot) list -> unit @@ -289,11 +289,12 @@ val unparse_data : (Script.node * context) tzresult Lwt.t val unparse_comparable_data : + loc:'loc -> context -> unparsing_mode -> 'a Script_typed_ir.comparable_ty -> 'a -> - (Script.node * context) tzresult Lwt.t + ('loc Script.michelson_node * context) tzresult Lwt.t val unparse_code : context -> @@ -376,12 +377,16 @@ val parse_ty : (ex_ty * context) tzresult val unparse_ty : - context -> 'a Script_typed_ir.ty -> (Script.node * context) tzresult + loc:'loc -> + context -> + 'a Script_typed_ir.ty -> + ('loc Script.michelson_node * context) tzresult val unparse_comparable_ty : + loc:'loc -> context -> 'a Script_typed_ir.comparable_ty -> - (Script.node * context) tzresult + ('loc Script.michelson_node * context) tzresult val ty_of_comparable_ty : 'a Script_typed_ir.comparable_ty -> 'a Script_typed_ir.ty @@ -392,8 +397,8 @@ val parse_toplevel : val add_field_annot : Script_typed_ir.field_annot option -> Script_typed_ir.var_annot option -> - Script.node -> - Script.node + ('loc, 'prim) Micheline.node -> + ('loc, 'prim) Micheline.node val typecheck_code : legacy:bool -> context -> Script.expr -> (type_map * context) tzresult Lwt.t @@ -462,7 +467,8 @@ val list_entrypoints : context -> root_name:Script_typed_ir.field_annot option -> (Michelson_v1_primitives.prim list list - * (Michelson_v1_primitives.prim list * Script.node) Entrypoints_map.t) + * (Michelson_v1_primitives.prim list * Script.unlocated_michelson_node) + Entrypoints_map.t) tzresult val pack_data : diff --git a/src/proto_alpha/lib_protocol/script_repr.ml b/src/proto_alpha/lib_protocol/script_repr.ml index 2d5e7af3ea350716f8cf421df9e7ed34e171fe9d..83c98a2bbcf54a8df09e736a92761b80df1bc9fb 100644 --- a/src/proto_alpha/lib_protocol/script_repr.ml +++ b/src/proto_alpha/lib_protocol/script_repr.ml @@ -33,7 +33,12 @@ type expr = Michelson_v1_primitives.prim Micheline.canonical type lazy_expr = expr Data_encoding.lazy_t -type node = (location, Michelson_v1_primitives.prim) Micheline.node +type 'location michelson_node = + ('location, Michelson_v1_primitives.prim) Micheline.node + +type unlocated_michelson_node = unit michelson_node + +type node = location michelson_node let expr_encoding = Micheline.canonical_encoding diff --git a/src/proto_alpha/lib_protocol/script_repr.mli b/src/proto_alpha/lib_protocol/script_repr.mli index b41aa04cecd2cfe80c35bfa43f0e3e45efc33720..51560c8c99f2ce4b443fb793a790013d00405454 100644 --- a/src/proto_alpha/lib_protocol/script_repr.mli +++ b/src/proto_alpha/lib_protocol/script_repr.mli @@ -47,9 +47,14 @@ type error += Lazy_script_decode (* `Permanent *) computed on-demand. *) type lazy_expr = expr Data_encoding.lazy_t +type 'location michelson_node = + ('location, Michelson_v1_primitives.prim) Micheline.node + +type unlocated_michelson_node = unit michelson_node + (** Same as [expr], but used in different contexts, as required by Micheline's abstract interface. *) -type node = (location, Michelson_v1_primitives.prim) Micheline.node +type node = location michelson_node val location_encoding : location Data_encoding.t @@ -88,7 +93,7 @@ val is_unit_parameter : lazy_expr -> bool val strip_annotations : node -> node -val strip_locations_cost : node -> Gas_limit_repr.cost +val strip_locations_cost : _ michelson_node -> Gas_limit_repr.cost val strip_annotations_cost : node -> Gas_limit_repr.cost diff --git a/src/proto_alpha/lib_protocol/script_tc_errors.ml b/src/proto_alpha/lib_protocol/script_tc_errors.ml index 0b278768d5e97f99f3324cbce9a15afce246a88f..2fd81d50fb59e53fc496c924ec2413ff85442ebf 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors.ml @@ -32,7 +32,7 @@ type kind = Int_kind | String_kind | Bytes_kind | Prim_kind | Seq_kind type unparsed_stack_ty = (Script.expr * Script.annot) list -type type_map = (int * (unparsed_stack_ty * unparsed_stack_ty)) list +type type_map = (Script.location * (unparsed_stack_ty * unparsed_stack_ty)) list (* Structure errors *) type error += Invalid_arity of Script.location * prim * int * int diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 8c11eda42830acb991fdf754666ff4564cfc3f61..336715cea48fad19224f393929a738925f3bb2e3 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -448,26 +448,29 @@ let dummy_script = lazy_expr (strip_locations (Seq - ( 0, + ( (), [ - Prim (0, K_parameter, [Prim (0, T_unit, [], [])], []); - Prim (0, K_storage, [Prim (0, T_unit, [], [])], []); + Prim ((), K_parameter, [Prim ((), T_unit, [], [])], []); + Prim ((), K_storage, [Prim ((), T_unit, [], [])], []); Prim - ( 0, + ( (), K_code, [ Seq - ( 0, + ( (), [ - Prim (0, I_CDR, [], []); + Prim ((), I_CDR, [], []); Prim - (0, I_NIL, [Prim (0, T_operation, [], [])], []); - Prim (0, I_PAIR, [], []); + ( (), + I_NIL, + [Prim ((), T_operation, [], [])], + [] ); + Prim ((), I_PAIR, [], []); ] ); ], [] ); ] ))); - storage = lazy_expr (strip_locations (Prim (0, D_Unit, [], []))); + storage = lazy_expr (strip_locations (Prim ((), D_Unit, [], []))); } let dummy_script_cost = Test_tez.of_mutez_exn 9_500L diff --git a/src/proto_alpha/lib_protocol/test/helpers/test_global_constants.ml b/src/proto_alpha/lib_protocol/test/helpers/test_global_constants.ml index be30b33afa8762035c4eb9ec28bbc02fd110a796..1e98e513b7d3ada4e7ab66a22caa3e86300d88ed 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/test_global_constants.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/test_global_constants.ml @@ -252,7 +252,7 @@ module Generators = struct () let rec replace_with_constant : - Script.node -> int -> Script.node * Script.node option = + Script.node -> Script.location -> Script.node * Script.node option = fun node loc -> let open Michelson_v1_primitives in let open Micheline in diff --git a/src/proto_alpha/lib_protocol/test/test_script_comparison.ml b/src/proto_alpha/lib_protocol/test/test_script_comparison.ml index 97d4083450c1e70464544f84ce540c62b933a927..0883396d00e64bfead71926e662f61348001b335 100644 --- a/src/proto_alpha/lib_protocol/test/test_script_comparison.ml +++ b/src/proto_alpha/lib_protocol/test/test_script_comparison.ml @@ -205,7 +205,8 @@ let unparse_comparable_ty ty = Micheline.strip_locations (fst (assert_ok - Script_ir_translator.(unparse_ty ctxt (ty_of_comparable_ty ty)))) + Script_ir_translator.( + unparse_ty ~loc:() ctxt (ty_of_comparable_ty ty)))) let unparse_comparable_data ty x = Micheline.strip_locations diff --git a/src/proto_alpha/lib_protocol/test/test_script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/test/test_script_typed_ir_size.ml index 88a8e5fac0846aa7ab2a7f6b77a500fc6fea264b..a92a08c9db3f71ad3fa71e20100d5414b2fbcf5d 100644 --- a/src/proto_alpha/lib_protocol/test/test_script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/test/test_script_typed_ir_size.ml @@ -168,7 +168,7 @@ module Printers = struct string_of_something @@ fun ctxt -> Lwt.return @@ Script_ir_translator.( - unparse_ty ctxt ty >>? fun (node, _) -> + unparse_ty ~loc:() ctxt ty >>? fun (node, _) -> Ok (Micheline.strip_locations node)) let string_of_code code = string_of_something @@ fun _ -> return code diff --git a/src/proto_alpha/lib_protocol/test/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml index 012139f0b8d43999429e21f96cb179075395a06a..3c043cebc776a15eee918f71b419027650574ed9 100644 --- a/src/proto_alpha/lib_protocol/test/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/test_typechecking.ml @@ -73,7 +73,8 @@ let test_context_with_nat_nat_big_map () = let ctxt = Incremental.alpha_ctxt v in wrap_error_lwt @@ Big_map.fresh ~temporary:false ctxt >>=? fun (ctxt, id) -> let nat_ty = Script_typed_ir.nat_t ~annot:None in - wrap_error_lwt @@ Lwt.return @@ Script_ir_translator.unparse_ty ctxt nat_ty + wrap_error_lwt @@ Lwt.return + @@ Script_ir_translator.unparse_ty ~loc:() ctxt nat_ty >>=? fun (nat_ty_node, ctxt) -> let nat_ty_expr = Micheline.strip_locations nat_ty_node in let alloc = Big_map.{key_type = nat_ty_expr; value_type = nat_ty_expr} in @@ -308,19 +309,19 @@ let test_parse_comb_type () = let test_unparse_ty loc ctxt expected ty = Environment.wrap_tzresult - ( Script_ir_translator.unparse_ty ctxt ty >>? fun (actual, ctxt) -> + ( Script_ir_translator.unparse_ty ~loc:() ctxt ty >>? fun (actual, ctxt) -> if actual = expected then ok ctxt else Alcotest.failf "Unexpected error: %s" loc ) let test_unparse_comb_type () = let open Script in let open Script_typed_ir in - let nat_prim = Prim (-1, T_nat, [], []) in - let nat_prim_a = Prim (-1, T_nat, [], ["%a"]) in - let nat_prim_b = Prim (-1, T_nat, [], ["%b"]) in - let nat_prim_c = Prim (-1, T_nat, [], ["%c"]) in + let nat_prim = Prim ((), T_nat, [], []) in + let nat_prim_a = Prim ((), T_nat, [], ["%a"]) in + let nat_prim_b = Prim ((), T_nat, [], ["%b"]) in + let nat_prim_c = Prim ((), T_nat, [], ["%c"]) in let nat_ty = nat_t ~annot:None in - let pair_prim l = Prim (-1, T_pair, l, []) in + let pair_prim l = Prim ((), T_pair, l, []) in let pair_ty ty1 ty2 = pair_t (-1) (ty1, None, None) (ty2, None, None) ~annot:None in @@ -417,7 +418,7 @@ let test_unparse_comb_type () = test_unparse_ty __LOC__ ctxt - (pair_prim2 nat_prim_a (Prim (-1, T_pair, [nat_prim; nat_prim], ["%b"]))) + (pair_prim2 nat_prim_a (Prim ((), T_pair, [nat_prim; nat_prim], ["%b"]))) pair_nat_a_pair_b_nat_nat_ty >>?= fun ctxt -> (* pair nat (pair @b nat nat) *) @@ -430,7 +431,7 @@ let test_unparse_comb_type () = test_unparse_ty __LOC__ ctxt - (pair_prim2 nat_prim (Prim (-1, T_pair, [nat_prim; nat_prim], ["@b"]))) + (pair_prim2 nat_prim (Prim ((), T_pair, [nat_prim; nat_prim], ["@b"]))) pair_nat_pair_b_nat_nat_ty >>?= fun ctxt -> (* pair nat (pair :b nat nat) *) @@ -445,7 +446,7 @@ let test_unparse_comb_type () = test_unparse_ty __LOC__ ctxt - (pair_prim2 nat_prim (Prim (-1, T_pair, [nat_prim; nat_prim], [":b"]))) + (pair_prim2 nat_prim (Prim ((), T_pair, [nat_prim; nat_prim], [":b"]))) pair_nat_pair_b_nat_nat_ty >>?= fun _ -> return_unit @@ -455,19 +456,20 @@ let test_unparse_comparable_ty loc ctxt expected ty = let open Script_typed_ir in Environment.wrap_tzresult ( set_t (-1) ty ~annot:None >>? fun set_ty_ty -> - Script_ir_translator.unparse_ty ctxt set_ty_ty >>? fun (actual, ctxt) -> - if actual = Prim (-1, T_set, [expected], []) then ok ctxt + Script_ir_translator.unparse_ty ~loc:() ctxt set_ty_ty + >>? fun (actual, ctxt) -> + if actual = Prim ((), T_set, [expected], []) then ok ctxt else Alcotest.failf "Unexpected error: %s" loc ) let test_unparse_comb_comparable_type () = let open Script in let open Script_typed_ir in - let nat_prim = Prim (-1, T_nat, [], []) in - let nat_prim_a = Prim (-1, T_nat, [], ["%a"]) in - let nat_prim_b = Prim (-1, T_nat, [], ["%b"]) in - let nat_prim_c = Prim (-1, T_nat, [], ["%c"]) in + let nat_prim = Prim ((), T_nat, [], []) in + let nat_prim_a = Prim ((), T_nat, [], ["%a"]) in + let nat_prim_b = Prim ((), T_nat, [], ["%b"]) in + let nat_prim_c = Prim ((), T_nat, [], ["%c"]) in let nat_ty = nat_key ~annot:None in - let pair_prim l = Prim (-1, T_pair, l, []) in + let pair_prim l = Prim ((), T_pair, l, []) in let pair_ty ty1 ty2 = pair_key (-1) (ty1, None) (ty2, None) ~annot:None in let pair_prim2 a b = pair_prim [a; b] in let pair_nat_nat_prim = pair_prim2 nat_prim nat_prim in @@ -552,7 +554,7 @@ let test_unparse_comb_comparable_type () = test_unparse_comparable_ty __LOC__ ctxt - (pair_prim2 nat_prim_a (Prim (-1, T_pair, [nat_prim; nat_prim], ["%b"]))) + (pair_prim2 nat_prim_a (Prim ((), T_pair, [nat_prim; nat_prim], ["%b"]))) pair_nat_a_pair_b_nat_nat_ty >>?= fun ctxt -> (* pair nat (pair :b nat nat) *) @@ -563,7 +565,7 @@ let test_unparse_comb_comparable_type () = test_unparse_comparable_ty __LOC__ ctxt - (pair_prim2 nat_prim (Prim (-1, T_pair, [nat_prim; nat_prim], [":b"]))) + (pair_prim2 nat_prim (Prim ((), T_pair, [nat_prim; nat_prim], [":b"]))) pair_nat_pair_b_nat_nat_ty >>?= fun _ -> return_unit @@ -811,7 +813,7 @@ let test_unparse_comb_data () = (* Generate all the possible syntaxes for pairs *) let gen_pairs left right = - [Prim (-1, Script.D_Pair, [left; right], []); Seq (-1, [left; right])] + [Prim ((), Script.D_Pair, [left; right], []); Seq ((), [left; right])] (* Generate all the possible syntaxes for combs *) let rec gen_combs leaf arity = @@ -832,7 +834,7 @@ let rec gen_combs leaf arity = let test_optimal_comb () = let open Script_typed_ir in let leaf_ty = nat_t ~annot:None in - let leaf_mich = Int (-1, Z.zero) in + let leaf_mich = Int ((), Z.zero) in let leaf_v = Script_int.zero_n in let size_of_micheline mich = let canonical = Micheline.strip_locations mich in diff --git a/src/proto_alpha/lib_protocol/test/unit/test_global_constants_storage.ml b/src/proto_alpha/lib_protocol/test/unit/test_global_constants_storage.ml index 19a96575d35b8337bcc6bd31bb041d94d5da32b0..454127b5e679e6edef7e05d3cbe20a9aeb76c40d 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_global_constants_storage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_global_constants_storage.ml @@ -101,7 +101,7 @@ let test_register_fails_with_unregistered_references_pbt = >>= assert_proto_error_id __LOC__ "Nonexistent_global") let rec grow n node = - match n with n when n <= 0 -> node | n -> grow (n - 1) (Seq (-1, [node])) + match n with n when n <= 0 -> node | n -> grow (n - 1) (Seq ((), [node])) (* Any expression with a depth that exceeds [Global_constants_storage.max_allowed_global_constant_depth] @@ -111,7 +111,7 @@ let test_register_fails_if_too_deep = let vdeep_expr = grow (Constants_repr.max_allowed_global_constant_depth + 1) - (Int (-1, Z.of_int 1)) + (Int ((), Z.of_int 1)) |> Micheline.strip_locations in create_context () >>=? fun context -> @@ -383,7 +383,7 @@ let test_expand_is_idempotent = given large values. *) let test_fold_does_not_stack_overflow = tztest "bottom_up_fold_cps: does not stack overflow" `Quick (fun () -> - let node = grow 1_000_000 @@ Int (-1, Z.zero) in + let node = grow 1_000_000 @@ Int ((), Z.zero) in return @@ ignore @@ Global_constants_storage.Internal_for_tests.bottom_up_fold_cps () diff --git a/src/proto_alpha/lib_protocol/ticket_balance_key.ml b/src/proto_alpha/lib_protocol/ticket_balance_key.ml index d55b8887992dd69b8fed51d7dae723410897f696..8546d3a221b89c4ae2b80e20a4396b6fa25b574b 100644 --- a/src/proto_alpha/lib_protocol/ticket_balance_key.ml +++ b/src/proto_alpha/lib_protocol/ticket_balance_key.ml @@ -35,7 +35,8 @@ open Alpha_context let ticket_balance_key_and_amount ctxt ~owner (Ticket_scanner.Ex_ticket (comp_ty, Script_typed_ir.{ticketer; contents; amount})) = - Script_ir_translator.unparse_comparable_ty ctxt comp_ty + let loc = Micheline.dummy_location in + Script_ir_translator.unparse_comparable_ty ~loc ctxt comp_ty >>?= fun (cont_ty_unstripped, ctxt) -> (* We strip the annotations from the content type in order to map tickets with the same content type, but with different annotations, to the @@ -53,6 +54,7 @@ let ticket_balance_key_and_amount ctxt ~owner ticketer_address >>=? fun (ticketer, ctxt) -> Script_ir_translator.unparse_comparable_data + ~loc ctxt Script_ir_translator.Optimized_legacy comp_ty diff --git a/src/proto_alpha/lib_protocol/ticket_storage.ml b/src/proto_alpha/lib_protocol/ticket_storage.ml index 4fad95fcd5d41faf1d7dbac6dd41fb6f6c83cfc8..9e97567d1708147004e9111741bb082e8729909f 100644 --- a/src/proto_alpha/lib_protocol/ticket_storage.ml +++ b/src/proto_alpha/lib_protocol/ticket_storage.ml @@ -49,7 +49,8 @@ let hash_of_node ctxt node = | None -> error Failed_to_hash_node let make_key_hash ctxt ~ticketer ~typ ~contents ~owner = - hash_of_node ctxt @@ Micheline.Seq (0, [ticketer; typ; contents; owner]) + hash_of_node ctxt + @@ Micheline.Seq (Micheline.dummy_location, [ticketer; typ; contents; owner]) let () = let open Data_encoding in