Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file incremental.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508(* This module is mostly a wrapper around [State] functions. *)open!Coreopen!ImportincludeIncremental_intfmoduletypeIncremental_config=Config.Incremental_configmoduleConfig=Configletdefault_max_height_allowed=128moduleGeneric=structmoduleCutoff=CutoffmoduleStep_function=Step_functionmoduleState=structincludeStatemoduletypeS=sigtypestate_witness[@@derivingsexp_of]valt:tendletcreate_internal=createletcreate?(max_height_allowed=default_max_height_allowed)():(moduleS)=(modulestructtypestate_witness[@@derivingsexp_of]lett=create(moduleConfig.Default())~max_height_allowedend);;endmoduleScope=structincludeScopeletcurrent(state:State.t)()=state.current_scopeletwithinstatet~f=State.within_scopestatet~fendincludeNodeletstatet=t.stateletpackt=Packed.Ttletconststatea=State.conststatealetreturn=constletobserve=State.create_observerletmap=State.mapletbind=State.bindmoduleN_ary_map_and_bind=structletmap2=State.map2letmap3=State.map3letmap4=State.map4letmap5=State.map5letmap6=State.map6letmap7=State.map7letmap8=State.map8letmap9=State.map9letmap10=State.map10letmap11=State.map11letmap12=State.map12letmap13=State.map13letmap14=State.map14letmap15=State.map15letbind2=State.bind2letbind3=State.bind3letbind4=State.bind4endincludeN_ary_map_and_bindmoduleInfix=structlet(>>|)tf=mapt~flet(>>=)tf=bindt~fendincludeInfixletjoin=State.joinletif_=State.if_letlazy_from_funstatef=State.lazy_from_funstate~fletdefault_hash_table_initial_size=State.default_hash_table_initial_sizeletmemoize_fun_by_key=State.memoize_fun_by_keyletmemoize_fun?initial_sizestatehashablef=memoize_fun_by_keystate?initial_sizehashableFn.idf;;letarray_foldstatets~init~f=State.array_foldstatets~init~fletreduce_balancedstatets~f~reduce=Reduce_balanced.createstatets~f~reducemoduleUnordered_array_fold_update=State.Unordered_array_fold_updateletunordered_array_fold=State.unordered_array_foldletopt_unordered_array_fold=State.opt_unordered_array_foldletall=State.allletexists=State.existsletfor_all=State.for_allletboth=State.bothletsum=State.sumletopt_sum=State.opt_sumletsum_int=State.sum_intletsum_float=State.sum_floatmoduleVar=structincludeVarletcreate=State.create_varletset=State.set_varletvaluet=t.valueletwatcht=t.watch(* We override [sexp_of_t] to just show the value, rather than the internal
representation. *)letsexp_of_tsexp_of_at=t.value|>[%sexp_of:a]letreplacet~f=sett(f(latest_valuet))endmoduleObserver=structincludeObservermoduleUpdate=structtype'at=|Initializedof'a|Changedof'a*'a|Invalidated[@@derivingcompare,sexp_of]endleton_update_exnt~(f:_Update.t->unit)=State.observer_on_update_exnt~f:(function|Necessarya->f(Initializeda)|Changed(a1,a2)->f(Changed(a1,a2))|Invalidated->fInvalidated|Unnecessary->failwiths~here:[%here]"Incremental bug -- Observer.on_update_exn got unexpected update Unnecessary"t[%sexp_of:_t]);;letdisallow_future_uset=State.disallow_future_use!tletvalue=State.observer_valueletvalue_exn=State.observer_value_exn(* We override [sexp_of_t] to just show the value, rather than the internal
representation. *)letsexp_of_tsexp_of_a(t:_t)=match!t.statewith|Created->[%message"<unstabilized>"]|Disallowed|Unlinked->[%message"<disallowed>"]|In_use->letuopt=!t.observing.value_optinifUopt.is_noneuoptthen[%message"<invalid>"]else[%sexp(Uopt.unsafe_valueuopt:a)];;endmoduleBefore_or_after=Before_or_aftermoduleClock=structincludeState.Clockletstate=incr_stateletdefault_timing_wheel_config=letalarm_precision=Alarm_precision.about_one_millisecondinletlevel_bits=[14;13;5]inTiming_wheel.Config.create~alarm_precision~level_bits:(Timing_wheel.Level_bits.create_exnlevel_bits~extend_to_max_num_bits:true)();;letcreatestate?(timing_wheel_config=default_timing_wheel_config)~start()=(* Make sure [start] is rounded to the nearest microsecond. Otherwise, if you
feed [Clock.now ()] to a time function, it can be rounded down to a time in
the past, causing errors. *)letstart=Time_ns.of_time_float_round_nearest_microsecond(Time_ns.to_time_float_round_nearest_microsecondstart)inState.create_clockstate~timing_wheel_config~start;;letalarm_precisiont=Timing_wheel.alarm_precisiont.timing_wheellettiming_wheel_length=State.timing_wheel_lengthletnow=State.nowletwatch_nowt=t.now.watchletat=State.atletafter=State.afterletat_intervals=State.at_intervalsletadvance_clock=State.advance_clockletadvance_clock_bytspan=advance_clockt~to_:(Time_ns.add(nowt)span)letincremental_step_function=State.incremental_step_functionletstep_functiont~initsteps=incremental_step_functiont(const(incr_statet)(Step_function.create_exn~init~steps));;letsnapshot=State.snapshotendletfreeze?(when_=fun_->true)t=State.freezet~only_freeze_when:when_letdepend_ont~depend_on=State.depend_ont~depend_onletnecessary_if_alive=State.necessary_if_alivemoduleUpdate=On_update_handler.Node_updateleton_update=State.node_on_updateletstabilizestate=State.stabilizestateletam_stabilizingstate=State.am_stabilizingstateletsave_dot=State.save_dotletsave_dot_to_file=State.save_dot_to_filemoduleNode_value=structtype'at=|Invalid|Necessary_maybe_staleof'aoption|Unnecessary_maybe_staleof'aoption[@@derivingsexp_of]endletnode_valuet:_Node_value.t=ifnot(is_validt)thenInvalidelseifis_necessarytthenNecessary_maybe_stale(Uopt.to_optiont.value_opt)elseUnnecessary_maybe_stale(Uopt.to_optiont.value_opt);;(* We override [sexp_of_t] to show just the value, rather than the internal
representation. We only show the value if it is necessary and valid. *)letsexp_of_tsexp_of_at=ifnot(is_validt)then"<invalid>"|>[%sexp_of:string]elseifnot(is_necessaryt)then"<unnecessary>"|>[%sexp_of:string]elseifUopt.is_nonet.value_optthen"<uncomputed>"|>[%sexp_of:string]elseunsafe_valuet|>[%sexp_of:a];;moduleExpert=Expert1moduleLet_syntax=structletreturn=returnlet(>>|)=(>>|)let(>>=)=(>>=)moduleLet_syntax=structletbind=bindletmap=mapletbotht1t2=map2t1t2~f:(funx1x2->x1,x2)includeN_ary_map_and_bindmoduleOpen_on_rhs=structletwatch=Var.watchendendendletweak_memoize_fun_by_key=State.weak_memoize_fun_by_keyletweak_memoize_fun?initial_sizestatehashablef=weak_memoize_fun_by_key?initial_sizestatehashableFn.idf;;endmoduleMake_with_config(Incremental_config:Incremental_config)()=structtypestate_witness[@@derivingsexp_of]includeGenericmoduleState=structincludeStatelett=create_internal(moduleIncremental_config)~max_height_allowed:128endmoduleClock=structincludeClockletcreate?timing_wheel_config~start()=create?timing_wheel_configState.t~start();;endmoduleExpert=structincludeExpertmoduleNode=structincludeNodeletcreate?on_observability_changef=createState.t?on_observability_changefendmoduleStep_result=State.Step_resultletdo_one_step_of_stabilize()=State.do_one_step_of_stabilizeState.tendmoduleLet_syntax=structincludeLet_syntaxletreturna=returnState.tamoduleLet_syntax=structincludeLet_syntaxletreturn=returnendendmoduleScope=structincludeScopeletcurrent()=currentState.t()letwithint~f=withinState.tt~fendmoduleVar=structincludeVarletcreate?use_current_scopevalue=create?use_current_scopeState.tvalueendletconsta=constState.taletreturna=returnState.taletallts=allState.ttsletexiststs=existsState.ttsletfor_allts=for_allState.ttsletlazy_from_funstatef=State.lazy_from_funstate~fletmemoize_fun_by_key?initial_sizehashableproject_keyf=memoize_fun_by_key?initial_sizeState.thashableproject_keyf;;letmemoize_fun?initial_sizehashablef=memoize_fun?initial_sizeState.thashablefletarray_foldts~init~f=array_foldState.tts~init~fletreduce_balancedts~f~reduce=reduce_balancedState.tts~f~reduceletunordered_array_fold?full_compute_every_n_changests~init~f~update=unordered_array_foldState.tts~init~f~update?full_compute_every_n_changes;;letopt_unordered_array_fold?full_compute_every_n_changests~init~f~f_inverse=opt_unordered_array_fold?full_compute_every_n_changesState.tts~init~f~f_inverse;;letsum?full_compute_every_n_changests~zero~add~sub=sum?full_compute_every_n_changesState.tts~zero~add~sub;;letopt_sum?full_compute_every_n_changests~zero~add~sub=opt_sum?full_compute_every_n_changesState.tts~zero~add~sub;;letsum_intts=sum_intState.ttsletsum_floatts=sum_floatState.ttsletstabilize()=stabilizeState.tletam_stabilizing()=am_stabilizingState.tletsave_dotout=save_dotState.toutletsave_dot_to_filefile=Out_channel.with_filefile~f:save_dotletlazy_from_funf=lazy_from_funState.tfletweak_memoize_fun_by_key?initial_sizehashableproject_keyf=weak_memoize_fun_by_key?initial_sizeState.thashableproject_keyf;;letweak_memoize_fun?initial_sizehashablef=weak_memoize_fun?initial_sizeState.thashablef;;endmoduleMake()=Make_with_config(Config.Default())()includeGenericmoduleAdd_witness0(M:sigtypet[@@derivingsexp_of]includeInvariant.Swithtypet:=tend):sigtype'wt=M.t[@@derivingsexp_of]includeInvariant.S1withtype'at:='atend=structtype'wt=M.tletinvariant_t=M.invarianttletsexp_of_t_t=M.sexp_of_ttendmoduleAdd_witness1(M:sigtype'at[@@derivingsexp_of]includeInvariant.S1withtype'at:='atend):sigtype('a,'w)t='aM.t[@@derivingsexp_of]includeInvariant.S2withtype('a,'b)t:=('a,'b)tend=structtype('a,'w)t='aM.tletinvariantinvariant_a_t=M.invariantinvariant_atletsexp_of_tsexp_of_a_t=M.sexp_of_tsexp_of_atendmoduleClock=structincludeClockincludeAdd_witness0(Clock)endmoduleExpert=structincludeExpertmoduleDependency=structincludeDependencyincludeAdd_witness1(structincludeDependencyletinvariant__=()end)endmoduleNode=structincludeNodeincludeAdd_witness1(structincludeNodeletinvariant__=()end)endmoduleStep_result=State.Step_resultletdo_one_step_of_stabilizestate=State.do_one_step_of_stabilizestateendmoduleNode=structincludeNodeincludeAdd_witness1(Node)endtype('a,'w)t=('a,'w)Node.t[@@derivingsexp_of]type('a,'w)incremental=('a,'w)tletinvariant=Node.invariantmoduleObserver=structincludeObserverincludeAdd_witness1(Observer)endmoduleScope=structincludeScopeincludeAdd_witness0(Scope)endmoduleState=structincludeStateincludeAdd_witness0(State)endmoduleVar=structincludeVarincludeAdd_witness1(Var)endmoduletypeS=sigtypestate_witness[@@derivingsexp_of]includeS_genwithtype'at=('a,state_witness)incrementalwithtypeBefore_or_after.t=Before_or_after.twithtypeClock.t=state_witnessClock.twithtype'aCutoff.t='aCutoff.twithtype'aExpert.Dependency.t=('a,state_witness)Expert.Dependency.twithtype'aExpert.Node.t=('a,state_witness)Expert.Node.twithtypeExpert.Step_result.t=Expert.Step_result.twithtype'aObserver.t=('a,state_witness)Observer.twithtype'aObserver.Update.t='aObserver.Update.twithtypePacked.t=Packed.twithtypeScope.t=state_witnessScope.twithtypeState.t=state_witnessState.twithtypeState.Stats.t=State.Stats.twithtype('a,'b)Unordered_array_fold_update.t=('a,'b)Unordered_array_fold_update.twithtype'aUpdate.t='aUpdate.twithtype'aVar.t=('a,state_witness)Var.tendmodulePrivate=structletdebug=debugend