text
stringlengths
0
601k
type ' a working_list = { indice : int ; clean : unit -> unit ; pop : unit ' -> a option ; push : ' a -> unit ; list : unit -> ' a list ; exists : ( ' a -> bool ) -> bool ; member : ' a -> bool ; not_empty : unit -> bool ; copy : unit ' -> a working_list }
let rec make n = let h = Hashtbl . create n in let l = Queue . create ( ) in let push a = try ( Hashtbl . find h a ) with _ -> ( Queue . add a l ; let pop ( ) = try ( let k = Queue . take l in Hashtbl . remove h k ; Some k ) with _ -> None in let not_empty ( ) = match pop ( ) with | Some a -> let ( ) = push a in true | None -> false in let clean ( ) = try ( while true do let _ = pop ( ) in ( ) done ) with _ -> ( ) in let list ( ) = let rep = ref [ ] in iter ( fun x -> rep := x ( ::! rep ) ) l ; ! rep in let copy ( ) = let rep = make n in iter ( fun x -> rep . push x ) l ; rep in let member x = try ( Hashtbl . find h x ; true ) with _ -> false in let exists p = try ( iter ( fun x -> if p x then raise Exit else ( ) ) l ; false ) { indice = n ; clean = clean ; list = list ; pop = pop ; push = push ; exists = exists ; member = member ; not_empty = not_empty ; copy = copy } ; ;
let _wmap parameters _error f l = let rep = make ( Remanent_parameters . get_empty_hashtbl_size parameters ) in List . map ( fun x -> rep . push ( f x ) ) ( l . list ( ) )
let indice wl = wl . indice
let clean wl = wl . clean ( )
let list wl = wl . list ( )
let pop wl = wl . pop ( )
let push a wl = wl . push a
let exists p wl = wl . exists p
let not_empty wl = wl . not_empty ( )
let copy wl = wl . copy ( )
let member a wl = wl . member a
module Make = functor ( S : EqConstrSys ) -> functor ( HM : Hashtbl . S with type key = S . v ) -> struct include Generic . SolverStats ( S ) ( HM ) module VS = Set . Make ( S . Var ) open S . Dom let eq x get set = match S . system x with | None -> bot ( ) | Some f -> eval_rhs_event x ; f get set let solve _ st vs = let infl = HM . create 10 in let rho = HM . create 10 in let vs = ref ( VS . of_enum ( List . enum vs ) ) in let init x = new_var_event x ; HM . replace rho x ( bot ( ) ) ; HM . replace infl x VS . empty ; in let eval x y = get_var_event y ; HM . replace infl y ( VS . add x ( try HM . find infl y with Not_found -> VS . empty ) ) ; try HM . find rho y with Not_found -> new_var_event y ; HM . replace rho y ( bot ( ) ) ; vs := VS . add y ! vs ; bot ( ) in let set x d = let old = try HM . find rho x with Not_found -> init x ; bot ( ) in if not ( leq d old ) then begin update_var_event x old d ; HM . replace rho x ( join old d ) ; let q = try HM . find infl x with Not_found -> VS . empty in HM . replace infl x VS . empty ; vs := ( VS . fold VS . add q ! vs ) end in start_event ( ) ; let _ = List . iter ( fun ( x , d ) -> HM . add rho x d ) st in while not ( VS . is_empty ! vs ) do let x , vs ' = VS . pop ! vs in let _ = vs := vs ' in set x ( eq x ( eval x ) set ) done ; stop_event ( ) ; rho end
let _ = Selector . add_solver ( " WL " , ( module EqIncrSolverFromEqSolver ( Make ) ) ) ;
module Cell = struct module Type = struct type t = | Boolean | Error | Inline_string | Number | Shared_string | Formula_string [ @@ deriving sexp_of ] let of_string = function | " b " -> Boolean | " e " -> Error | " inlineStr " -> Inline_string | " n " -> Number | " s " -> Shared_string | " str " -> Formula_string | str -> failwithf " Expected ST_CellType but got ' % s ' " str ( ) end module Value = struct type t = | Inline of string | Rich_inline of Shared_string_table . String_item . t | Shared of uint32 [ @@ deriving sexp_of ] let to_string ~ shared_strings = function | Inline v -> v | Rich_inline v -> Shared_string_table . String_item . to_string v | Shared n -> let n = Uint32 . to_int n in shared_strings . ( n ) |> Shared_string_table . String_item . to_string let of_xml ~ data_type el = let open Xml in match data_type , el with | _ , Element ( " is " , _ , children ) -> let value = List . filter_map children ~ f : Shared_string_table . Rich_text . of_xml in Some ( Rich_inline value ) | Type . Shared_string , Element ( " v " , _ , children ) -> Some ( Shared ( Uint32 . of_string ( expect_pcdata children ) ) ) | _ , Element ( " v " , _ , children ) -> Some ( Inline ( expect_pcdata children ) ) | _ -> None end type t = { reference : string option ; formula : string option ; value : Value . t option ; cell_metadata_index : uint32 ; show_phonetic : bool ; style_index : uint32 ; data_type : Type . t ; value_metadata_index : uint32 } [ @@ deriving fields , sexp_of ] let column { reference ; _ } = ( Option . value_exn reference ~ here [ :% here ] |> String . to_list |> List . take_while ~ f : Char . is_alpha |> List . map ~ f : Char . uppercase |> List . map ~ f ( : fun c -> Char . to_int c - Char . to_int ' A ' + 1 ) |> List . fold ~ init : 0 ~ f ( : fun acc n -> acc * 26 + n ) ) - 1 let to_string ~ shared_strings { value ; _ } = Option . map value ~ f ( : Value . to_string ~ shared_strings ) |> Option . value ~ default " " : let default = { reference = None ; formula = None ; value = None ; cell_metadata_index = Uint32 . zero ; show_phonetic = false ; style_index = Uint32 . zero ; data_type = Type . Number ; value_metadata_index = Uint32 . zero } let of_xml = let open Xml in function | Element ( " c " , attrs , children ) -> let with_attrs = List . fold attrs ~ init : default ~ f ( : fun acc -> function | " r " , v -> { acc with reference = Some v } | " s " , v -> { acc with style_index = Uint32 . of_string v } | " t " , v -> { acc with data_type = Type . of_string v } | " cm " , v -> { acc with cell_metadata_index = Uint32 . of_string v } | " vm " , v -> { acc with value_metadata_index = Uint32 . of_string v } | " ph " , v -> { acc with show_phonetic = bool_of_xsd_boolean v } | _ -> acc ) in List . fold children ~ init : with_attrs ~ f ( : fun acc -> function | Element ( " f " , _ , children ) -> { acc with formula = Some ( expect_pcdata children ) } | el -> let value = Value . of_xml ~ data_type : with_attrs . data_type el in { acc with value = Option . first_some value acc . value } ) |> Option . some | _ -> None end
module Row = struct type t = { cells : Cell . t list ; collapsed : bool ; custom_format : bool ; custom_height : bool ; hidden : bool ; height : float option ; outline_level : uint8 ; show_phonetic : bool ; row_index : uint32 option ; style_index : uint32 ; thick_bottom_border : bool ; thick_top_border : bool } [ @@ deriving fields , sexp_of ] let default = { cells = [ ] ; collapsed = false ; custom_format = false ; custom_height = false ; hidden = false ; height = None ; outline_level = Uint8 . zero ; show_phonetic = false ; row_index = None ; style_index = Uint32 . zero ; thick_bottom_border = false ; thick_top_border = false } let of_xml = function | Xml . Element ( " row " , attrs , children ) -> let cells = List . filter_map children ~ f : Cell . of_xml in List . fold attrs ~ init { : default with cells } ~ f ( : fun acc -> function | " collapsed " , v -> { acc with collapsed = bool_of_xsd_boolean v } | " customFormat " , v -> { acc with custom_format = bool_of_xsd_boolean v } | " customHeight " , v -> { acc with custom_height = bool_of_xsd_boolean v } | " hidden " , v -> { acc with hidden = bool_of_xsd_boolean v } | " ht " , v -> { acc with height = Some ( Float . of_string v ) } | " outlineLevel " , v -> { acc with outline_level = Uint8 . of_string v } | " ph " , v -> { acc with show_phonetic = bool_of_xsd_boolean v } | " r " , v -> { acc with row_index = Some ( Uint32 . of_string v ) } | " s " , v -> { acc with style_index = Uint32 . of_string v } | " thickBot " , v -> { acc with thick_bottom_border = bool_of_xsd_boolean v } | " thickTop " , v -> { acc with thick_top_border = bool_of_xsd_boolean v } | _ -> acc ) |> Option . some | _ -> None end
module Column = struct type t = { best_fit : bool ; collapsed : bool ; custom_width : bool ; hidden : bool ; max : uint32 ; min : uint32 ; outline_level : uint8 ; show_phonetic : bool ; default_style : uint32 ; width : float option } [ @@ deriving fields , sexp_of ] let of_xml = function | Xml . Element ( " col " , attrs , _ ) -> let best_fit = ref false in let collapsed = ref false in let custom_width = ref false in let hidden = ref false in let max = ref None in let min = ref None in let outline_level = ref Uint8 . zero in let show_phonetic = ref false in let default_style = ref Uint32 . zero in let width = ref None in List . iter attrs ~ f ( : function | " bestFit " , v -> best_fit := bool_of_xsd_boolean v | " collapsed " , v -> collapsed := bool_of_xsd_boolean v | " customWidth " , v -> custom_width := bool_of_xsd_boolean v | " hidden " , v -> hidden := bool_of_xsd_boolean v | " max " , v -> max := Some ( Uint32 . of_string v ) | " min " , v -> min := Some ( Uint32 . of_string v ) | " outlineLevel " , v -> outline_level := Uint8 . of_string v | " phonetic " , v -> show_phonetic := bool_of_xsd_boolean v | " style " , v -> default_style := Uint32 . of_string v | " width " , v -> width := Some ( Float . of_string v ) | _ -> ( ) ) ; let max = require_attribute " col " " max " ! max in let min = require_attribute " col " " min " ! min in Some { best_fit = ! best_fit ; collapsed = ! collapsed ; custom_width = ! custom_width ; hidden = ! hidden ; max ; min ; outline_level = ! outline_level ; show_phonetic = ! show_phonetic ; default_style = ! default_style ; width = ! width } | _ -> None end
type t = { columns : Column . t list ; rows : Row . t list } [ @@ deriving fields , sexp_of ]
let default = { columns = [ ] ; rows = [ ] }
let of_xml = expect_element " worksheet " ( fun _ -> let open Xml in List . fold ~ init : default ~ f ( : fun acc -> function | Element ( " cols " , _ , children ) -> { acc with columns = List . filter_map children ~ f : Column . of_xml } | Element ( " sheetData " , _ , children ) -> { acc with rows = List . filter_map children ~ f : Row . of_xml } | _ -> acc ) )
type role = [ ` Chair | ` Co_chair ]
let role_to_string = function ` Chair -> " chair " | ` Co_chair -> " co - chair "
let role_of_string = function | " chair " -> Ok ` Chair | " co - chair " -> Ok ` Co_chair | _ -> Error ( ` Msg " Unknown role type ) "
let role_of_yaml = function | ` String s -> Result . bind ( role_of_string s ) s ( fun t -> Ok t ) t | _ -> Error ( ` Msg " Expected a string for a role type ) "
let role_to_yaml t = ` String ( role_to_string t ) t
type important_date = { date : string ; info : string } [ @@ deriving yaml ] yaml
type committee_member = { name : string ; role : role option ; affiliation : string option ; picture : string option ; }
type presentation = { title : string ; authors : string list ; link : string option ; video : string option ; slides : string option ; poster : bool option ; additional_links : string list option ; }
type metadata = { title : string ; location : string ; date : string ; important_dates : important_date list ; presentations : presentation list ; program_committee : committee_member list ; organising_committee : committee_member list ; }
let path = Fpath . v " data / workshops "
let parse content = let metadata , _ = Utils . extract_metadata_body content in metadata_of_yaml metadata
type t = { title : string ; slug : string ; location : string ; date : string ; important_dates : important_date list ; presentations : presentation list ; program_committee : committee_member list ; organising_committee : committee_member list ; toc_html : string ; body_md : string ; body_html : string ; }
let all ( ) = Utils . map_files ( fun content -> let metadata , body = Utils . extract_metadata_body content in let metadata = Utils . decode_or_raise metadata_of_yaml metadata in let omd = Omd . of_string body in { title = metadata . title ; slug = Utils . slugify metadata . title ; location = metadata . location ; date = metadata . date ; important_dates = metadata . important_dates ; presentations = metadata . presentations ; program_committee = metadata . program_committee ; organising_committee = metadata . organising_committee ; toc_html = Omd . to_html ( Omd . toc ~ depth : 4 omd ) omd ; body_md = body ; body_html = Omd . to_html omd ; } ) " workshops . /* md " |> List . sort ( fun w1 w2 -> String . compare w1 . date w2 . date ) date |> List . rev
let pp_role ppf = function | ` Chair -> Fmt . string ppf " ` Chair " | ` Co_chair -> Fmt . string ppf " ` Co_chair "
let pp_important_date ppf ( v : important_date ) important_date = Fmt . pf ppf { | { date = % a ; info = % a ; } } | Pp . string v . date Pp . string v . info
let pp_committee_member ppf ( v : committee_member ) committee_member = Fmt . pf ppf { | { name = % a ; role = % a ; affiliation = % a ; picture = % a ; } } | Pp . string v . name Pp ( . option pp_role ) pp_role v . role Pp ( . option string ) string v . affiliation Pp ( . option string ) string v . picture
let pp_presentation ppf ( v : presentation ) presentation = Fmt . pf ppf { | { title = % a ; authors = % a ; link = % a ; video = % a ; slides = % a ; poster = % a ; additional_links = % a ; } } | Pp . string v . title Pp . string_list v . authors Pp ( . option string ) string v . link Pp ( . option string ) string v . video Pp ( . option string ) string v . slides Pp ( . option Fmt . bool ) bool v . poster Pp ( . option string_list ) string_list v . additional_links
let pp ppf v = Fmt . pf ppf { | { title = % a ; slug = % a ; location = % a ; date = % a ; important_dates = % a ; presentations = % a ; program_committee = % a ; organising_committee = % a ; body_md = % a ; toc_html = % a ; body_html = % a } } | Pp . string v . title Pp . string v . slug Pp ( . string ) string v . location Pp . string v . date Pp ( . list pp_important_date ) pp_important_date v . important_dates Pp ( . list pp_presentation ) pp_presentation v . presentations Pp ( . list pp_committee_member ) pp_committee_member v . program_committee Pp ( . list pp_committee_member ) pp_committee_member v . organising_committee Pp . string v . body_md Pp . string v . toc_html Pp . string v . body_html
let pp_list = Pp . list pp
let template ( ) = Format . asprintf { |
type role = [ ` Chair | ` Co_chair ]
type important_date = { date : string ; info : string }
type committee_member = { name : string ; role : role option ; affiliation : string option ; picture : string option ; }
type presentation = { title : string ; authors : string list ; link : string option ; video : string option ; slides : string option ; poster : bool option ; additional_links : string list option ; }
type t = { title : string ; slug : string ; location : string ; date : string ; important_dates : important_date list ; presentations : presentation list ; program_committee : committee_member list ; organising_committee : committee_member list ; toc_html : string ; body_md : string ; body_html : string ; }
let all = % a } | pp_list ( all ( ) )
let env_field , env_field_lazy = let make f g = field " env " ~ default ( : f Dune_env . Stanza . empty ) ( g ( Dune_lang . Syntax . since syntax ( 1 , 1 ) >>> Dune_env . Stanza . decode ) ) in ( make Fun . id Fun . id , make Lazy . from_val lazy_ )
module Context = struct module Target = struct type t = | Native | Named of Context_name . t let equal x y = match ( x , y ) with | Native , Native -> true | Native , _ | _ , Native -> false | Named x , Named y -> Context_name . equal x y let t = let + context_name = Context_name . decode in match Context_name . to_string context_name with | " native " -> Native | _ -> Named context_name let add ts x = match x with | None -> ts | Some t -> if List . mem ts t ~ equal then ts else ts @ [ t ] end module Common = struct type t = { loc : Loc . t ; profile : Profile . t ; targets : Target . t list ; env : Dune_env . Stanza . t ; toolchain : Context_name . t option ; name : Context_name . t ; host_context : Context_name . t option ; paths : ( string * Ordered_set_lang . t ) list ; fdo_target_exe : Path . t option ; dynamically_linked_foreign_archives : bool ; instrument_with : Lib_name . t list ; merlin : bool } let to_dyn = Dyn . opaque let equal { loc = _ ; profile ; targets ; env ; toolchain ; name ; host_context ; paths ; fdo_target_exe ; dynamically_linked_foreign_archives ; instrument_with ; merlin } t = Profile . equal profile t . profile && List . equal Target . equal targets t . targets && Dune_env . Stanza . equal env t . env && Option . equal Context_name . equal toolchain t . toolchain && Context_name . equal name t . name && Option . equal Context_name . equal host_context t . host_context && List . equal ( Tuple . T2 . equal String . equal Ordered_set_lang . equal ) paths t . paths && Option . equal Path . equal fdo_target_exe t . fdo_target_exe && Bool . equal dynamically_linked_foreign_archives t . dynamically_linked_foreign_archives && List . equal Lib_name . equal instrument_with t . instrument_with && Bool . equal merlin t . merlin let fdo_suffix t = match t . fdo_target_exe with | None -> " " | Some file -> let name , _ = Path . split_extension file in " - fdo " - ^ Path . basename name let t = let + env = env_field and + targets = field " targets " ( repeat Target . t ) ~ default [ : Target . Native ] and + profile = field_o " profile " Profile . decode and + host_context = field_o " host " ( Dune_lang . Syntax . since syntax ( 1 , 10 ) >>> Context_name . decode ) and + toolchain = field_o " toolchain " ( Dune_lang . Syntax . since syntax ( 1 , 5 ) >>> Context_name . decode ) and + dynamically_linked_foreign_archives = let + disable = field ~ default : false " disable_dynamically_linked_foreign_archives " ( Dune_lang . Syntax . since syntax ( 2 , 0 ) >>> bool ) in not disable and + fdo_target_exe = let f file = let ext = Filename . extension file in if ext = " . exe " then Path . ( relative root file ) else User_error . raise [ Pp . textf " ` fdo % s ` expects executable filename ending with . exe \ extension , not % s . \ n \ Please specify the name of the executable to optimize , \ including path from < root . " > file ext ] in field_o " fdo " ( Dune_lang . Syntax . since syntax ( 2 , 0 ) >>> map string ~ f ) and + paths = let f l = match Env . Map . of_list ( List . map ~ f ( : fun ( ( loc , s ) , _ ) -> ( s , loc ) ) l ) with | Ok _ -> List . map ~ f ( : fun ( ( _ , s ) , x ) -> ( s , x ) ) l | Error ( var , _ , loc ) -> User_error . raise ~ loc [ Pp . textf " the variable % S can appear at most once in this stanza . " var ] in field " paths " ~ default [ ] : ( Dune_lang . Syntax . since Stanza . syntax ( 1 , 12 ) >>> map ~ f ( repeat ( pair ( located string ) Ordered_set_lang . decode ) ) ) and + instrument_with = field_o " instrument_with " ( Dune_lang . Syntax . since syntax ( 2 , 7 ) >>> repeat Lib_name . decode ) and + loc = loc and + merlin = field_b " merlin " in fun ~ profile_default ~ instrument_with_default -> let profile = Option . value profile ~ default : profile_default in let instrument_with = Option . value instrument_with ~ default : instrument_with_default in Option . iter host_context ~ f ( : fun _ -> match targets with | [ Target . Native ] -> ( ) | _ -> User_error . raise ~ loc [ Pp . text " ` targets ` and ` host ` options cannot be used in the same \ context . " ] ) ; { targets ; profile ; loc ; env ; name = Context_name . default ; host_context ; toolchain ; paths ; fdo_target_exe ; dynamically_linked_foreign_archives ; instrument_with ; merlin } end module Opam = struct type t = { base : Common . t ; switch : string ; root : string option } let to_dyn { base ; switch ; root } = let open Dyn in record [ ( " base " , Common . to_dyn base ) ; ( " switch " , string switch ) ; ( " root " , option string root ) ] let equal { base ; switch ; root } t = Common . equal base t . base && String . equal switch t . switch && Option . equal String . equal root t . root let t = let + loc_switch , switch = field " switch " ( located string ) and + name = field_o " name " Context_name . decode and + root = field_o " root " string and + base = Common . t in fun ~ profile_default ~ instrument_with_default ~ x -> let base = base ~ profile_default ~ instrument_with_default in let name = match name with | Some s -> s | None -> ( let name = switch ^ Common . fdo_suffix base in match Context_name . of_string_opt name with | Some s -> s | None -> User_error . raise ~ loc : loc_switch [ Pp . textf " Generated context name % S is invalid " name ; Pp . text " Please specify a context name manually with the ( name . . ) \ field " ] ) in let base = { base with targets = Target . add base . targets x ; name } in { base ; switch ; root } end module Default = struct type t = Common . t let to_dyn = Common . to_dyn let t = let + common = Common . t and + name = field_o " name " ( Dune_lang . Syntax . since syntax ( 1 , 10 ) >>= fun ( ) -> Context_name . decode ) in fun ~ profile_default ~ instrument_with_default ~ x -> let common = common ~ profile_default ~ instrument_with_default in let default = let name = Context_name . to_string common . name ^ Common . fdo_suffix common in Context_name . parse_string_exn ( Loc . none , name ) in let name = Option . value ~ default name in { common with targets = Target . add common . targets x ; name } let equal = Common . equal end type t = | Default of Default . t | Opam of Opam . t let hash = Hashtbl . hash let to_dyn = let open Dyn in function | Default d -> variant " Default " [ Default . to_dyn d ] | Opam o -> variant " Opam " [ Opam . to_dyn o ] let equal x y = match ( x , y ) with | Default x , Default y -> Default . equal x y | Opam x , Opam y -> Opam . equal x y | _ , _ -> false let loc = function | Default x -> x . loc | Opam x -> x . base . loc let host_context = function | Default { host_context ; _ } | Opam { base = { host_context ; _ } ; _ } -> host_context let t = sum [ ( " default " , let + f = fields Default . t in fun ~ profile_default ~ instrument_with_default ~ x -> Default ( f ~ profile_default ~ instrument_with_default ~ x ) ) ; ( " opam " , let + f = fields Opam . t in fun ~ profile_default ~ instrument_with_default ~ x -> Opam ( f ~ profile_default ~ instrument_with_default ~ x ) ) ] let env = function | Default d -> d . env | Opam o -> o . base . env let name = function | Default d -> d . name | Opam o -> o . base . name let targets = function | Default x -> x . targets | Opam x -> x . base . targets let all_names t = let n = name t in n :: List . filter_map ( targets t ) ~ f ( : function | Native -> None | Named s -> Some ( Context_name . target n ~ toolchain : s ) ) let default ~ x ~ profile ~ instrument_with = Default { loc = Loc . of_pos __POS__ ; targets = [ Option . value x ~ default : Target . Native ] ; profile = Option . value profile ~ default : Profile . default ; name = Context_name . default ; host_context = None ; env = Dune_env . Stanza . empty ; toolchain = None ; paths = [ ] ; fdo_target_exe = None ; dynamically_linked_foreign_archives = true ; instrument_with = Option . value instrument_with ~ default [ ] : ; merlin = false } let build_contexts t = let name = name t in let native = Build_context . create ~ name ~ host ( : host_context t ) in native :: List . filter_map ( targets t ) ~ f ( : function | Native -> None | Named toolchain -> let name = Context_name . target name ~ toolchain in Some ( Build_context . create ~ name ~ host ( : Some native . name ) ) ) end
type t = { merlin_context : Context_name . t option ; contexts : Context . t list ; env : Dune_env . Stanza . t ; config : Dune_config . t }
let to_dyn { merlin_context ; contexts ; env ; config } = let open Dyn in record [ ( " merlin_context " , option Context_name . to_dyn merlin_context ) ; ( " contexts " , list Context . to_dyn contexts ) ; ( " env " , Dune_env . Stanza . to_dyn env ) ; ( " config " , Dune_config . to_dyn config ) ]
let equal { merlin_context ; contexts ; env ; config } w = Option . equal Context_name . equal merlin_context w . merlin_context && List . equal Context . equal contexts w . contexts && Dune_env . Stanza . equal env w . env && Dune_config . equal config w . config
let hash { merlin_context ; contexts ; env ; config } = Hashtbl . hash ( Option . hash Context_name . hash merlin_context , List . hash Context . hash contexts , Dune_env . Stanza . hash env , Dune_config . hash config ) type t = unit end )
let ( ) = Lang . register syntax ( )
module Clflags = struct type t = { x : Context_name . t option ; profile : Profile . t option ; instrument_with : Lib_name . t list option ; workspace_file : Path . t option ; config_from_command_line : Dune_config . Partial . t ; config_from_config_file : Dune_config . Partial . t } let to_dyn { x ; profile ; instrument_with ; workspace_file ; config_from_command_line ; config_from_config_file } = let open Dyn in record [ ( " x " , option Context_name . to_dyn x ) ; ( " profile " , option Profile . to_dyn profile ) ; ( " instrument_with " , option ( list Lib_name . to_dyn ) instrument_with ) ; ( " workspace_file " , option Path . to_dyn workspace_file ) ; ( " config_from_command_line " , Dune_config . Partial . to_dyn config_from_command_line ) ; ( " config_from_config_file " , Dune_config . Partial . to_dyn config_from_config_file ) ] let t = Fdecl . create to_dyn let set v = Fdecl . set t v let t ( ) = Fdecl . get t end
let bad_configuration_check map = let find_exn loc name host = match Context_name . Map . find map host with | Some host_ctx -> host_ctx | None -> User_error . raise ~ loc [ Pp . textf " Undefined host context ' % s ' for ' % s ' . " ( Context_name . to_string host ) ( Context_name . to_string name ) ] in let check elt = Context . host_context elt |> Option . iter ~ f ( : fun host -> let name = Context . name elt in let loc = Context . loc elt in let host_elt = find_exn loc name host in Context . host_context host_elt |> Option . iter ~ f ( : fun host_of_host -> User_error . raise ~ loc ( : Context . loc host_elt ) [ Pp . textf " Context ' % s ' is both a host ( for ' % s ' ) and a target \ ( for ' % s ' ) . " ( Context_name . to_string host ) ( Context_name . to_string name ) ( Context_name . to_string host_of_host ) ] ) ) in Context_name . Map . iter map ~ f : check
let top_sort contexts = let key = Context . name in let map = Context_name . Map . of_list_map_exn contexts ~ f ( : fun x -> ( key x , x ) ) in let deps def = match Context . host_context def with | None -> [ ] | Some ctx -> [ Context_name . Map . find_exn map ctx ] in bad_configuration_check map ; match Context_name . Top_closure . top_closure ~ key ~ deps contexts with | Ok topo_contexts -> topo_contexts | Error _ -> assert false
let create_final_config ~ config_from_config_file ~ config_from_command_line ~ config_from_workspace_file = let ( ++ ) = Dune_config . superpose in Dune_config . default ++ config_from_config_file ++ config_from_workspace_file ++ config_from_command_line
module Step1 = struct type nonrec t = { t : t Lazy . t ; config : Dune_config . t } end
let step1 clflags = let { Clflags . x ; profile = cl_profile ; instrument_with = cl_instrument_with ; workspace_file = _ ; config_from_command_line ; config_from_config_file } = clflags in let x = Option . map x ~ f ( : fun s -> Context . Target . Named s ) in let superpose_with_command_line cl field = let + x = field in lazy ( Option . value cl ~ default ( : Lazy . force x ) ) in let * ( ) = Dune_lang . Versioned_file . no_more_lang and + env = env_field_lazy and + profile = superpose_with_command_line cl_profile ( field " profile " ( lazy_ Profile . decode ) ~ default ( : lazy Profile . default ) ) and + instrument_with = superpose_with_command_line cl_instrument_with ( field " instrument_with " ( lazy_ ( Dune_lang . Syntax . since Stanza . syntax ( 2 , 7 ) >>> repeat Lib_name . decode ) ) ~ default ( : lazy [ ] ) ) and + config_from_workspace_file = Dune_config . decode_fields_of_workspace_file in let + contexts = multi_field " context " ( lazy_ Context . t ) in let config = create_final_config ~ config_from_workspace_file ~ config_from_config_file ~ config_from_command_line in let t = lazy ( let profile = Lazy . force profile in let instrument_with = Lazy . force instrument_with in let contexts = List . map contexts ~ f ( : fun f -> Lazy . force f ~ profile_default : profile ~ instrument_with_default : instrument_with ~ x ) in let env = Lazy . force env in let defined_names = ref Context_name . Set . empty in let merlin_context = List . fold_left contexts ~ init : None ~ f ( : fun acc ctx -> let name = Context . name ctx in if Context_name . Set . mem ! defined_names name then User_error . raise ~ loc ( : Context . loc ctx ) [ Pp . textf " second definition of build context % S " ( Context_name . to_string name ) ] ; defined_names := Context_name . Set . union ! defined_names ( Context_name . Set . of_list ( Context . all_names ctx ) ) ; match ( ctx , acc ) with | Opam { base = { merlin = true ; _ } ; _ } , Some _ | Default { merlin = true ; _ } , Some _ -> User_error . raise ~ loc ( : Context . loc ctx ) [ Pp . text " you can only have one context for merlin " ] | Opam { base = { merlin = true ; _ } ; _ } , None | Default { merlin = true ; _ } , None -> Some name | _ -> acc ) in let contexts = match contexts with | [ ] -> [ Context . default ~ x ~ profile ( : Some profile ) ~ instrument_with ( : Some instrument_with ) ] | _ -> contexts in let merlin_context = match merlin_context with | Some _ -> merlin_context | None -> if List . exists contexts ~ f ( : function | Context . Default _ -> true | _ -> false ) then Some Context_name . default else None in { merlin_context ; contexts = top_sort ( List . rev contexts ) ; env ; config } ) in { Step1 . t ; config }
let step1 clflags = fields ( step1 clflags )
let default clflags = let { Clflags . x ; profile ; instrument_with ; workspace_file = _ ; config_from_command_line ; config_from_config_file } = clflags in let x = Option . map x ~ f ( : fun s -> Context . Target . Named s ) in let config = create_final_config ~ config_from_config_file ~ config_from_command_line ~ config_from_workspace_file : Dune_config . Partial . empty in { merlin_context = Some Context_name . default ; contexts = [ Context . default ~ x ~ profile ~ instrument_with ] ; env = Dune_env . Stanza . empty ; config }
let default_step1 clflags = let t = default clflags in { Step1 . t = lazy t ; config = t . config }
let load_step1 clflags p = Io . with_lexbuf_from_file p ~ f ( : fun lb -> if Dune_lexer . eof_reached lb then default_step1 clflags else parse_contents lb ~ f ( : fun lang -> String_with_vars . set_decoding_env ( Pform . Env . initial lang . version ) ( step1 clflags ) ) )
let workspace_step1 = let open Memo . O in let f ( ) = let clflags = Clflags . t ( ) in let + workspace_file = match clflags . workspace_file with | None -> let p = Path . of_string filename in let + exists = Fs_memo . file_exists p in Option . some_if exists p | Some p -> ( Fs_memo . file_exists p >>| function | true -> Some p | false -> User_error . raise [ Pp . textf " Workspace file % s does not exist " ( Path . to_string_maybe_quoted p ) ] ) in let clflags = { clflags with workspace_file } in match workspace_file with | None -> default_step1 clflags | Some p -> load_step1 clflags p in let memo = Memo . create " workspaces - internal " ~ input ( : module Unit ) f in Memo . exec memo
let workspace_config ( ) = let open Memo . O in let + step1 = workspace_step1 ( ) in step1 . config
let workspace = let open Memo . O in let f ( ) = let + step1 = workspace_step1 ( ) in Lazy . force step1 . t in let memo = Memo . create " workspace " ~ input ( : module Unit ) ~ cutoff : equal f in Memo . exec memo
let update_execution_parameters t ep = ep |> Execution_parameters . set_action_stdout_on_success t . config . action_stdout_on_success |> Execution_parameters . set_action_stderr_on_success t . config . action_stderr_on_success
let build_contexts t = List . concat_map t . contexts ~ f : Context . build_contexts
module Uri_map = Map . Make ( struct include Uri let compare x y = Ordering . of_int ( compare x y ) end )
type t = { workspace_folders : WorkspaceFolder . t Uri_map . t option ; root_uri : Uri . t option ; root_path : string option }
let create ( ip : InitializeParams . t ) = let workspace_folders = match ip . workspaceFolders with | None | Some None -> None | Some ( Some workspace_folders ) -> Uri_map . of_list_map_exn workspace_folders ~ f ( : fun ( ws : WorkspaceFolder . t ) -> ( ws . uri , ws ) ) |> Option . some in let root_uri = ip . rootUri in let root_path = match ip . rootPath with | None -> None | Some s -> s in { workspace_folders ; root_uri ; root_path }
let on_change t { DidChangeWorkspaceFoldersParams . event = { added ; removed } } = assert ( t . workspace_folders <> None ) ; let workspace_folders = let init = Option . value t . workspace_folders ~ default : Uri_map . empty in let init = List . fold_left removed ~ init ~ f ( : fun acc ( a : WorkspaceFolder . t ) -> Uri_map . remove acc a . uri ) in List . fold_left added ~ init ~ f ( : fun acc ( a : WorkspaceFolder . t ) -> Uri_map . set acc a . uri a ) |> Option . some in { t with workspace_folders }
let workspace_folders { root_uri ; root_path ; workspace_folders } = match workspace_folders with | Some s -> Uri_map . values s | None -> ( match ( workspace_folders , root_uri , root_path ) with | Some workspace_folders , _ , _ -> Uri_map . values workspace_folders | _ , Some root_uri , _ -> [ WorkspaceFolder . create ~ uri : root_uri ~ name ( : Filename . basename ( Uri . to_path root_uri ) ) ] | _ , _ , Some root_path -> [ WorkspaceFolder . create ~ uri ( : Uri . of_path root_path ) ~ name ( : Filename . basename root_path ) ] | _ -> let cwd = Sys . getcwd ( ) in [ WorkspaceFolder . create ~ uri ( : Uri . of_path cwd ) ~ name ( : Filename . basename cwd ) ] )
module Kind = struct type t = | Explicit | Dune_workspace | Dune_project | Cwd let priority = function | Explicit -> 0 | Dune_workspace -> 1 | Dune_project -> 2 | Cwd -> 3 let lowest_priority = max_int let of_dir_contents files = if String . Set . mem files Workspace . filename then Some Dune_workspace else if String . Set . mem files Dune_project . filename then Some Dune_project else None end
type t = { dir : string ; to_cwd : string list ; reach_from_root_prefix : string ; kind : Kind . t }
module Candidate = struct type t = { dir : string ; to_cwd : string list ; kind : Kind . t } end
let find ( ) = let cwd = Sys . getcwd ( ) in let rec loop counter ( ~ candidate : Candidate . t option ) ~ to_cwd dir : Candidate . t option = match Sys . readdir dir with | exception Sys_error msg -> User_warning . emit [ Pp . textf " Unable to read directory % s . Will not look for root in parent \ directories . " dir ; Pp . textf " Reason : % s " msg ; Pp . text " To remove this warning , set your root explicitly using -- root . " ] ; candidate | files -> let files = String . Set . of_list ( Array . to_list files ) in let candidate = let candidate_priority = match candidate with | Some c -> Kind . priority c . kind | None -> Kind . lowest_priority in match Kind . of_dir_contents files with | Some kind when Kind . priority kind <= candidate_priority -> Some { Candidate . kind ; dir ; to_cwd } | _ -> candidate in cont counter ~ candidate dir ~ to_cwd and cont counter ~ candidate ~ to_cwd dir = if counter > String . length cwd then candidate else let parent = Filename . dirname dir in if parent = dir then candidate else let base = Filename . basename dir in loop ( counter + 1 ) parent ~ candidate ~ to_cwd ( : base :: to_cwd ) in loop 0 ~ to_cwd [ ] : cwd ~ candidate : None
let create ~ default_is_cwd ~ specified_by_user = match match specified_by_user with | Some dn -> Some { Candidate . kind = Explicit ; dir = dn ; to_cwd = [ ] } | None -> ( let cwd = { Candidate . kind = Cwd ; dir = " . " ; to_cwd = [ ] } in if Dune_util . Config . inside_dune then Some cwd else match find ( ) with | Some s -> Some s | None -> if default_is_cwd then Some cwd else None ) with | Some { Candidate . dir ; to_cwd ; kind } -> { kind ; dir ; to_cwd ; reach_from_root_prefix = String . concat ~ sep " " : ( List . map to_cwd ~ f ( : sprintf " % s " ) ) / } | None -> User_error . raise [ Pp . text " I cannot find the root of the current workspace / project . " ; Pp . text " If you would like to create a new dune project , you can type " : ; Pp . nop ; Pp . verbatim " dune init project NAME " ; Pp . nop ; Pp . text " Otherwise , please make sure to run dune inside an existing project \ or workspace . For more information about how dune identifies the \ root of the current workspace / project , please refer to \ https :// dune . readthedocs . io / en / stable / usage . html # finding - the - root " ]
let browse_of_cmt ( cmt_infos : Cmt_format . cmt_infos ) : Browse_raw . node option = match cmt_infos . cmt_annots with | Implementation str -> Some ( Structure str ) | Interface sig_ -> Some ( Signature sig_ ) | Packed _ | Partial_implementation _ | Partial_interface _ -> None
let is_directory dir = try Sys . is_directory dir with Sys_error _ -> false
type error = Build_dir_not_found of string
let find_build_dir ( { name ; uri } : WorkspaceFolder . t ) = let build_dir = Filename . concat ( Uri . to_path uri ) " _build / default " in if is_directory build_dir then Ok build_dir else Error ( Build_dir_not_found name )
type cm_file = | Cmt of string | Cmti of string
let string_of_cm cm = match cm with | Cmt f | Cmti f -> f
module Outline : sig val get : Merlin_analysis . Browse_tree . t list -> Query_protocol . item list module Location = Loc open Merlin_utils open Merlin_analysis open Std open Option . Infix open Typedtree open Browse_raw open Browse_tree let id_of_patt = function | { pat_desc = Tpat_var ( id , _ ) ; _ } -> Some id | _ -> None let mk ( ? children = [ ] ) ~ location ~ deprecated outline_kind id = { Query_protocol . outline_kind ; outline_type = None ; location ; children ; outline_name = Ident . name id ; deprecated } let get_class_field_desc_infos = function | Typedtree . Tcf_val ( str_loc , _ , _ , _ , _ ) -> Some ( str_loc , ` Value ) | Typedtree . Tcf_method ( str_loc , _ , _ ) -> Some ( str_loc , ` Method ) | _ -> None let rec summarize node = let location = node . t_loc in match node . t_node with | Value_binding vb -> ( let deprecated = Type_utils . is_deprecated vb . vb_attributes in match id_of_patt vb . vb_pat with | None -> None | Some ident -> Some ( mk ~ location ~ deprecated ` Value ident ) ) | Value_description vd -> let deprecated = Type_utils . is_deprecated vd . val_attributes in Some ( mk ~ location ~ deprecated ` Value vd . val_id ) | Module_declaration md -> ( let children = get_mod_children node in match md . md_id with | None -> None | Some id -> let deprecated = Type_utils . is_deprecated md . md_attributes in Some ( mk ~ children ~ location ~ deprecated ` Module id ) ) | Module_binding mb -> ( let children = get_mod_children node in match mb . mb_id with | None -> None | Some id -> let deprecated = Type_utils . is_deprecated mb . mb_attributes in Some ( mk ~ children ~ location ~ deprecated ` Module id ) ) | Module_type_declaration mtd -> let children = get_mod_children node in let deprecated = Type_utils . is_deprecated mtd . mtd_attributes in Some ( mk ~ deprecated ~ children ~ location ` Modtype mtd . mtd_id ) | Type_declaration td -> let children = List . concat_map ( Lazy . force node . t_children ) ~ f ( : fun child -> match child . t_node with | Type_kind _ -> List . map ( Lazy . force child . t_children ) ~ f ( : fun x -> match x . t_node with | Constructor_declaration c -> let deprecated = Type_utils . is_deprecated c . cd_attributes in mk ` Constructor c . cd_id ~ deprecated ~ location : c . cd_loc | Label_declaration ld -> let deprecated = Type_utils . is_deprecated ld . ld_attributes in mk ` Label ld . ld_id ~ deprecated ~ location : ld . ld_loc | _ -> assert false ) | _ -> [ ] ) in let deprecated = Type_utils . is_deprecated td . typ_attributes in Some ( mk ~ children ~ location ~ deprecated ` Type td . typ_id ) | Type_extension te -> let name = Path . name te . tyext_path in let children = List . filter_map ( Lazy . force node . t_children ) ~ f ( : fun x -> summarize x >>| fun x -> { x with Query_protocol . outline_kind = ` Constructor } ) in let deprecated = Type_utils . is_deprecated te . tyext_attributes in Some { Query_protocol . outline_name = name ; outline_kind = ` Type ; outline_type = None ; location ; children ; deprecated } | Extension_constructor ec -> let deprecated = Type_utils . is_deprecated ec . ext_attributes in Some ( mk ~ location ` Exn ec . ext_id ~ deprecated ) | Class_declaration cd -> let children = List . concat_map ( Lazy . force node . t_children ) ~ f : get_class_elements in let deprecated = Type_utils . is_deprecated cd . ci_attributes in Some ( mk ~ children ~ location ` Class cd . ci_id_class_type ~ deprecated ) | _ -> None and get_class_elements node = match node . t_node with | Class_expr _ -> List . concat_map ( Lazy . force node . t_children ) ~ f : get_class_elements | Class_structure _ -> List . filter_map ( Lazy . force node . t_children ) ~ f ( : fun child -> match child . t_node with | Class_field cf -> ( match get_class_field_desc_infos cf . cf_desc with | Some ( str_loc , outline_kind ) -> let deprecated = Type_utils . is_deprecated cf . cf_attributes in Some { Query_protocol . outline_name = str_loc . Location . txt ; outline_kind ; outline_type = None ; location = str_loc . Location . loc ; children = [ ] ; deprecated } | None -> None ) | _ -> None ) | _ -> [ ] and get_mod_children node = List . concat_map ( Lazy . force node . t_children ) ~ f : remove_mod_indir and remove_mod_indir node = match node . t_node with | Module_expr _ | Module_type _ -> List . concat_map ( Lazy . force node . t_children ) ~ f : remove_mod_indir | _ -> remove_top_indir node and remove_top_indir t = match t . t_node with | Structure _ | Signature _ -> List . concat_map ~ f : remove_top_indir ( Lazy . force t . t_children ) | Signature_item _ | Structure_item _ -> List . filter_map ( Lazy . force t . t_children ) ~ f : summarize | _ -> [ ] let get browses = List . concat @@ List . rev_map ~ f : remove_top_indir browses end
let symbols_from_cm_file ~ filter root_uri cm_file = let cmt = let filename = string_of_cm cm_file in Cmt_format . read_cmt filename in match cmt . cmt_sourcefile with | None -> [ ] | Some sourcefile -> ( match Filename . extension sourcefile with | " . ml " | " . mli " -> ( match browse_of_cmt cmt with | None -> [ ] | Some browse -> let outline = let browse_tree = Merlin_analysis . Browse_tree . of_node browse in Outline . get [ browse_tree ] in let loc = Mbrowse . node_loc browse in let fname = loc . loc_start . pos_fname in let uri = Uri . of_path ( Filename . concat root_uri fname ) in filter ( Document_symbol . symbols_of_outline uri outline ) ) | _ -> [ ] )
let find_cm_files dir = let choose_file f1 f2 = match ( f1 , f2 ) with | ( Cmt _ as f ) , _ | _ , ( Cmt _ as f ) -> f | ( Cmti _ as f ) , Cmti _ -> f in let rec loop acc dir = let contents = Sys . readdir dir in Array . fold_left contents ~ init : acc ~ f ( : fun acc fname -> let path = Filename . concat dir fname in if is_directory path then loop acc path else match String . rsplit2 ~ on ' . ' : path with | Some ( path_without_ext , " cmt " ) -> String . Map . set acc path_without_ext ( Cmt path ) | Some ( path_without_ext , " cmti " ) -> ( let current_file = String . Map . find acc path_without_ext in let cmi_file = Cmti path in match current_file with | None -> String . Map . set acc path_without_ext cmi_file | Some current_file -> String . Map . set acc path_without_ext ( choose_file current_file cmi_file ) ) | _ -> acc ) in loop String . Map . empty dir |> String . Map . values
let run ( { query ; _ } : WorkspaceSymbolParams . t ) ( workspace_folders : WorkspaceFolder . t list ) = let filter = match query with | " " -> fun x -> x | query -> let re = Re . str query |> Re . compile in List . filter ~ f ( : fun ( symbol : SymbolInformation . t ) -> Re . execp re symbol . name ) in List . map workspace_folders ~ f ( : fun ( workspace_folder : WorkspaceFolder . t ) -> let open Result . O in let * build_dir = find_build_dir workspace_folder in Ok ( let cm_files = find_cm_files build_dir in let path = let uri = workspace_folder . uri in Uri . to_path uri in List . concat_map ~ f ( : symbols_from_cm_file ~ filter path ) cm_files ) )
module Make ( Inputs : Intf . Inputs_intf ) Inputs_intf = struct module Work_spec = Snark_work_lib . Work . Single . Spec module Job_status = struct type t = Assigned of Time . t let is_old ( Assigned at_time ) at_time ~ now ~ reassignment_wait = let max_age = Time . Span . of_ms ( Float . of_int reassignment_wait ) reassignment_wait in let delta = Time . diff now at_time in Time . Span ( . > ) delta max_age end module State = struct module Seen_key = struct module T = struct type t = Transaction_snark . Statement . t One_or_two . t [ @@ deriving compare , sexp , to_yojson , hash ] hash end include T include Comparable . Make ( T ) T end type t = { mutable available_jobs : ( Inputs . Transaction_witness . t , Inputs . Ledger_proof . t ) t Work_spec . t One_or_two . t list ; jobs_seen : ( Seen_key . t , Job_status . t ) t Hashtbl . t ; reassignment_wait : int } let init : reassignment_wait : int -> frontier_broadcast_pipe : Inputs . Transition_frontier . t option Pipe_lib . Broadcast_pipe . Reader . t -> logger : Logger . t -> t = fun ~ reassignment_wait ~ frontier_broadcast_pipe ~ logger -> let t = { available_jobs = [ ] ; jobs_seen = Hashtbl . create ( module Seen_key ) Seen_key ; reassignment_wait } in Pipe_lib . Broadcast_pipe . Reader . iter frontier_broadcast_pipe ~ f ( : fun frontier_opt -> ( match frontier_opt with | None -> [ % log debug ] debug " No frontier , setting available work to be empty " ; t . available_jobs <- [ ] | Some frontier -> Pipe_lib . Broadcast_pipe . Reader . iter ( Inputs . Transition_frontier . best_tip_pipe frontier ) frontier ~ f ( : fun _ -> let best_tip_staged_ledger = Inputs . Transition_frontier . best_tip_staged_ledger frontier in let start_time = Time . now ( ) in ( match Inputs . Staged_ledger . all_work_pairs best_tip_staged_ledger ~ get_state : ( Inputs . Transition_frontier . get_protocol_state frontier ) with | Error e -> [ % log fatal ] fatal " Error occured when updating available work : $ error " ~ metadata [ : ( " error " , Error_json . error_to_yojson e ) e ] | Ok new_available_jobs -> let end_time = Time . now ( ) in [ % log info ] info " Updating new available work took $ time ms " ~ metadata : [ ( " time " , ` Float ( Time . diff end_time start_time |> Time . Span . to_ms ) ) ] ; t . available_jobs <- new_available_jobs ) ; Deferred . unit ) |> Deferred . don ' t_wait_for ) ; Deferred . unit ) |> Deferred . don ' t_wait_for ; t let all_unseen_works t = List . filter t . available_jobs ~ f ( : fun js -> not @@ Hashtbl . mem t . jobs_seen ( One_or_two . map ~ f : Work_spec . statement js ) js ) let remove_old_assignments t ~ logger = let now = Time . now ( ) in Hashtbl . filteri_inplace t . jobs_seen ~ f ( : fun ~ key : work ~ data : status -> if Job_status . is_old status ~ now ~ reassignment_wait : t . reassignment_wait then ( [ % log info ] info ~ metadata [ : ( " work " , Seen_key . to_yojson work ) work ] " Waited too long to get work for $ work . Ready to be reassigned " ; Mina_metrics ( . Counter . inc_one Snark_work . snark_work_timed_out_rpc ) snark_work_timed_out_rpc ; false ) else true ) let remove t x = Hashtbl . remove t . jobs_seen ( One_or_two . map ~ f : Work_spec . statement x ) x let set t x = Hashtbl . set t . jobs_seen ~ key ( : One_or_two . map ~ f : Work_spec . statement x ) x ~ data ( : Job_status . Assigned ( Time . now ( ) ) ) end let does_not_have_better_fee ~ snark_pool ~ fee ( statements : Inputs . Transaction_snark_work . Statement . t ) t : bool = Option . value_map ~ default : true ( Inputs . Snark_pool . get_completed_work snark_pool statements ) statements ~ f ( : fun priced_proof -> let competing_fee = Inputs . Transaction_snark_work . fee priced_proof in Fee . compare fee competing_fee < 0 ) module For_tests = struct let does_not_have_better_fee = does_not_have_better_fee end let get_expensive_work ~ snark_pool ~ fee ( jobs : ( ' a , ' b ) ' b Work_spec . t One_or_two . t list ) list : ( ' a , ' b ) ' b Work_spec . t One_or_two . t list = List . filter jobs ~ f ( : fun job -> does_not_have_better_fee ~ snark_pool ~ fee ( One_or_two . map job ~ f : Work_spec . statement ) statement ) let all_pending_work ~ snark_pool statements = List . filter statements ~ f ( : fun st -> Option . is_none ( Inputs . Snark_pool . get_completed_work snark_pool st ) st ) let pending_work_statements ~ snark_pool ~ fee_opt ( state : State . t ) t = let all_todo_statements = List . map state . available_jobs ~ f ( : One_or_two . map ~ f : Work_spec . statement ) statement in let expensive_work statements ~ fee = List . filter statements ~ f ( : does_not_have_better_fee ~ snark_pool ~ fee ) fee in match fee_opt with | None -> all_pending_work ~ snark_pool all_todo_statements | Some fee -> expensive_work all_todo_statements ~ fee end
let anglex = ref 0 . 0
let angley = ref 30 . 0
let anglez = ref 0 . 0
let ball_radius = wall_size . / 3 . 0
let resting_space = spring_thickness . * spring_ncoils . + ( 2 . 0 . * ball_radius )
let left_offset = . - distance . / 4 . 0
let w1 = 0 . 0 . - ( wall_width . / 2 . 0 ) . - resting_space
let w2 = distance . + ( wall_width . / 2 . 0 ) . + resting_space
let lightOnePosition = ( 280 . 0 , 100 . 0 , 50 . 0 , 0 . 0 )
let lightAmbient = ( 0 . 5 , 0 . 5 , 0 . 5 , 1 . 0 )
let lightDiffuse = ( 0 . 2 , 0 . 2 , 0 . 2 , 1 . 0 )