text
stringlengths
12
786k
let make_printable node = Micheline_printer . printable Michelson_v1_primitives . string_of_prim node
let pp_error_kind fmtr ( error_kind : error_kind ) = match error_kind with | Global_error { benchmark_name ; workload } -> Format . open_vbox 1 ; Format . fprintf fmtr " Global error , " :@ ; Format . fprintf fmtr " benchmark = % s , " @ benchmark_name ; Format . fprintf fmt...
let ( ) = Printexc . register_printer ( function | Translator_benchmark_error err -> Some ( Format . asprintf " % a " pp_error_kind err ) | _ -> None )
let global_error benchmark_name workload = raise ( Translator_benchmark_error ( Global_error { benchmark_name ; workload } ) )
let bad_data benchmark_name micheline expected_type phase = raise ( Translator_benchmark_error ( Bad_data { benchmark_name ; micheline ; expected_type ; phase } ) )
let bad_code benchmark_name micheline expected_stack_type phase = raise ( Translator_benchmark_error ( Bad_code { benchmark_name ; micheline ; expected_stack_type ; phase } ) )
module Typechecking_data : Benchmark . S = struct include Config include Default_boilerplate let models = make_models Translator_workload . Parsing Translator_workload . Data let name = " TYPECHECKING_DATA " let info = " Benchmarking typechecking of data " let typechecking_data_benchmark rng_state ( ...
let ( ) = Registration_helpers . register ( module Typechecking_data )
module Unparsing_data : Benchmark . S = struct include Config include Default_boilerplate let models = make_models Translator_workload . Unparsing Translator_workload . Data let name = " UNPARSING_DATA " let info = " Benchmarking unparsing of data " let unparsing_data_benchmark rng_state ( node : ...
let ( ) = Registration_helpers . register ( module Unparsing_data )
module Typechecking_code : Benchmark . S = struct include Config include Default_boilerplate let models = make_models Translator_workload . Parsing Translator_workload . Code let name = " TYPECHECKING_CODE " let info = " Benchmarking typechecking of code " let typechecking_code_benchmark rng_state ( ...
let ( ) = Registration_helpers . register ( module Typechecking_code )
module Unparsing_code : Benchmark . S = struct include Config include Default_boilerplate let models = make_models Translator_workload . Unparsing Translator_workload . Code let name = " UNPARSING_CODE " let info = " Benchmarking unparsing of code " let unparsing_code_benchmark rng_state ( node : ...
let ( ) = Registration_helpers . register ( module Unparsing_code )
let rec check_printable_ascii v i = if Compare . Int . ( i < 0 ) then true else match v . [ i ] with | ' \ n ' | ' \ x20 ' . . ' \ x7E ' -> check_printable_ascii v ( i - 1 ) | _ -> false
let check_printable_benchmark = let open Tezos_shell_benchmarks . Encoding_benchmarks_helpers in linear_shared ~ name " : CHECK_PRINTABLE " ~ generator ( : fun rng_state -> let open Base_samplers in let string = readable_ascii_string rng_state ~ size { : min = 1 ; max = 1024 } in ( string ,...
let ( ) = Registration_helpers . register check_printable_benchmark
module Merge_types : Benchmark . S = struct type config = { max_size : int } let config_encoding = let open Data_encoding in conv ( fun { max_size } -> max_size ) ( fun max_size -> { max_size } ) ( obj1 ( req " max_size " int31 ) ) let default_config = { max_size = 64 } t...
let ( ) = Registration_helpers . register ( module Merge_types )
let rec dummy_type_generator size = let open Script_ir_translator in let open Script_typed_ir in if size <= 1 then Ex_ty unit_t else match dummy_type_generator ( size - 2 ) with | Ex_ty r -> let l = unit_t in Ex_ty ( match pair_t ( - 1 ) l r with Error _ -> assert false | Ok t -> t )
let rec dummy_comparable_type_generator size = let open Script_ir_translator in let open Script_typed_ir in if size <= 0 then Ex_comparable_ty unit_key else match dummy_comparable_type_generator ( size - 2 ) with | Ex_comparable_ty r -> let l = unit_key in Ex_comparable_ty ( match pair_key ( - 1 ) l...
module Parse_type_shared = struct type config = { max_size : int } let default_config = { max_size = Constants_repr . michelson_maximum_type_size } let config_encoding = let open Data_encoding in conv ( fun { max_size } -> max_size ) ( fun max_size -> { max_size } ) ( obj1 ( req " ...
let parse_ty ctxt node = Script_ir_translator . parse_ty ctxt ~ legacy : true ~ allow_lazy_storage : true ~ allow_operation : true ~ allow_contract : true ~ allow_ticket : true node
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 let name = " PARSE_TYPE " let info = " Benchmarking parse_ty " let make_bench rng_state config ( ) = let open Error_monad in ( Lwt_main . run ( Execution_context . make ~ rng_state ) >>? fun ( ctxt , _ ) ...
let ( ) = Registration_helpers . register ( module Parse_type_benchmark )
module Unparse_type_benchmark : Benchmark . S = struct include Parse_type_shared let name = " UNPARSE_TYPE " let info = " Benchmarking unparse_ty " let make_bench rng_state config ( ) = let open Error_monad in ( Lwt_main . run ( Execution_context . make ~ rng_state ) >>? fun ( ctxt , ...
let ( ) = Registration_helpers . register ( module Unparse_type_benchmark )
module Unparse_comparable_type_benchmark : Benchmark . S = struct include Parse_type_shared let name = " UNPARSE_COMPARABLE_TYPE " let info = " Benchmarking unparse_comparable_ty " let make_bench rng_state config ( ) = let open Error_monad in let res = Lwt_main . run ( Execution_context . make...
let ( ) = Registration_helpers . register ( module Unparse_comparable_type_benchmark )
let gas_full t_kind code_or_data = let name = Format . asprintf " % a_ % a " Translator_workload . pp_kind t_kind Translator_workload . pp_code_or_data code_or_data in let intercept = Free_variable . of_string ( Format . asprintf " % s_const " name ) in let coeff = Free_variable . of_stri...
let size_full t_kind code_or_data = let name = Format . asprintf " % a_ % a " Translator_workload . pp_kind t_kind Translator_workload . pp_code_or_data code_or_data in let coeff1 = Free_variable . of_string ( Format . asprintf " % s_traversal " name ) in let coeff2 = Free_variable . of_s...
let gas_based_model t_kind code_or_data = Model . make ~ conv ( : function | Translator_workload . Typechecker_workload { consumed ; _ } -> ( consumed , ( ) ) ) ~ model ( : gas_full t_kind code_or_data )
let size_based_model t_kind code_or_data = Model . make ~ conv ( : function | Translator_workload . Typechecker_workload { micheline_size ; _ } -> ( match micheline_size with | { traversal ; int_bytes ; string_bytes } -> ( traversal , ( int_bytes , ( string_bytes , ( ) ) ...
type kind = Parsing | Unparsing
type code_or_data = Code | Data
type t = | Typechecker_workload of { t_kind : kind ; code_or_data : code_or_data ; micheline_size : Size . micheline_size ; consumed : Size . t ; }
let kind_encoding : kind Data_encoding . t = let open Data_encoding in def " kind_encoding " @@ string_enum [ ( " parsing " , Parsing ) ; ( " unparsing " , Unparsing ) ]
let code_or_data_encoding : code_or_data Data_encoding . t = let open Data_encoding in def " code_or_data_encoding " @@ string_enum [ ( " code " , Code ) ; ( " data " , Data ) ]
let encoding : t Data_encoding . t = let open Data_encoding in def " translator_trace_encoding " @@ conv ( function | Typechecker_workload { t_kind ; code_or_data ; micheline_size ; consumed } -> ( t_kind , code_or_data , micheline_size , consumed ) ) ( fun ( t_kind , code_or_da...
let pp_kind fmtr ( kind : kind ) = match kind with | Parsing -> Format . pp_print_string fmtr " Parsing " | Unparsing -> Format . pp_print_string fmtr " Unparsing "
let pp_code_or_data fmtr ( x : code_or_data ) = match x with | Code -> Format . pp_print_string fmtr " Code " | Data -> Format . pp_print_string fmtr " Data "
let pp fmtr ( trace : t ) = match trace with | Typechecker_workload { t_kind ; code_or_data ; micheline_size ; consumed } -> Format . fprintf fmtr " typechecker_trace { % a ; % a ; % a ; % a } " pp_kind t_kind pp_code_or_data code_or_data Size . pp_micheline_size micheline_size S...
let workload_to_sparse_vec ( trace : t ) = let ( name , { Size . traversal ; int_bytes ; string_bytes } , consumed ) = match trace with | Typechecker_workload { t_kind ; code_or_data ; micheline_size ; consumed } -> let name = Format . asprintf " % a_ % a " pp_kind t_kind p...
let data_typechecker_workload ctxt t_kind micheline_node ex_ty = let open Protocol in match ex_ty with | Script_ir_translator . Ex_ty ty -> let ctxt = Gas_helpers . set_limit ctxt in Lwt_main . run ( Script_ir_translator . parse_data ctxt ~ legacy : false ~ allow_forged : false ty micheline_node |> L...
let code_typechecker_workload ( ctxt : Protocol . Alpha_context . context ) ( t_kind : kind ) ( code : Protocol . Alpha_context . Script . node ) ( bef : Protocol . Script_ir_translator . ex_stack_ty ) = let open Protocol in let ctxt = Gas_helpers . set_limit ctxt in let ( Script...
let is_inline_attribute = function | { txt ( " = inline " " | ocaml . inline " ) } -> true | _ -> false
let is_inlined_attribute = function | { txt ( " = inlined " " | ocaml . inlined " ) } -> true | { txt ( " = unrolled " " | ocaml . unrolled " ) } when Config . flambda -> true | _ -> false
let is_specialise_attribute = function | { txt ( " = specialise " " | ocaml . specialise " ) } when Config . flambda -> true | _ -> false
let is_specialised_attribute = function | { txt ( " = specialised " " | ocaml . specialised " ) } when Config . flambda -> true | _ -> false
let is_local_attribute = function | { txt ( " = local " " | ocaml . local " ) } -> true | _ -> false
let find_attribute p attributes = let inline_attribute , other_attributes = List . partition ( fun a -> p a . Parsetree . attr_name ) attributes in let attr = match inline_attribute with | [ ] -> None | [ attr ] -> Some attr | _ :: { Parsetree . attr_name = { txt ; loc } ; _ ...
let is_unrolled = function | { txt " = unrolled " " | ocaml . unrolled " } -> true | { txt " = inline " " | ocaml . inline " " | inlined " " | ocaml . inlined " } -> false | _ -> assert false
let get_id_payload = let open Parsetree in function | PStr [ ] -> Some " " | PStr [ { pstr_desc = Pstr_eval ( { pexp_desc } , [ ] ) } ] -> begin match pexp_desc with | Pexp_ident { txt = Longident . Lident id } -> Some id | _ -> None end | _ -> None
let parse_id_payload txt loc ~ default ~ empty cases payload = let [ @ local ] warn ( ) = let ( %> ) f g x = g ( f x ) in let msg = cases |> List . map ( fst %> Printf . sprintf " ' % s ' " ) |> String . concat " , " |> Printf . sprintf " It must be either % s o...
let parse_inline_attribute attr = match attr with | None -> Default_inline | Some { Parsetree . attr_name = { txt ; loc } as id ; attr_payload = payload } -> let open Parsetree in if is_unrolled id then begin let warning txt = Warnings . Attribute_payload ( txt , " It must be an integer li...
let parse_specialise_attribute attr = match attr with | None -> Default_specialise | Some { Parsetree . attr_name = { txt ; loc } ; attr_payload = payload } -> parse_id_payload txt loc ~ default : Default_specialise ~ empty : Always_specialise [ " never " , Never_specialise ; " alwa...
let parse_local_attribute attr = match attr with | None -> Default_local | Some { Parsetree . attr_name = { txt ; loc } ; attr_payload = payload } -> parse_id_payload txt loc ~ default : Default_local ~ empty : Always_local [ " never " , Never_local ; " always " , Always_local ;...
let get_inline_attribute l = let attr , _ = find_attribute is_inline_attribute l in parse_inline_attribute attr
let get_specialise_attribute l = let attr , _ = find_attribute is_specialise_attribute l in parse_specialise_attribute attr
let get_local_attribute l = let attr , _ = find_attribute is_local_attribute l in parse_local_attribute attr
let check_local_inline loc attr = match attr . local , attr . inline with | Always_local , ( Always_inline | Unroll _ ) -> Location . prerr_warning loc ( Warnings . Duplicated_attribute " local / inline " ) | _ -> ( )
let add_inline_attribute expr loc attributes = match expr , get_inline_attribute attributes with | expr , Default_inline -> expr | Lfunction ( { attr = { stub = false } as attr } as funct ) , inline -> begin match attr . inline with | Default_inline -> ( ) | Always_inline | Never_inli...
let add_specialise_attribute expr loc attributes = match expr , get_specialise_attribute attributes with | expr , Default_specialise -> expr | Lfunction ( { attr = { stub = false } as attr } as funct ) , specialise -> begin match attr . specialise with | Default_specialise -> ( ) | Alw...
let add_local_attribute expr loc attributes = match expr , get_local_attribute attributes with | expr , Default_local -> expr | Lfunction ( { attr = { stub = false } as attr } as funct ) , local -> begin match attr . local with | Default_local -> ( ) | Always_local | Never_local -> L...
let get_and_remove_inlined_attribute e = let attr , exp_attributes = find_attribute is_inlined_attribute e . exp_attributes in let inlined = parse_inline_attribute attr in inlined , { e with exp_attributes }
let get_and_remove_inlined_attribute_on_module e = let rec get_and_remove mod_expr = let attr , mod_attributes = find_attribute is_inlined_attribute mod_expr . mod_attributes in let attr = parse_inline_attribute attr in let attr , mod_desc = match mod_expr . Typedtree . mod_desc with | Tmod_constraint (...
let get_and_remove_specialised_attribute e = let attr , exp_attributes = find_attribute is_specialised_attribute e . exp_attributes in let specialised = parse_specialise_attribute attr in specialised , { e with exp_attributes }
let get_tailcall_attribute e = let is_tailcall_attribute = function | { Parsetree . attr_name = { txt ( " = tailcall " " | ocaml . tailcall " ) } ; _ } -> true | _ -> false in let tailcalls , exp_attributes = List . partition is_tailcall_attribute e . exp_attributes in match ...
let check_attribute e { Parsetree . attr_name = { txt ; loc } ; _ } = match txt with | " inline " | " ocaml . inline " | " specialise " | " ocaml . specialise " -> begin match e . exp_desc with | Texp_function _ -> ( ) | _ -> Location . prerr_warning loc ( Warni...
let check_attribute_on_module e { Parsetree . attr_name = { txt ; loc } ; _ } = match txt with | " inline " | " ocaml . inline " -> begin match e . mod_desc with | Tmod_functor _ -> ( ) | _ -> Location . prerr_warning loc ( Warnings . Misplaced_attribute txt ) end | " ...
let add_function_attributes lam loc attr = let lam = add_inline_attribute lam loc attr in let lam = add_specialise_attribute lam loc attr in let lam = add_local_attribute lam loc attr in lam
type error = Tags of label * label
let lfunction params body = if params = [ ] then body else match body with | Lfunction { kind = Curried ; params = params ' ; body = body ' ; attr ; loc } -> Lfunction { kind = Curried ; params = params @ params ' ; return = Pgenval ; body = body ' ; attr ; loc } | _ ...
let lapply ap = match ap . ap_func with Lapply ap ' -> Lapply { ap with ap_func = ap ' . ap_func ; ap_args = ap ' . ap_args @ ap . ap_args } | _ -> Lapply ap
let mkappl ( func , args ) = Lapply { ap_should_be_tailcall = false ; ap_loc = Location . none ; ap_func = func ; ap_args = args ; ap_inlined = Default_inline ; ap_specialised = Default_specialise } ; ;
let lsequence l1 l2 = if l2 = lambda_unit then l1 else Lsequence ( l1 , l2 )
let lfield v i = Lprim ( Pfield i , [ Lvar v ] , Location . none )
let transl_label l = share ( Const_immstring l )
let transl_meth_list lst = if lst = [ ] then Lconst ( Const_pointer 0 ) else share ( Const_block ( 0 , List . map ( fun lab -> Const_immstring lab ) lst ) )
let set_inst_var obj id expr = Lprim ( Psetfield_computed ( Typeopt . maybe_pointer expr , Assignment ) , [ Lvar obj ; Lvar id ; transl_exp expr ] , Location . none )
let transl_val tbl create name = mkappl ( oo_prim ( if create then " new_variable " else " get_variable " ) , [ Lvar tbl ; transl_label name ] )
let transl_vals tbl create strict vals rem = List . fold_right ( fun ( name , id ) rem -> Llet ( strict , Pgenval , id , transl_val tbl create name , rem ) ) vals rem
let meths_super tbl meths inh_meths = List . fold_right ( fun ( nm , id ) rem -> try ( nm , id , mkappl ( oo_prim " get_method " , [ Lvar tbl ; Lvar ( Meths . find nm meths ) ] ) ) :: rem with Not_found -> rem ) inh_meths [ ]
let bind_super tbl ( vals , meths ) cl_init = transl_vals tbl false StrictOpt vals ( List . fold_right ( fun ( _nm , id , def ) rem -> Llet ( StrictOpt , Pgenval , id , def , rem ) ) meths cl_init )
let create_object cl obj init = let obj ' = Ident . create_local " self " in let ( inh_init , obj_init , has_init ) = init obj ' in if obj_init = lambda_unit then ( inh_init , mkappl ( oo_prim ( if has_init then " create_object_and_run_initializers " else " create_object_opt " ) ...
let name_pattern default p = match p . pat_desc with | Tpat_var ( id , _ ) -> id | Tpat_alias ( _ , id , _ ) -> id | _ -> Ident . create_local default
let rec build_object_init cl_table obj params inh_init obj_init cl = match cl . cl_desc with Tcl_ident ( path , _ , _ ) -> let obj_init = Ident . create_local " obj_init " in let envs , inh_init = inh_init in let env = match envs with None -> [ ] | Some envs -> [ Lprim ( Pfield ( L...
let rec build_object_init_0 cl_table params cl copy_env subst_env top ids = match cl . cl_desc with Tcl_let ( _rec_flag , _defs , vals , cl ) -> build_object_init_0 cl_table ( vals @ params ) cl copy_env subst_env top ids | _ -> let self = Ident . create_local " self " in let env = Ident...
let bind_method tbl lab id cl_init = Llet ( Strict , Pgenval , id , mkappl ( oo_prim " get_method_label " , [ Lvar tbl ; transl_label lab ] ) , cl_init )
let bind_methods tbl meths vals cl_init = let methl = Meths . fold ( fun lab id tl -> ( lab , id ) :: tl ) meths [ ] in let len = List . length methl and nvals = List . length vals in if len < 2 && nvals = 0 then Meths . fold ( bind_method tbl ) meths cl_init else if len = 0 && n...
let output_methods tbl methods lam = match methods with [ ] -> lam | [ lab ; code ] -> lsequence ( mkappl ( oo_prim " set_method " , [ Lvar tbl ; lab ; code ] ) ) lam | _ -> lsequence ( mkappl ( oo_prim " set_methods " , [ Lvar tbl ; Lprim ( Pmakeblock ( 0 , I...
let rec ignore_cstrs cl = match cl . cl_desc with Tcl_constraint ( cl , _ , _ , _ , _ ) -> ignore_cstrs cl | Tcl_apply ( cl , _ ) -> ignore_cstrs cl | _ -> cl
let rec index a = function [ ] -> raise Not_found | b :: l -> if b = a then 0 else 1 + index a l
let bind_id_as_val ( id , _ ) = ( " " , id )
let rec build_class_init cla cstr super inh_init cl_init msubst top cl = match cl . cl_desc with | Tcl_ident _ -> begin match inh_init with | ( _ , path_lam , obj_init ) :: inh_init -> ( inh_init , Llet ( Strict , Pgenval , obj_init , mkappl ( Lprim ( Pfield 1 , [ path_lam ] , ...
let rec build_class_lets cl = match cl . cl_desc with Tcl_let ( rec_flag , defs , _vals , cl ' ) -> let env , wrap = build_class_lets cl ' in ( env , fun x -> Translcore . transl_let rec_flag defs ( wrap x ) ) | _ -> ( cl . cl_env , fun x -> x )
let rec get_class_meths cl = match cl . cl_desc with Tcl_structure cl -> Meths . fold ( fun _ -> Ident . Set . add ) cl . cstr_meths Ident . Set . empty | Tcl_ident _ -> Ident . Set . empty | Tcl_fun ( _ , _ , _ , cl , _ ) | Tcl_let ( _ , _ , _ , cl ) | Tcl_a...
let rec transl_class_rebind obj_init cl vf = match cl . cl_desc with Tcl_ident ( path , _ , _ ) -> if vf = Concrete then begin try if ( Env . find_class path cl . cl_env ) . cty_new = None then raise Exit with Not_found -> raise Exit end ; let path_lam = transl_class_path cl . cl_loc cl ...
let rec transl_class_rebind_0 ( self : Ident . t ) obj_init cl vf = match cl . cl_desc with Tcl_let ( rec_flag , defs , _vals , cl ) -> let path , path_lam , obj_init = transl_class_rebind_0 self obj_init cl vf in ( path , path_lam , Translcore . transl_let rec_flag defs obj_init ) ...