123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566open!Coreopen!ImportmodulePrevious_update_kind=structtypet=|Never_been_updated|Necessary|Changed|Invalidated|Unnecessary[@@derivingsexp_of]endmoduleNode_update=structtype'at=|Necessaryof'a|Changedof'a*'a|Invalidated|Unnecessary[@@derivingcompare,sexp_of]endtype'at={f:'aNode_update.t->unit;mutableprevious_update_kind:Previous_update_kind.t;created_at:Stabilization_num.t}[@@derivingsexp_of]letcreatef~at:created_at={f;previous_update_kind=Never_been_updated;created_at}letreally_runt(node_update:_Node_update.t)=t.previous_update_kind<-(matchnode_updatewith|Necessary_->Necessary|Changed_->Changed|Invalidated->Invalidated|Unnecessary->Unnecessary);t.fnode_update;;letrunt(node_update:_Node_update.t)~now=(* We only run the handler if was created in an earlier stabilization cycle. If the
handler was created by another on-update handler during the running of on-update
handlers in the current stabilization, we treat the added handler as if it were added
after this stabilization finished. We will run it at the next stabilization, because
the node with the handler was pushed on [state.handle_after_stabilization]. *)ifStabilization_num.comparet.created_atnow<0then(matcht.previous_update_kind,node_updatewith(* Once a node is invalidated, there will never be further information to provide,
since incremental does not allow an invalid node to become valid. *)|Invalidated,_->()(* These cases can happen if a node is handled after stabilization due to another
handler. But for the current handler, there is nothing to do because there is no
new information to provide. *)|Changed,Necessary_|Necessary,Necessary_|Unnecessary,Unnecessary->()(* If this handler hasn't seen a node that is changing, we treat the update as an
initialization. *)|(Never_been_updated|Unnecessary),Changed(_,a)->really_runt(Necessarya)(* All other updates are run as is. *)|Never_been_updated,(Necessary_|Unnecessary|Invalidated)|Unnecessary,(Necessary_|Invalidated)|Necessary,(Changed_|Unnecessary|Invalidated)|Changed,(Changed_|Unnecessary|Invalidated)->really_runtnode_update);;