text
stringlengths
0
601k
let add_waiter t cb = let w = Lwt_dllist . add_l cb t in Hook . Node w
let wake { enqueue ; ctx } r = if Cancel . Fiber_context . clear_cancel_fn ctx then ( enqueue ( Ok r ) ; true ) else false
let wake_all ( t : _ t ) v = try while true do let waiter = Lwt_dllist . take_r t in ignore ( wake waiter v : bool ) done with Lwt_dllist . Empty -> ( )
let rec wake_one t v = match Lwt_dllist . take_opt_r t with | None -> ` Queue_empty | Some waiter -> if wake waiter v then ` Ok else wake_one t v
let await_internal ~ mutex ( t ' : a t ) id ( ctx : Cancel . fiber_context ) enqueue = match Cancel . Fiber_context . get_error ctx with | Some ex -> Option . iter Mutex . unlock mutex ; enqueue ( Error ex ) | None -> let resolved_waiter = ref Hook . null in let enqueue x = Ctf . note_read ~ reader : id ctx . tid ; enqueue x in let cancel ex = Hook . remove ! resolved_waiter ; enqueue ( Error ex ) in Cancel . Fiber_context . set_cancel_fn ctx cancel ; let waiter = { enqueue ; ctx } in match mutex with | None -> resolved_waiter := add_waiter t waiter | Some mutex -> resolved_waiter := add_waiter_protected ~ mutex t waiter ; Mutex . unlock mutex
let await ~ mutex waiters id = Suspend . enter_unchecked ( await_internal ~ mutex waiters id )
let all_equal ~ equal ~ compare ls = Option . value_map ( List . hd ls ) ls ~ default : true ~ f ( : fun h -> List . equal equal [ h ] ( List . find_all_dups ~ compare ls ) ls )
module Make ( Engine : Intf . Engine . S ) S ( Event_router : Intf . Dsl . Event_router_intf with module Engine := Engine ) Engine ( Network_state : Intf . Dsl . Network_state_intf with module Engine := Engine and module Event_router := Event_router ) Event_router = struct open Network_state module Node = Engine . Network . Node type ' a predicate_result = | Predicate_passed | Predicate_continuation of ' a | Predicate_failure of Error . t type predicate = | Network_state_predicate : ( Network_state . t -> ' a predicate_result ) predicate_result * ( ' a -> Network_state . t -> ' a predicate_result ) predicate_result -> predicate | Event_predicate : ' b Event_type . t * ' a * ( ' a -> Node . t -> ' b -> ' a predicate_result ) predicate_result -> predicate type t = { description : string ; predicate : predicate ; soft_timeout : Network_time_span . t ; hard_timeout : Network_time_span . t } let with_timeouts ? soft_timeout ? hard_timeout t = { t with soft_timeout = Option . value soft_timeout ~ default : t . soft_timeout ; hard_timeout = Option . value hard_timeout ~ default : t . hard_timeout } let network_state ~ description ( ~ f : Network_state . t -> bool ) bool : t = let check ( ) ( state : Network_state . t ) t = if f state then Predicate_passed else Predicate_continuation ( ) in { description ; predicate = Network_state_predicate ( check ( ) , check ) check ; soft_timeout = Literal ( Time . Span . of_hr 1 . 0 ) 0 ; hard_timeout = Literal ( Time . Span . of_hr 2 . 0 ) 0 } let nodes_to_initialize nodes = let open Network_state in network_state ~ description : ( nodes |> List . map ~ f : Node . id |> String . concat ~ sep " , : " |> Printf . sprintf [ " % s ] s to initialize " ) ~ f ( : fun ( state : Network_state . t ) t -> List . for_all nodes ~ f ( : fun node -> String . Map . find state . node_initialization ( Node . id node ) node |> Option . value ~ default : false ) ) |> with_timeouts ~ soft_timeout ( : Literal ( Time . Span . of_min 10 . 0 ) 0 ) 0 ~ hard_timeout ( : Literal ( Time . Span . of_min 15 . 0 ) 0 ) 0 let node_to_initialize node = nodes_to_initialize [ node ] let blocks_to_be_produced n = let init state = Predicate_continuation state . blocks_generated in let check init_blocks_generated state = if state . blocks_generated - init_blocks_generated >= n then Predicate_passed else Predicate_continuation init_blocks_generated in let soft_timeout_in_slots = ( 2 * n ) n + 1 in { description = Printf . sprintf " % d blocks to be produced " n ; predicate = Network_state_predicate ( init , check ) check ; soft_timeout = Slots soft_timeout_in_slots ; hard_timeout = Slots ( soft_timeout_in_slots * 2 ) 2 } let nodes_to_synchronize ( nodes : Node . t list ) list = let check ( ) state = let all_best_tips_equal = all_equal ~ equal [ :% equal : State_hash . t option ] option ~ compare [ :% compare : State_hash . t option ] option in let best_tips = List . map nodes ~ f ( : fun node -> String . Map . find state . best_tips_by_node ( Node . id node ) node ) in if List . for_all best_tips ~ f : Option . is_some && all_best_tips_equal best_tips then Predicate_passed else Predicate_continuation ( ) in let soft_timeout_in_slots = 8 * 3 in let formatted_nodes = nodes |> List . map ~ f ( : fun node -> " " " \ ^ Node . id node ^ ) " " " \ |> String . concat ~ sep " , : " in { description = Printf . sprintf " % s to synchronize " formatted_nodes ; predicate = Network_state_predicate ( check ( ) , check ) check ; soft_timeout = Slots soft_timeout_in_slots ; hard_timeout = Slots ( soft_timeout_in_slots * 2 ) 2 } let signed_command_to_be_included_in_frontier ~ txn_hash ( ~ node_included_in : [ ` Any_node | ` Node of Node . t ] ) = let check ( ) state = let blocks_with_txn_set_opt = Map . find state . blocks_including_txn txn_hash in match blocks_with_txn_set_opt with | None -> Predicate_continuation ( ) | Some blocks_with_txn_set -> ( match node_included_in with | ` Any_node -> Predicate_passed | ` Node n -> let blocks_seen_by_n = Map . find state . blocks_seen_by_node ( Node . id n ) n |> Option . value ~ default : State_hash . Set . empty in let intersection = State_hash . Set . inter blocks_with_txn_set blocks_seen_by_n in if State_hash . Set . is_empty intersection then Predicate_continuation ( ) else Predicate_passed ) in let soft_timeout_in_slots = 8 in { description = Printf . sprintf " signed command with hash % s " ( Transaction_hash . to_base58_check txn_hash ) txn_hash ; predicate = Network_state_predicate ( check ( ) , check ) check ; soft_timeout = Slots soft_timeout_in_slots ; hard_timeout = Slots ( soft_timeout_in_slots * 2 ) 2 } let ledger_proofs_emitted_since_genesis ~ num_proofs = let open Network_state in let check ( ) ( state : Network_state . t ) t = if state . snarked_ledgers_generated >= num_proofs then Predicate_passed else Predicate_continuation ( ) in let description = Printf . sprintf [ " % d ] d snarked_ledgers to be generated since genesis " num_proofs in { description ; predicate = Network_state_predicate ( check ( ) , check ) check ; soft_timeout = Slots 15 ; hard_timeout = Slots 20 } let snapp_to_be_included_in_frontier ~ has_failures ~ parties = let command_matches_parties cmd = let open User_command in match cmd with | Parties p -> Parties . equal p parties | Signed_command _ -> false in let check ( ) _node ( breadcrumb_added : Event_type . Breadcrumb_added . t ) t = let snapp_opt = List . find breadcrumb_added . user_commands ~ f ( : fun cmd_with_status -> cmd_with_status . With_status . data |> User_command . forget_check |> command_matches_parties ) in match snapp_opt with | Some cmd_with_status -> let actual_status = cmd_with_status . With_status . status in let successful = match actual_status with | Transaction_status . Applied -> not has_failures | Failed _ -> has_failures in if successful then Predicate_passed else Predicate_failure ( Error . createf " Unexpected status in matching payment : % s " ( Transaction_status . to_yojson actual_status |> Yojson . Safe . to_string ) ) | None -> Predicate_continuation ( ) in let soft_timeout_in_slots = 8 in let is_first = ref true in { description = sprintf " snapp with fee payer % s and other parties ( % s ) s " ( Signature_lib . Public_key . Compressed . to_base58_check parties . fee_payer . body . public_key ) ( Parties . Call_forest . Tree . fold_forest ~ init " " : parties . other_parties ~ f ( : fun acc party -> let str = Signature_lib . Public_key . Compressed . to_base58_check party . body . public_key in if ! is_first then ( is_first := false ; str ) else acc ^ " , " ^ str ) ) ; predicate = Event_predicate ( Event_type . Breadcrumb_added , ( ) , check ) check ; soft_timeout = Slots soft_timeout_in_slots ; hard_timeout = Slots ( soft_timeout_in_slots * 2 ) 2 } end
let refl = Filename . concat Filename . current_dir_name " reflector . exe "
let ( ) = let oc = Unix . open_process_out ( refl ^ " - i2o " ) in let pid = Unix . process_out_pid oc in let ( pid1 , status1 ) = Unix . waitpid [ WNOHANG ] pid in assert ( pid1 = 0 ) ; assert ( status1 = WEXITED 0 ) ; output_string oc " aa \ n " ; close_out oc ; let rec busywait ( ) = let ( pid2 , status2 ) = Unix . waitpid [ WNOHANG ] pid in if pid2 = 0 then begin Unix . sleepf 0 . 001 ; busywait ( ) end else begin assert ( pid2 = pid ) ; assert ( status2 = WEXITED 0 ) end in busywait ( )
module Steps = struct type t = [ ` PerZ of float | ` Flat of int ] let to_int t z = match t with ` PerZ mm -> Int . max 2 ( Float . to_int ( z . / mm ) ) | ` Flat n -> n end
module Edge = struct type t = float -> Vec3 . t let translate p = Fn . compose ( Vec3 . add p ) let scale s = Fn . compose ( Vec3 . scale s ) let mirror ax = Fn . compose ( Vec3 . mirror ax ) let rotate r = Fn . compose ( Vec3 . rotate r ) let rotate_about_pt r p = Fn . compose ( Vec3 . rotate_about_pt r p ) let quaternion q = Fn . compose ( Vec3 . quaternion q ) let quaternion_about_pt q p = Fn . compose ( Vec3 . quaternion_about_pt q p ) let point_at_z ( ? max_iter = 100 ) ( ? tolerance = 0 . 001 ) t z = let bez_frac = Util . bisection_exn ~ max_iter ~ tolerance ~ f ( : fun s -> Vec3 . get_z ( t s ) . - z ) 0 . 1 . in t bez_frac end
module EdgeDrawer = struct type drawer = Vec3 . t -> Edge . t type t = { top : drawer ; bot : drawer } let make ( ? max_iter = 100 ) ( ? tolerance = 0 . 001 ) ( ~ get_bez : bool -> Vec3 . t -> Edge . t ) Points . { top_left ; top_right ; bot_left ; bot_right ; _ } = let find_between lp rp ( x , y , _ ) = let ( ( dx , dy , _ ) as diff ) = Vec3 . sub rp lp in let get_major , target = if Float . ( abs dx > abs dy ) then ( Vec3 . get_x , x ) else ( Vec3 . get_y , y ) in let ml = get_major lp and mr = get_major rp in if Float . ( target > ml && target < mr ) || Float . ( target < ml && target > mr ) then let get s = Vec3 . ( add lp ( mul_scalar diff s ) ) in let pos = Util . bisection_exn ~ max_iter ~ tolerance ~ f ( : fun s -> get_major ( get s ) . - target ) 0 . 1 . in get pos else if Float . ( abs ( target . - ml ) < abs ( target . - mr ) ) then lp else rp in { top = find_between top_left top_right >> get_bez true ; bot = find_between bot_left bot_right >> get_bez false } let map ~ f t = { top = f t . top ; bot = f t . bot } let translate p = map ~ f ( : fun d start -> d start >> Vec3 . add p ) let scale s = map ~ f ( : fun d start -> d start >> Vec3 . scale s ) let mirror ax = map ~ f ( : fun d start -> d start >> Vec3 . mirror ax ) let rotate r = map ~ f ( : fun d start -> d start >> Vec3 . rotate r ) let rotate_about_pt r p = map ~ f ( : fun d start -> d start >> Vec3 . rotate_about_pt r p ) let quaternion q = map ~ f ( : fun d start -> d start >> Vec3 . quaternion q ) let quaternion_about_pt q p = map ~ f ( : fun d start -> d start >> Vec3 . quaternion_about_pt q p ) end
module Edges = struct type t = { top_left : Edge . t ; top_right : Edge . t ; bot_left : Edge . t ; bot_right : Edge . t } [ @@ deriving scad ] let map ~ f t = { top_left = f t . top_left ; top_right = f t . top_right ; bot_left = f t . bot_left ; bot_right = f t . bot_right } let of_clockwise_list_exn = function | [ top_left ; top_right ; bot_right ; bot_left ] -> { top_left ; top_right ; bot_left ; bot_right } | _ -> failwith " Expect list of length 4 , with edges beziers in clockwise order . " let of_clockwise_list l = try Ok ( of_clockwise_list_exn l ) with Failure e -> Error e let get t = function | ` TL -> t . top_left | ` TR -> t . top_right | ` BL -> t . bot_left | ` BR -> t . bot_right end
type config = { d1 : float ; d2 : float ; z_off : float ; thickness : float ; clearance : float ; n_steps : Steps . t ; n_facets : int ; eyelet_config : Eyelet . config option }
let default = { d1 = 2 . ; d2 = 5 . ; z_off = 0 . ; thickness = 3 . 5 ; clearance = 1 . 5 ; n_steps = ` Flat 4 ; n_facets = 1 ; eyelet_config = None }
type t = { scad : Scad . d3 ; start : Points . t ; foot : Points . t ; edge_drawer : EdgeDrawer . t ; edges : Edges . t ; screw : Eyelet . t option }
let swing_face ( ? step = Float . pi . / 24 . ) key_origin face = let quat = Quaternion . make ( KeyHole . Face . direction face ) and free , pivot , rock_z , z_sign = let ortho = Vec3 . ( normalize ( face . points . centre <-> key_origin ) ) in if Float . ( Vec3 . get_z ortho > 0 . ) then ( face . points . top_right , Vec3 . ( div ( face . points . bot_left <+> face . points . bot_right ) ( - 2 . , - 2 . , - 2 . ) ) , Vec3 . get_z face . points . bot_right , 1 . ) else ( face . points . bot_right , Vec3 . ( div ( face . points . top_left <+> face . points . top_right ) ( - 2 . , - 2 . , - 2 . ) ) , Vec3 . get_z face . points . top_right , - 1 . ) in let diff a = Vec3 . ( get_z ( Vec3 . quaternion_about_pt ( quat ( a . * z_sign ) ) pivot free ) . - rock_z ) . * z_sign in let rec find_angle a last_diff = if Float . ( a < pi ) then let d = diff a in if Float . ( d < last_diff ) then a . - step else find_angle ( a . + step ) d else a . - step in let q = quat @@ ( find_angle step ( Vec3 . get_z free . - rock_z ) . * z_sign ) in let face ' = KeyHole . Face . quaternion_about_pt q pivot face in let ortho ' = Vec3 . quaternion_about_pt q pivot key_origin |> Vec3 . sub face ' . points . centre |> Vec3 . normalize in ( face ' , ortho ' )
let poly_siding ( ? x_off = 0 . ) ( ? y_off = 0 . ) ( ? z_off = 0 . ) ( ? clearance = 1 . 5 ) ( ? n_steps = ` Flat 4 ) ( ? n_facets = 1 ) ( ? d1 = 2 . ) ( ? d2 = 5 . ) ? thickness ? eyelet_config side ( key : _ KeyHole . t ) = let start_face = KeyHole . Faces . face key . faces side and thickness = Option . value ~ default : key . config . thickness thickness in let pivoted_face , ortho = swing_face key . origin start_face in let cleared_face = KeyHole . Face . translate ( Vec3 . map ( ( . * ) clearance ) ortho ) pivoted_face in let xy = Vec3 . ( normalize ( mul ortho ( 1 . , 1 . , 0 . ) ) ) and z_hop = ( Float . max 0 . ( Vec3 . get_z ortho ) . * key . config . thickness ) . + z_off and top_offset = Vec3 . ( mul ( 1 . , 1 . , 0 . ) ( cleared_face . points . bot_right <-> cleared_face . points . top_right ) ) in let get_bez top ( ( x , y , z ) as start ) = let jog , d1 , plus = let half_delta = ( d2 . - d1 ) . / 2 . in if top then ( thickness , d1 . + Float . max half_delta 0 . , top_offset ) else ( 0 . , d1 . + Float . min half_delta 0 . , ( 0 . , 0 . , 0 . ) ) in let p1 = Vec3 . ( start <-> mul ortho ( 0 . 01 , 0 . 01 , 0 . 01 ) ) and p2 = Vec3 . ( mul xy ( d1 . + jog , d1 . + jog , 0 . ) |> add ( x . + x_off , y . + y_off , z . + z_hop ) |> add plus ) and p3 = Vec3 . ( add ( mul xy ( d2 . + jog , d2 . + jog , 0 . ) ) ( x . + x_off , y . + y_off , 0 . ) |> add plus ) in ( p3 , Bezier . quad_vec3 ~ p1 ~ p2 ~ p3 ) in let cw_points = let n = n_facets - 1 in Util . fill_points ~ init : ( Util . fill_points ~ n cleared_face . points . bot_left cleared_face . points . bot_right ) ~ n cleared_face . points . top_right cleared_face . points . top_left in let corners = List . filteri ~ f ( : fun i _ -> i = 0 || i = n_facets || i = n_facets + 1 || i = 3 + ( ( n_facets - 1 ) * 2 ) ) and steps = let adjust ( _ , _ , z ) = let lowest_z = let f m ( _ , _ , z ) = Float . min m z in Points . fold ~ f ~ init : Float . max_value cleared_face . points in Float . ( to_int ( ( 1 . . + ( ( z . - lowest_z ) . / z ) ) . * of_int ( Steps . to_int n_steps z ) ) ) in ` Ragged ( List . map ~ f : adjust cw_points ) and end_ps , bezs = List . foldi ~ f ( : fun i ( ends , bs ) p -> let e , b = get_bez ( i > n_facets ) p in ( e :: ends , b :: bs ) ) ~ init ( [ ] , : [ ] ) ( List . rev cw_points ) in let foot = Points . of_clockwise_list_exn ( corners end_ps ) in let screw = let f config = let open Eyelet in let placement = let n = Vec3 . negate xy in match config with | { hole = Through ; _ } -> Normal n | { hole = Inset _ ; outer_rad ; _ } -> let offset = outer_rad . + Vec3 . ( norm ( sub foot . top_left foot . bot_left ) . / 4 . ) in Point Vec3 . ( mean [ foot . top_left ; foot . top_right ] <+> mul_scalar n offset ) in make ~ placement config foot . bot_left foot . bot_right in Option . map ~ f eyelet_config in { scad = Scad . hull [ start_face . scad ; cleared_face . scad ] :: Bezier . prism_exn bezs steps :: Option . value_map ~ default [ ] : ~ f ( : fun s -> [ s . scad ] ) screw |> Scad . union |> Fn . flip Scad . difference ( Option . value_map ~ default [ ] : ~ f ( : fun s -> Option . to_list s . cut ) screw ) ; start = start_face . points ; foot ; edge_drawer = EdgeDrawer . make ~ get_bez ( : fun top start -> snd ( get_bez top start ) ) cleared_face . points ; edges = Edges . of_clockwise_list_exn ( corners bezs ) ; screw }
let poly_of_config ? x_off ? y_off { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = poly_siding ~ d1 ~ d2 ? x_off ? y_off ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ? eyelet_config
let column_drop ? z_off ? clearance ? n_steps ? n_facets ? d1 ? d2 ? thickness ? eyelet_config ~ spacing ~ columns side idx = let key , face , hanging = let c : _ Column . t = Map . find_exn columns idx in match side with | ` North -> let key = snd @@ Map . max_elt_exn c . keys in let edge_y = Vec3 . get_y key . faces . north . points . centre in ( key , key . faces . north , Float . ( ( <= ) edge_y ) ) | ` South -> let key = Map . find_exn c . keys 0 in let edge_y = Vec3 . get_y key . faces . south . points . centre in ( key , key . faces . south , Float . ( ( >= ) edge_y ) ) in let x_dodge = match Map . find columns ( idx + 1 ) with | Some next_c -> let right_x = Vec3 . get_x face . points . top_right and next_face = KeyHole . Faces . face ( snd @@ Map . max_elt_exn next_c . keys ) . faces side in let diff = if hanging ( Vec3 . get_y next_face . points . centre ) then right_x . - Vec3 . get_x next_face . points . bot_left else . - spacing in if Float . ( diff > 0 . ) then diff . + spacing else Float . max 0 . ( spacing . + diff ) | _ -> 0 . in poly_siding ~ x_off ( : x_dodge . * - 1 . ) ? z_off ? clearance ? d1 ? d2 ? thickness ? n_steps ? n_facets ? eyelet_config side key
let drop_of_config ~ spacing { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = column_drop ~ d1 ~ d2 ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ~ spacing ? eyelet_config
let start_direction { start = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let foot_direction { foot = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let to_scad t = t . scad
module Mnemonic = struct let new_random = Bip39 . of_entropy ( Hacl . Rand . gen 32 ) let to_sapling_key mnemonic = let seed_64_to_seed_32 ( seed_64 : bytes ) : bytes = assert ( Bytes . length seed_64 = 64 ) ; let first_32 = Bytes . sub seed_64 0 32 in let second_32 = Bytes . sub seed_64 32 32 in let seed_32 = Bytes . create 32 in for i = 0 to 31 do Bytes . set seed_32 i ( Char . chr ( Char . code ( Bytes . get first_32 i ) lxor Char . code ( Bytes . get second_32 i ) ) ) done ; seed_32 in Spending_key . of_seed ( seed_64_to_seed_32 ( Bip39 . to_seed mnemonic ) ) let words_pp = Format . ( pp_print_list ~ pp_sep : pp_print_space pp_print_string ) end
let to_uri unencrypted cctxt sapling_key = if unencrypted then Tezos_signer_backends . Unencrypted . make_sapling_key sapling_key >>?= return else Tezos_signer_backends . Encrypted . encrypt_sapling_key cctxt sapling_key
let from_uri ( cctxt : # Client_context . full ) uri = Tezos_signer_backends . Encrypted . decrypt_sapling_key cctxt uri
let register ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) mnemonic name = let sk = Mnemonic . to_sapling_key mnemonic in to_uri unencrypted cctxt sk >>=? fun sk_uri -> let key = { sk = sk_uri ; path = [ Spending_key . child_index sk ] ; address_index = Viewing_key . default_index ; } in Sapling_key . add ~ force cctxt name key >>=? fun ( ) -> return @@ Viewing_key . of_sk sk
let derive ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) src_name dst_name child_index = Sapling_key . find cctxt src_name >>=? fun k -> from_uri cctxt k . sk >>=? fun src_sk -> let child_index = Int32 . of_int child_index in let dst_sk = Spending_key . derive_key src_sk child_index in to_uri unencrypted cctxt dst_sk >>=? fun dst_sk_uri -> let dst_key = { sk = dst_sk_uri ; path = child_index :: k . path ; address_index = Viewing_key . default_index ; } in let _ = force in Sapling_key . add ~ force : true cctxt dst_name dst_key >>=? fun ( ) -> let path = String . concat " " / ( List . map Int32 . to_string ( List . rev dst_key . path ) ) in return ( path , Viewing_key . of_sk dst_sk )
let find_vk cctxt name = Sapling_key . find cctxt name >>=? fun k -> from_uri cctxt k . sk >>=? fun sk -> return ( Viewing_key . of_sk sk )
let new_address ( cctxt : # Client_context . full ) name index_opt = Sapling_key . find cctxt name >>=? fun k -> let index = match index_opt with | None -> k . address_index | Some i -> Viewing_key . index_of_int64 ( Int64 . of_int i ) in from_uri cctxt k . sk >>=? fun sk -> return ( Viewing_key . of_sk sk ) >>=? fun vk -> let ( corrected_index , address ) = Viewing_key . new_address vk index in Sapling_key . update cctxt name { k with address_index = Viewing_key . index_succ corrected_index } >>=? fun ( ) -> return ( sk , corrected_index , address )
let export_vk cctxt name = find_vk cctxt name >>=? fun vk -> return ( Data_encoding . Json . construct Viewing_key . encoding vk )
type locked_key = | Locked of string | Unlocked of ( string * Keypair . t ) t | Hd_account of Mina_numbers . Hd_index . t
type t = { cache : locked_key Public_key . Compressed . Table . t ; path : string }
let get_privkey_filename public_key = Public_key . Compressed . to_base58_check public_key
let get_path { path ; cache } public_key = let filename = Public_key . Compressed . Table . find cache public_key |> Option . bind ~ f ( : function | Locked file | Unlocked ( file , _ ) _ -> Option . return file | Hd_account _ -> Option . return ( Public_key . Compressed . to_base58_check public_key ^ " . index ) " ) |> Option . value ~ default ( : get_privkey_filename public_key ) public_key in path ^/ filename
let decode_public_key key file path logger = match Or_error . try_with ( fun ( ) -> Public_key . of_base58_check_decompress_exn key ) key with | Ok pk -> Some pk | Error e -> [ % log error ] error " Error decoding public key at $ path /$ file : $ error " ~ metadata : [ ( " file " , ` String file ) file ; ( " path " , ` String path ) path ; ( " error " , Error_json . error_to_yojson e ) e ] ; None
let reload ~ logger { cache ; path } : unit Deferred . t = let logger = Logger . extend logger [ ( " wallets_context " , ` String " Wallets . get ) " ] in Public_key . Compressed . Table . clear cache ; let % bind ( ) = File_system . create_dir path in let % bind files = Sys . readdir path >>| Array . to_list in let % bind ( ) = Deferred . List . iter files ~ f ( : fun file -> match String . chop_suffix file ~ suffix " . : pub " with | Some sk_filename -> ( let % map lines = Reader . file_lines ( path ^/ file ) file in match lines with | public_key :: _ -> decode_public_key public_key file path logger |> Option . iter ~ f ( : fun pk -> ignore @@ Public_key . Compressed . Table . add cache ~ key : pk ~ data ( : Locked sk_filename ) sk_filename ) | _ -> ( ) ) | None -> ( match String . chop_suffix file ~ suffix " . : index " with | Some public_key -> ( let % map lines = Reader . file_lines ( path ^/ file ) file in match lines with | hd_index :: _ -> decode_public_key public_key file path logger |> Option . iter ~ f ( : fun pk -> ignore @@ Public_key . Compressed . Table . add cache ~ key : pk ~ data : ( Hd_account ( Mina_numbers . Hd_index . of_string hd_index ) hd_index ) ) | _ -> ( ) ) | None -> return ( ) ) ) in Unix . chmod path ~ perm : 0o700
let load ~ logger ~ disk_location = let t = { cache = Public_key . Compressed . Table . create ( ) ; path = disk_location ^/ " store " } in let % map ( ) = reload ~ logger t in t
let import_keypair_helper t keypair write_keypair = let compressed_pk = Public_key . compress keypair . Keypair . public_key in let privkey_path = get_path t compressed_pk in let % bind ( ) = write_keypair privkey_path in let % map ( ) = Unix . chmod privkey_path ~ perm : 0o600 in ignore ( Public_key . Compressed . Table . add t . cache ~ key : compressed_pk ~ data ( : Unlocked ( get_privkey_filename compressed_pk , keypair ) keypair ) keypair : [ ` Duplicate | ` Ok ] ) ; compressed_pk
let import_keypair t keypair ~ password = import_keypair_helper t keypair ( fun privkey_path -> Secret_keypair . write_exn keypair ~ privkey_path ~ password )
let import_keypair_terminal_stdin t keypair = import_keypair_helper t keypair ( fun privkey_path -> Secret_keypair . Terminal_stdin . write_exn keypair ~ privkey_path )
let generate_new t ~ password : Public_key . Compressed . t Deferred . t = let keypair = Keypair . create ( ) in import_keypair t keypair ~ password
let create_hd_account t ~ hd_index : ( Public_key . Compressed . t , string ) string Deferred . Result . t = let open Deferred . Result . Let_syntax in let % bind public_key = Hardware_wallets . compute_public_key ~ hd_index in let compressed_pk = Public_key . compress public_key in let index_path = t . path ^/ Public_key . Compressed . to_base58_check compressed_pk ^ " . index " in let % bind ( ) = Hardware_wallets . write_exn ~ hd_index ~ index_path |> Deferred . map ~ f : Result . return in let % map ( ) = Unix . chmod index_path ~ perm : 0o600 |> Deferred . map ~ f : Result . return in ignore ( Public_key . Compressed . Table . add t . cache ~ key : compressed_pk ~ data ( : Hd_account hd_index ) hd_index : [ ` Duplicate | ` Ok ] ) ; compressed_pk
let delete ( { cache ; _ } as t : t ) t ( pk : Public_key . Compressed . t ) t : ( unit , [ ` Not_found ] ) Deferred . Result . t = Hashtbl . remove cache pk ; Deferred . Or_error . try_with ~ here [ :% here ] here ( fun ( ) -> Unix . remove ( get_path t pk ) pk ) |> Deferred . Result . map_error ~ f ( : fun _ -> ` Not_found ) Not_found
let pks ( { cache ; _ } : t ) t = Public_key . Compressed . Table . keys cache
let find_unlocked ( { cache ; _ } : t ) t ~ needle = Public_key . Compressed . Table . find cache needle |> Option . bind ~ f ( : function | Locked _ -> None | Unlocked ( _ , kp ) kp -> Some kp | Hd_account _ -> None )
let find_identity ( { cache ; _ } : t ) t ~ needle = Public_key . Compressed . Table . find cache needle |> Option . bind ~ f ( : function | Locked _ -> None | Unlocked ( _ , kp ) kp -> Some ( ` Keypair kp ) kp | Hd_account index -> Some ( ` Hd_index index ) index )
let check_locked { cache ; _ } ~ needle = Public_key . Compressed . Table . find cache needle |> Option . map ~ f ( : function | Locked _ -> true | Unlocked _ -> false | Hd_account _ -> true )
let unlock { cache ; path } ~ needle ~ password = let unlock_keypair = function | Locked file -> Secret_keypair . read ~ privkey_path ( : path ^/ file ) file ~ password |> Deferred . Result . map_error ~ f ( : fun e -> ` Key_read_error e ) e |> Deferred . Result . map ~ f ( : fun kp -> Public_key . Compressed . Table . set cache ~ key : needle ~ data ( : Unlocked ( file , kp ) kp ) kp ) |> Deferred . Result . ignore_m | Unlocked _ -> Deferred . Result . return ( ) | Hd_account _ -> Deferred . Result . return ( ) in Public_key . Compressed . Table . find cache needle |> Result . of_option ~ error ` : Not_found |> Deferred . return |> Deferred . Result . bind ~ f : unlock_keypair
let lock { cache ; _ } ~ needle = Public_key . Compressed . Table . change cache needle ~ f ( : function | Some ( Unlocked ( file , _ ) _ ) _ -> Some ( Locked file ) file | k -> k )
let get_tracked_keypair ~ logger ~ which ~ read_from_env_exn ~ conf_dir pk = let % bind wallets = load ~ logger ~ disk_location ( : conf_dir ^/ " wallets ) " in let sk_file = get_path wallets pk in read_from_env_exn ~ which sk_file ( module struct let logger = Logger . create ( ) let password = lazy ( Deferred . return ( Bytes . of_string ) ) " " module Set = Public_key . Compressed . Set let % test_unit " get from scratch " = Async . Thread_safe . block_on_async_exn ( fun ( ) -> File_system . with_temp_dir " / tmp / coda - wallets - test " ~ f ( : fun path -> let % bind wallets = load ~ logger ~ disk_location : path in let % map pk = generate_new wallets ~ password in let keys = Set . of_list ( pks wallets ) wallets in assert ( Set . mem keys pk ) pk ; assert ( find_unlocked wallets ~ needle : pk |> Option . is_some ) is_some ) ) let % test_unit " get from existing file system not - scratch " = Backtrace . elide := false ; Async . Thread_safe . block_on_async_exn ( fun ( ) -> File_system . with_temp_dir " / tmp / coda - wallets - test " ~ f ( : fun path -> let % bind wallets = load ~ logger ~ disk_location : path in let % bind pk1 = generate_new wallets ~ password in let % bind pk2 = generate_new wallets ~ password in let keys = Set . of_list ( pks wallets ) wallets in assert ( Set . mem keys pk1 && Set . mem keys pk2 ) pk2 ; let % map wallets = load ~ logger ~ disk_location : path in let keys = Set . of_list ( pks wallets ) wallets in assert ( Set . mem keys pk1 && Set . mem keys pk2 ) pk2 ) ) let % test_unit " create wallet then delete it " = Async . Thread_safe . block_on_async_exn ( fun ( ) -> File_system . with_temp_dir " / tmp / coda - wallets - test " ~ f ( : fun path -> let % bind wallets = load ~ logger ~ disk_location : path in let % bind pk = generate_new wallets ~ password in let keys = Set . of_list ( pks wallets ) wallets in assert ( Set . mem keys pk ) pk ; match % map delete wallets pk with | Ok ( ) -> assert ( Option . is_none @@ Public_key . Compressed . Table . find wallets . cache pk ) | Error _ -> failwith " unexpected " ) ) let % test_unit " Unable to find wallet " = Async . Thread_safe . block_on_async_exn ( fun ( ) -> File_system . with_temp_dir " / tmp / coda - wallets - test " ~ f ( : fun path -> let % bind wallets = load ~ logger ~ disk_location : path in let keypair = Keypair . create ( ) in let % map result = delete wallets ( Public_key . compress @@ keypair . public_key ) public_key in assert ( Result . is_error result ) result ) ) end )
type presence = | No | Yes | Eye
module Side = struct type t = Wall . t Map . M ( Int ) . t [ @@ deriving scad_jane ] type config = int -> Wall . config option end
module Sides = struct type t = { west : Side . t ; north : Side . t ; east : Side . t ; south : Side . t } [ @@ deriving scad ] let manual_body ( ? spacing = 1 . ) ~ west ~ north ~ east ~ south ( columns : _ Columns . t ) = { west = Map . filter_mapi ~ f ( : fun ~ key ~ data -> Option . map ~ f ( : fun c -> Wall . poly_of_config c ` West data ) ( west key ) ) ( Map . find_exn columns 0 ) . keys ; north = Map . filter_mapi ~ f ( : fun ~ key ~ data : _ -> Option . map ~ f ( : fun c -> Wall . drop_of_config ~ spacing ~ columns c ` North key ) ( north key ) ) columns ; east = Map . filter_mapi ~ f ( : fun ~ key ~ data -> Option . map ~ f ( : fun c -> Wall . poly_of_config c ` East data ) ( east key ) ) ( snd @@ Map . max_elt_exn columns ) . keys ; south = Map . filter_mapi ~ f ( : fun ~ key ~ data : _ -> Option . map ~ f ( : fun c -> Wall . drop_of_config ~ spacing ~ columns c ` South key ) ( south key ) ) columns } let manual_thumb ~ west ~ north ~ east ~ south ( columns : _ Columns . t ) = { west = Map . filter_mapi ~ f ( : fun ~ key ~ data -> let % bind . Option _ , k = Map . min_elt data . keys in Option . map ~ f ( : fun c -> Wall . poly_of_config c ` West k ) ( west key ) ) columns ; north = Map . filter_mapi ~ f ( : fun ~ key ~ data -> Option . map ~ f ( : fun c -> Wall . poly_of_config c ` North data ) ( north key ) ) ( snd @@ Map . min_elt_exn columns ) . keys ; east = Map . filter_mapi ~ f ( : fun ~ key ~ data -> let % bind . Option k = Map . find data . keys 0 in Option . map ~ f ( : fun c -> Wall . poly_of_config c ` East k ) ( east key ) ) columns ; south = Map . filter_mapi ~ f ( : fun ~ key ~ data -> Option . map ~ f ( : fun c -> Wall . poly_of_config c ` South data ) ( south key ) ) ( snd @@ Map . max_elt_exn columns ) . keys } let auto ( ? d1 = 2 . ) ( ? d2 = 5 . ) ( ? z_off = 0 . ) ( ? thickness = 3 . 5 ) ? index_thickness ( ? north_clearance = 2 . 5 ) ( ? south_clearance = 2 . 5 ) ( ? side_clearance = 3 . 0 ) ( ? n_steps = ` Flat 4 ) ( ? n_facets = 1 ) ( ? north_lookup = fun i -> if i = 2 || i = 4 then Eye else Yes ) ( ? south_lookup = function | i when i = 3 -> Eye | i when i > 1 -> Yes | _ -> No ) ( ? west_lookup = fun i -> if i = 0 then Eye else No ) ( ? east_lookup = fun _ -> No ) ( ? eyelet_config = Eyelet . m4_config ) ( ? spacing = 1 . ) ( ? thumb = false ) ( columns : ' k Columns . t ) = let present m i conf = function | Yes -> Map . add_exn m ~ key : i ~ data : conf | Eye -> Map . add_exn m ~ key : i ~ data : Wall . { conf with eyelet_config = Some eyelet_config } | No -> m and conf = Wall . { d1 ; d2 ; z_off ; thickness ; clearance = side_clearance ; n_steps ; n_facets ; eyelet_config = None } and init = Map . empty ( module Int ) in let west = Map . find @@ List . fold ~ init ~ f ( : fun m i -> present m i conf ( west_lookup i ) ) ( if thumb then Map . keys columns else Map . keys ( Map . find_exn columns 0 ) . keys ) and east = Map . find @@ List . fold ~ init ~ f ( : fun m i -> present m i conf ( east_lookup i ) ) ( if thumb then Map . keys columns else Map . keys ( snd @@ Map . min_elt_exn columns ) . keys ) and north = let index = Option . value ~ default : thickness index_thickness in let f m i = present m i { conf with clearance = north_clearance ; thickness = ( if i < 2 then index else thickness ) } ( north_lookup i ) in Map . find @@ List . fold ~ init ~ f ( if thumb then Map . keys ( snd @@ Map . min_elt_exn columns ) . keys else Map . keys columns ) and south = Map . find @@ List . fold ~ init ~ f ( : fun m i -> present m i { conf with clearance = south_clearance } ( south_lookup i ) ) ( if thumb then Map . keys ( snd @@ Map . max_elt_exn columns ) . keys else Map . keys columns ) in if thumb then manual_thumb ~ west ~ north ~ east ~ south columns else manual_body ~ west ~ north ~ east ~ south ~ spacing columns let fold ~ init ~ f ( t : t ) = let init = Map . fold ~ init ~ f t . west in let init = Map . fold ~ init ~ f t . north in let init = Map . fold ~ init ~ f t . east in Map . fold ~ init ~ f t . south let get t = function | ` N -> t . north | ` E -> t . east | ` S -> t . south | ` W -> t . west let to_scad t = let f ~ key : _ ~ data l = Wall . to_scad data :: l in Scad . union_3d ( fold ~ init [ ] : ~ f t ) let collect_screws ( ? init = [ ] ) ( t : t ) = let f ~ key : _ ~ data l = Option . value_map ~ default : l ~ f ( : fun s -> s :: l ) data . Wall . screw in fold ~ init ~ f t end
let auto_body ? d1 ? d2 ? z_off ? thickness ? index_thickness ? north_clearance ? south_clearance ? side_clearance ? n_steps ? n_facets ? north_lookup ? south_lookup ? west_lookup ? east_lookup ? eyelet_config Plate . { config = { spacing ; _ } ; body ; _ } = Sides . auto ? d1 ? d2 ? z_off ? thickness ? index_thickness ? north_clearance ? south_clearance ? side_clearance ? n_steps ? n_facets ? north_lookup ? south_lookup ? west_lookup ? east_lookup ? eyelet_config ~ spacing body
let auto_thumb ( ? d1 = 1 . ) ( ? d2 = 3 . ) ( ? z_off = 0 . ) ( ? thickness = 3 . 5 ) ? index_thickness ( ? north_clearance = 2 . 5 ) ( ? south_clearance = 2 . 5 ) ( ? side_clearance = 3 . 0 ) ( ? n_steps = ` PerZ 4 . ) ( ? n_facets = 1 ) ( ? north_lookup = fun i -> if i = 0 then Yes else No ) ( ? south_lookup = fun i -> if i = 0 then Yes else if i = 2 then Eye else No ) ( ? west_lookup = fun i -> if i = 0 then Yes else No ) ( ? east_lookup = fun _ -> No ) ? eyelet_config Plate . { thumb ; _ } = Sides . auto ~ d1 ~ d2 ~ z_off ~ thickness ? index_thickness ~ north_clearance ~ south_clearance ~ side_clearance ~ n_steps ~ n_facets ~ north_lookup ~ south_lookup ~ west_lookup ~ east_lookup ? eyelet_config ~ thumb : true thumb
type t = { body : Sides . t ; thumb : Sides . t }
let make ~ body ~ thumb = { body ; thumb }
let manual ~ body_west ~ body_north ~ body_east ~ body_south ~ thumb_south ~ thumb_north ~ thumb_east ~ thumb_west Plate . { config = { spacing ; _ } ; body ; thumb ; _ } = { body = Sides . manual_body ~ west : body_west ~ north : body_north ~ east : body_east ~ south : body_south ~ spacing body ; thumb = Sides . manual_thumb ~ west : thumb_west ~ north : thumb_north ~ east : thumb_east ~ south : thumb_south thumb }
let to_scad { body ; thumb } = Scad . union [ Sides . to_scad body ; Sides . to_scad thumb ]
let collect_screws { body ; thumb } = Sides . collect_screws ~ init ( : Sides . collect_screws thumb ) body
let test_check_walrus_operator context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | ( x := True ) reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` typing_extensions . Literal [ True ] ` . " ] ; assert_type_errors { | if ( b := True ) : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ True ] ` . " ] ; assert_type_errors { | a = [ 1 , 2 , 3 ] if ( d := len ( a ) ) : reveal_type ( d ) } | [ " Revealed type [ - 1 ] : Revealed type for ` d ` is ` int ` . " ] ; assert_type_errors { | x = ( y := 0 ) reveal_type ( x ) reveal_type ( y ) } | [ " Missing global annotation [ 5 ] : Globally accessible variable ` x ` has type ` int ` but no type \ is specified . " ; " Revealed type [ - 1 ] : Revealed type for ` x ` is ` typing_extensions . Literal [ 0 ] ` . " ; " Revealed type [ - 1 ] : Revealed type for ` y ` is ` typing_extensions . Literal [ 0 ] ` . " ; ] ; assert_type_errors { | def foo ( x : int , cat : str ) -> None : pass foo ( x := 3 , cat ' = vector ' ) reveal_type ( x ) } | [ " Revealed type [ - 1 ] : Revealed type for ` x ` is ` typing_extensions . Literal [ 3 ] ` . " ] ; assert_type_errors { | def foo ( cat : str ) -> None : pass foo ( cat ( = category := ' vector ' ) ) reveal_type ( category ) } | [ " Revealed type [ - 1 ] : Revealed type for ` category ` is ` typing_extensions . Literal [ ' vector ' ] ` . " ] ; assert_type_errors { | a = [ 1 , 2 , 3 ] if ( b := len ( a ) ) > 4 : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` int ` . " ] ; assert_type_errors { | a = [ 1 , 2 , 3 ] if ( b := 3 ) in a : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 3 ] ` . " ] ; assert_type_errors { | if ( b := 42 ) and True : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 42 ] ` . " ] ; assert_type_errors { | if True and ( b := 42 ) : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 42 ] ` . " ] ; assert_type_errors { | if ( b := 0 ) or True : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 0 ] ` . " ] ; assert_type_errors { | if False or ( b := 0 ) : reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 0 ] ` . " ] ; assert_type_errors { | if ( b := 3 ) > 4 : pass reveal_type ( b ) } | [ " Revealed type [ - 1 ] : Revealed type for ` b ` is ` typing_extensions . Literal [ 3 ] ` . " ] ; assert_type_errors { | from typing import Optional def foo ( ) -> Optional [ int ] : . . . if ( a := foo ( ) ) is not None : reveal_type ( a ) } | [ " Revealed type [ - 1 ] : Revealed type for ` a ` is ` int ` . " ]
let ( ) = " walrus " >::: [ " check_walrus_operator " >:: test_check_walrus_operator ] |> Test . run
this is a comment ) *
type t = Foo | Bar ; ;
let f = function | Foo -> print_string " 1 " | _ -> print_string " other than 1 "
let _ = print_string " hello " ; List . iter print_string ; print_string " world "
let ( ) = let iter ' ~ f xs = List . iter f xs in iter ' print_endline [ " hello " ; " world " ] method m = print_endline " hello " end inherit c method m = print_endline " bye " end
let g = function | true -> print_endline " hello "
type r = { x : int ; y : int }
let h = function | { x = 0 } -> 0 | { x = _ } -> 1
let f10 fd = let buf = Bytes . create 10 in Unix . read fd buf 0 10 ; buf
let x11 x = match x with | Some true -> 1 | Some false -> 0 | None -> 0 | Some _ -> 2
let w12 = function | ( Some _ | Some _ ) -> 1 | None -> 0 val mutable x = 1 method get_x = x end val mutable x = 10 inherit c13 method get_x ' = x end
let regexp = " ( [ \ A - Z ] [ + A - Za - z0 - 9 ] ) . " +\\ method private x = self # x + 1 end
module type DEPRECATED = sig end [ @@ ocaml . deprecated ]
module T = struct type deprecated [ @@ ocaml . deprecated ] end
let _ = let x = 1 in ( )
module A = struct let _ = let x = 1 in ( ) end
module rec B : sig type t end = struct type t = T . deprecated end
module type T = sig type t = T . deprecated end
module type S = sig val x : T . deprecated [ @@ ocaml . alert " - deprecated " ] module AA : sig type t = T . deprecated end [ @@ ocaml . alert " - deprecated " ] module rec BB : sig type t = T . deprecated end [ @@ ocaml . alert " - deprecated " ] module type T = sig type t = T . deprecated end [ @@ ocaml . alert " - deprecated " ] include DEPRECATED [ @@ ocaml . alert " - deprecated " ] end
let foo ? x = ( ) [ %% expect { | ^ } ] |
let foo ? x ~ y = ( ) [ %% expect { | ^ } ] |
let foo ? x ( ) = ( ) [ %% expect { | } ] |
let foo ? x ~ y ( ) = ( ) [ %% expect { | } ] | [ %% expect { | ^ } ] | [ %% expect { | ^ } ] | [ %% expect { | } ] | [ %% expect { | } ] |
type loc = { loc_start : Lexing . position ; loc_end : Lexing . position ; loc_ghost : bool ; }
type t = | Comment_start | Comment_not_end | Fragile_match of string | Partial_application | Labels_omitted of string list | Method_override of string list | Partial_match of string | Non_closed_record_pattern of string | Statement_type | Unused_match | Unused_pat | Instance_variable_override of string list | Illegal_backslash | Implicit_public_methods of string list | Unerasable_optional_argument | Undeclared_virtual_method of string | Not_principal of string | Without_principality of string | Unused_argument | Nonreturning_statement | Preprocessor of string | Useless_record_with | Bad_module_name of string | All_clauses_guarded | Unused_var of string | Unused_var_strict of string | Wildcard_arg_to_constant_constr | Eol_in_string | Duplicate_definitions of string * string * string * string | Multiple_definition of string * string * string | Unused_value_declaration of string | Unused_open of string | Unused_type_declaration of string | Unused_for_index of string | Unused_ancestor of string | Unused_constructor of string * bool * bool | Unused_extension of string * bool * bool * bool | Unused_rec_flag | Name_out_of_scope of string * string list * bool | Ambiguous_name of string list * string list * bool * string | Disambiguated_name of string | Nonoptional_label of string | Open_shadow_identifier of string * string | Open_shadow_label_constructor of string * string | Bad_env_variable of string * string | Attribute_payload of string * string | Eliminated_optional_arguments of string list | No_cmi_file of string * string option | Bad_docstring of bool | Expect_tailcall | Fragile_literal_pattern | Misplaced_attribute of string | Duplicated_attribute of string | Inlining_impossible of string | Unreachable_case | Ambiguous_pattern of string list | No_cmx_file of string | Assignment_to_non_mutable_value | Unused_module of string | Unboxable_type_in_prim_decl of string | Constraint_on_gadt | Erroneous_printed_signature of string | Unsafe_without_parsing | Redefining_unit of string | Unused_open_bang of string | Unused_functor_parameter of string | Module_compiled_without_lto of string ; ;
type alert = { kind : string ; message : string ; def : loc ; use : loc }
let number = function | Comment_start -> 1 | Comment_not_end -> 2 | Fragile_match _ -> 4 | Partial_application -> 5 | Labels_omitted _ -> 6 | Method_override _ -> 7 | Partial_match _ -> 8 | Non_closed_record_pattern _ -> 9 | Statement_type -> 10 | Unused_match -> 11 | Unused_pat -> 12 | Instance_variable_override _ -> 13 | Illegal_backslash -> 14 | Implicit_public_methods _ -> 15 | Unerasable_optional_argument -> 16 | Undeclared_virtual_method _ -> 17 | Not_principal _ -> 18 | Without_principality _ -> 19 | Unused_argument -> 20 | Nonreturning_statement -> 21 | Preprocessor _ -> 22 | Useless_record_with -> 23 | Bad_module_name _ -> 24 | All_clauses_guarded -> 8 | Unused_var _ -> 26 | Unused_var_strict _ -> 27 | Wildcard_arg_to_constant_constr -> 28 | Eol_in_string -> 29 | Duplicate_definitions _ -> 30 | Multiple_definition _ -> 31 | Unused_value_declaration _ -> 32 | Unused_open _ -> 33 | Unused_type_declaration _ -> 34 | Unused_for_index _ -> 35 | Unused_ancestor _ -> 36 | Unused_constructor _ -> 37 | Unused_extension _ -> 38 | Unused_rec_flag -> 39 | Name_out_of_scope _ -> 40 | Ambiguous_name _ -> 41 | Disambiguated_name _ -> 42 | Nonoptional_label _ -> 43 | Open_shadow_identifier _ -> 44 | Open_shadow_label_constructor _ -> 45 | Bad_env_variable _ -> 46 | Attribute_payload _ -> 47 | Eliminated_optional_arguments _ -> 48 | No_cmi_file _ -> 49 | Bad_docstring _ -> 50 | Expect_tailcall -> 51 | Fragile_literal_pattern -> 52 | Misplaced_attribute _ -> 53 | Duplicated_attribute _ -> 54 | Inlining_impossible _ -> 55 | Unreachable_case -> 56 | Ambiguous_pattern _ -> 57 | No_cmx_file _ -> 58 | Assignment_to_non_mutable_value -> 59 | Unused_module _ -> 60 | Unboxable_type_in_prim_decl _ -> 61 | Constraint_on_gadt -> 62 | Erroneous_printed_signature _ -> 63 | Unsafe_without_parsing -> 64 | Redefining_unit _ -> 65 | Unused_open_bang _ -> 66 | Unused_functor_parameter _ -> 67 | Module_compiled_without_lto _ -> 68 ; ;
let last_warning_number = 67 ; ;
let letter = function | ' a ' -> let rec loop i = if i = 0 then [ ] else i :: loop ( i - 1 ) in loop last_warning_number | ' b ' -> [ ] | ' c ' -> [ 1 ; 2 ] | ' d ' -> [ 3 ] | ' e ' -> [ 4 ] | ' f ' -> [ 5 ] | ' g ' -> [ ] | ' h ' -> [ ] | ' i ' -> [ ] | ' j ' -> [ ] | ' k ' -> [ 32 ; 33 ; 34 ; 35 ; 36 ; 37 ; 38 ; 39 ] | ' l ' -> [ 6 ] | ' m ' -> [ 7 ] | ' n ' -> [ ] | ' o ' -> [ ] | ' p ' -> [ 8 ] | ' q ' -> [ ] | ' r ' -> [ 9 ] | ' s ' -> [ 10 ] | ' t ' -> [ ] | ' u ' -> [ 11 ; 12 ] | ' v ' -> [ 13 ] | ' w ' -> [ ] | ' x ' -> [ 14 ; 15 ; 16 ; 17 ; 18 ; 19 ; 20 ; 21 ; 22 ; 23 ; 24 ; 30 ] | ' y ' -> [ 26 ] | ' z ' -> [ 27 ] | _ -> assert false ; ;
type state = { active : bool array ; error : bool array ; alerts : ( Misc . Stdlib . String . Set . t * bool ) ; alert_errors : ( Misc . Stdlib . String . Set . t * bool ) ; }
let current = ref { active = Array . make ( last_warning_number + 1 ) true ; error = Array . make ( last_warning_number + 1 ) false ; alerts = ( Misc . Stdlib . String . Set . empty , false ) ; alert_errors = ( Misc . Stdlib . String . Set . empty , true ) ; }
let disabled = ref false
let without_warnings f = Misc . protect_refs [ Misc . R ( disabled , true ) ] f
let backup ( ) = ! current
let restore x = current := x