import Base import ./change_tick.bend as Tick import ./ordinary_machine_initialization.bend as Init import ./ordinary_machine_declaration.bend as OD import ./ordinary_machine_handler_bundle.bend as Classic import ./ordinary_machine_handler_bundle_context.bend as Operation import ./trace_facts.bend as Facts import ./ordinary_machine_schedule.bend as Ordinary import ./machine_handler_bundle.bend as B import ./machine_handler_phases.bend as Phase import ./machine_handlers.bend as H import ./machine_stream.bend as St import ./machine.bend as M import ./world.bend as W import ./system.bend as Sys import ./schedule.bend as Sch import ./event_runtime.bend as Ev def take_world(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World) -> W.World & M.Slot: W.observe_resource(~S,~C,~R,~E,~M.Slot,~Init.take_slot(~S,~K,~V,~R,~take,~put),world) def put_resource(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~same:V -> V -> Bool,resource:R,value:M.Slot) -> R & Unit: (Init.put_slot(~S,~K,~V,~R,~take,~put,~same,resource,value),Unit{}) def returned_world(~S:Data,~C:Type,~R:Type,~E:Data,pair:W.World & Unit) -> W.World: match pair: case (world,_):world def put_world(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~same:V -> V -> Bool,world:W.World,value:M.Slot) -> W.World: returned_world(~S,~C,~R,~E,Init.with_resource(~S,~C,~R,~E,~Unit,(resource => put_resource(~S,~K,~V,~R,~take,~put,~C,~E,~same,resource,value)),world)) def stream_taken(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,pair:R & Init.State) -> R & St.Stream: match pair: case (resource,Init.State{slot,+stream,revision}):(put(resource,Init.State{slot,stream,revision}),stream) def stream_put_taken(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,stream:St.Stream,pair:R & Init.State) -> R & Unit: match pair: case (resource,Init.State{slot,_,revision}):(put(resource,Init.State{slot,stream,revision}),Unit{}) def stream_put(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World,stream:St.Stream) -> W.World: returned_world(~S,~C,~R,~E,Init.with_resource(~S,~C,~R,~E,~Unit,(resource => stream_put_taken(~S,~K,~V,~R,~take,~put,~C,~E,stream,take(resource))),world)) def published(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,tick:Nat,event:M.Transition,pair:W.World & St.Stream) -> W.World: match pair: case (world,stream):stream_put(~S,~K,~V,~R,~take,~put,~C,~E,world,St.publish(~V,stream,tick,event)) def publish_clocked(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,event:M.Transition,pair:W.World & Tick.Tick) -> W.World: match pair: case (world,tick):published(~S,~K,~V,~R,~take,~put,~C,~E,Tick.total(tick),event,W.observe_resource(~S,~C,~R,~E,~St.Stream,~(resource => stream_taken(~S,~K,~V,~R,~take,~put,~C,~E,take(resource))),world)) # Stream publication advances administrative time independently of component run ticks. def publish(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World,event:M.Transition) -> W.World: publish_clocked(~S,~K,~V,~R,~take,~put,~C,~E,event,W.advance_clock(~S,~C,~R,~E,world)) def last(~V:Data,items:List<&2,M.Transition>,prior:Maybe<&2,M.Transition>) -> Maybe<&2,M.Transition>: match items: case []:prior case value <> tail:last(~V,tail,Some{value}) type Opening is Type: Opened{world:W.World,reader:St.Reader,latest:Maybe<&2,M.Transition>,readThrough:Nat} OpenRejected{world:W.World,reader:St.Reader} def opened_finished(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World,latest:Maybe<&2,M.Transition>,tick:Nat,pair:St.Reader & St.Stream) -> Opening: match pair: case (reader,stream):Opened{stream_put(~S,~K,~V,~R,~take,~put,~C,~E,world,stream),reader,latest,tick} def opened(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World,+tick:Nat,result:St.OpenResult) -> Opening: match result: case St.ReaderRefused{reader,stream}:OpenRejected{stream_put(~S,~K,~V,~R,~take,~put,~C,~E,world,stream),reader} case St.Opened{reader,stream,Ev.Reading{values,_}}:opened_finished(~S,~K,~V,~R,~take,~put,~C,~E,world,last(~V,values,None{}),tick,St.finish(~S,~K,~V,reader,stream,tick,True{})) def open_stream(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,namespace:U32,+tick:Nat,pair:W.World & St.Stream) -> Opening: match pair: case (world,stream):opened(~S,~K,~V,~R,~take,~put,~C,~E,world,tick,St.open(~S,~K,~V,reader,stream,namespace,tick)) def open_clocked(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,namespace:U32,pair:W.World & Tick.Tick) -> Opening: match pair: case (world,tick):open_stream(~S,~K,~V,~R,~take,~put,~C,~E,reader,namespace,Tick.total(tick),W.observe_resource(~S,~C,~R,~E,~St.Stream,~(resource => stream_taken(~S,~K,~V,~R,~take,~put,~C,~E,take(resource))),world)) def open_namespaced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,pair:W.World & U32) -> Opening: match pair: case (world,namespace):open_clocked(~S,~K,~V,~R,~take,~put,~C,~E,reader,namespace,W.clock(~S,~C,~R,~E,world)) def open(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,world:W.World) -> Opening: open_namespaced(~S,~K,~V,~R,~take,~put,~C,~E,reader,W.namespace(~S,~C,~R,~E,world)) def reader_trace(~name:String,state:Facts.State,namespace:U32,+id:U32,lagged:Bool) -> Facts.State: match state: case Facts.Off{}:Facts.Off{} case Facts.On{facts}:Facts.On{Facts.ReaderFact{namespace,id,"machine." ++ name ++ ".initial-marker",id,"machine." ++ name ++ ".transition",lagged} <> facts} def opened_traced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~name:String,world:W.World,+tick:Nat,result:St.OpenResult,trace:Facts.State) -> Opening & Facts.State: match result: case St.ReaderRefused{reader,stream}:(opened(~S,~K,~V,~R,~take,~put,~C,~E,world,tick,St.ReaderRefused{reader,stream}),trace) case St.Opened{St.Reader{+namespace,+id},stream,Ev.Reading{values,+lagged}}:(opened(~S,~K,~V,~R,~take,~put,~C,~E,world,tick,St.Opened{St.Reader{namespace,id},stream,Ev.Reading{values,lagged}}),reader_trace(~name,trace,namespace,id,lagged)) def open_stream_traced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~name:String,reader:St.Reader,namespace:U32,+tick:Nat,pair:W.World & St.Stream,trace:Facts.State) -> Opening & Facts.State: match pair: case (world,stream):opened_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,world,tick,St.open(~S,~K,~V,reader,stream,namespace,tick),trace) def open_clocked_traced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~name:String,reader:St.Reader,namespace:U32,pair:W.World & Tick.Tick,trace:Facts.State) -> Opening & Facts.State: match pair: case (world,tick):open_stream_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,namespace,Tick.total(tick),W.observe_resource(~S,~C,~R,~E,~St.Stream,~(resource => stream_taken(~S,~K,~V,~R,~take,~put,~C,~E,take(resource))),world),trace) def open_namespaced_traced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~name:String,reader:St.Reader,pair:W.World & U32,trace:Facts.State) -> Opening & Facts.State: match pair: case (world,namespace):open_clocked_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,namespace,W.clock(~S,~C,~R,~E,world),trace) def open_traced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~name:String,reader:St.Reader,world:W.World,trace:Facts.State) -> Opening & Facts.State: open_namespaced_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,W.namespace(~S,~C,~R,~E,world),trace) def completed_stream(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,world:W.World,pair:St.Reader & St.Stream) -> W.World & St.Reader: match pair: case (reader,stream):(stream_put(~S,~K,~V,~R,~take,~put,~C,~E,world,stream),reader) def complete_taken(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,tick:Nat,success:Bool,pair:W.World & St.Stream) -> W.World & St.Reader: match pair: case (world,stream):completed_stream(~S,~K,~V,~R,~take,~put,~C,~E,world,St.finish(~S,~K,~V,reader,stream,tick,success)) def complete_clocked(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,success:Bool,pair:W.World & Tick.Tick) -> W.World & St.Reader: match pair: case (world,tick):complete_taken(~S,~K,~V,~R,~take,~put,~C,~E,reader,Tick.total(tick),success,W.observe_resource(~S,~C,~R,~E,~St.Stream,~(resource => stream_taken(~S,~K,~V,~R,~take,~put,~C,~E,take(resource))),world)) def complete(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,reader:St.Reader,success:Bool,world:W.World) -> W.World & St.Reader: complete_clocked(~S,~K,~V,~R,~take,~put,~C,~E,reader,success,W.clock(~S,~C,~R,~E,world)) type Owners -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: Owners{ordinary:Operation.Owners,reader:St.Reader,readThrough:Nat} type ObservedMarkerRun -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: ObservedMarkerRun{reader:St.Reader,result:Operation.MarkerResult} def opened_for_owners(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,ordinary:Operation.Owners,pair:Opening & Facts.State) -> Operation.Owners & Opening: match pair: case (opened,trace):(Operation.replaced_trace(~S,~K,~V,~Q,~C,~R,~E,~runner,ordinary,trace),opened) def open_for_owners(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,ordinary:Operation.Owners,reader:St.Reader,world:W.World) -> Operation.Owners & Opening: match ordinary: case Operation.Pending{entries,trace}:opened_for_owners(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,Operation.Pending{entries,Facts.Off{}},open_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,world,trace)) case Operation.Unavailable{entries,trace}:opened_for_owners(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,Operation.Unavailable{entries,Facts.Off{}},open_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,world,trace)) case Operation.Selected{positions,kept,active,phase,trace}:opened_for_owners(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,Operation.Selected{positions,kept,active,phase,Facts.Off{}},open_traced(~S,~K,~V,~R,~take,~put,~C,~E,~name,reader,world,trace)) def initial_partition(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,namespace:U32,to:V,partition:B.Partition,trace:Facts.State) -> Operation.Owners: match partition: case B.Partition{positions,kept,handlers}:Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.InitialReady{to}},H.Enter{},trace} def initial_selected(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,ordinary:Operation.Owners,opened:Opening) -> Owners & Sys.Outcome,String,Unit>: match ordinary opened: case Operation.Pending{entries,trace} Opened{world,reader,Some{M.Initial{+to}},through}:(Owners{initial_partition(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,0,to,B.partition_initial(~S,~K,~V,~Q,~C,~R,~E,~runner,~same,entries,to),trace),reader,through},Sys.Succeeded{world,Unit{}}) case Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.Idle{}},phase,trace} Opened{world,reader,Some{M.Initial{to}},through}:(Owners{Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.InitialReady{to}},phase,trace},reader,through},Sys.Succeeded{world,Unit{}}) case ordinary Opened{world,reader,_,through}:(Owners{ordinary,reader,through},Sys.Succeeded{world,Unit{}}) case ordinary OpenRejected{world,reader}:(Owners{ordinary,reader,0n},Sys.Failed{world,"InitialReaderRejected"}) def initial_opened(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,pair:Operation.Owners & Opening) -> Owners & Sys.Outcome,String,Unit>: match pair: case (ordinary,opened):initial_selected(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,ordinary,opened) def apply_observed(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,reader:St.Reader,result:Operation.Owners & Sys.Outcome,String,Unit>) -> Owners & Sys.Outcome,String,Unit>: match result: case (ordinary,Sys.Failed{world,error}):(Owners{ordinary,reader,0n},Sys.Failed{world,error}) case (Operation.Unavailable{entries,trace},Sys.Succeeded{world,_}):(Owners{Operation.Unavailable{entries,trace},reader,0n},Sys.Succeeded{world,Unit{}}) case (Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.Ready{from,to,skip}},phase,trace},Sys.Succeeded{world,_}):(Owners{Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.Ready{from,to,skip}},phase,trace},reader,0n},Sys.Succeeded{world,Unit{}}) case (ordinary,Sys.Succeeded{world,_}):initial_opened(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,open_for_owners(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,ordinary,reader,world)) def apply(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World) -> Owners & Sys.Outcome,String,Unit>: match owners: case Owners{ordinary,reader,_}:apply_observed(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,reader,Operation.apply(~S,~K,~V,~Q,~C,~R,~E,~runner,~observed,~name,~take_world(~S,~K,~V,~R,~take,~put,~C,~E),~put_world(~S,~K,~V,~R,~take,~put,~C,~E,~same),~publish(~S,~K,~V,~R,~take,~put,~C,~E),~same,~requirement_same,~has,~frame,ordinary,world)) def phase_returned(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,reader:St.Reader,through:Nat,result:Operation.Owners & Sys.Outcome,String,Unit>) -> Owners & Sys.Outcome,String,Unit>: match result: case (ordinary,outcome):(Owners{ordinary,reader,through},outcome) def exit(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World) -> Owners & Sys.Outcome,String,Unit>: match owners: case Owners{ordinary,reader,through}:phase_returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,reader,through,Operation.exit(~S,~K,~V,~Q,~C,~R,~E,~runner,~observed,~name,~take_world(~S,~K,~V,~R,~take,~put,~C,~E),~put_world(~S,~K,~V,~R,~take,~put,~C,~E,~same),~publish(~S,~K,~V,~R,~take,~put,~C,~E),~same,~requirement_same,~has,~frame,ordinary,world)) def checkpoint_opened(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,ordinary:Operation.Owners,opened:Opening) -> Owners & Sys.Outcome,String,Unit>: match opened: case Opened{world,reader,_,through}:(Owners{ordinary,reader,through},Sys.Succeeded{world,Unit{}}) case OpenRejected{world,reader}:(Owners{ordinary,reader,0n},Sys.Failed{world,"InitialReaderRejected"}) def checkpoint_paired(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,pair:Operation.Owners & Opening) -> Owners & Sys.Outcome,String,Unit>: match pair: case (ordinary,opened):checkpoint_opened(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,ordinary,opened) def transition_returned(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,reader:St.Reader,through:Nat,result:Operation.Owners & Sys.Outcome,String,Unit>) -> Owners & Sys.Outcome,String,Unit>: match result: case (Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.Ready{from,to,skip}},phase,trace},Sys.Succeeded{world,_}):checkpoint_paired(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,open_for_owners(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,Operation.Selected{positions,kept,Phase.Owners{handlers,Phase.Ready{from,to,skip}},phase,trace},reader,world)) case (ordinary,outcome):(Owners{ordinary,reader,through},outcome) def transition(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World) -> Owners & Sys.Outcome,String,Unit>: match owners: case Owners{ordinary,reader,through}:transition_returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,reader,through,Operation.transition(~S,~K,~V,~Q,~C,~R,~E,~runner,~observed,~name,~take_world(~S,~K,~V,~R,~take,~put,~C,~E),~put_world(~S,~K,~V,~R,~take,~put,~C,~E,~same),~publish(~S,~K,~V,~R,~take,~put,~C,~E),~same,~requirement_same,~has,~frame,ordinary,world)) def enter(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World) -> Owners & Sys.Outcome,String,Unit>: match owners: case Owners{ordinary,reader,through}:phase_returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,reader,through,Operation.enter(~S,~K,~V,~Q,~C,~R,~E,~runner,~observed,~name,~take_world(~S,~K,~V,~R,~take,~put,~C,~E),~put_world(~S,~K,~V,~R,~take,~put,~C,~E,~same),~publish(~S,~K,~V,~R,~take,~put,~C,~E),~same,~requirement_same,~has,~frame,ordinary,world)) def finished_world(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,namespace:U32,ordinary:Operation.Owners,steps:List<&2,Sch.Step>,observations:List<&2,Sch.Observation>,error:Maybe<&2,String>,pair:W.World & St.Reader) -> ObservedMarkerRun: match pair: case (world,reader):ObservedMarkerRun{reader,Operation.marked(~S,~K,~V,~Q,~C,~R,~E,~runner,steps,observations,Operation.finished(~S,~K,~V,~Q,~C,~R,~E,~runner,~observed,~name,~take_world(~S,~K,~V,~R,~take,~put,~C,~E),~put_world(~S,~K,~V,~R,~take,~put,~C,~E,~same),~publish(~S,~K,~V,~R,~take,~put,~C,~E),~same,~requirement_same,~has,~frame,namespace,ordinary,world,error))} def succeeded(error:Maybe<&2,String>) -> Bool: match error: case None{}:True{} case Some{_}:False{} def finished(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,namespace:U32,owners:Owners,world:W.World,steps:List<&2,Sch.Step>,observations:List<&2,Sch.Observation>,+error:Maybe<&2,String>) -> ObservedMarkerRun: match owners: case Owners{ordinary,reader,through}:finished_world(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,namespace,ordinary,steps,observations,error,(world,reader)) def returned(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,result:Sch.RunResult,String>) -> ObservedMarkerRun: match result: case Sch.Finished{Sch.Schedule{namespace,_,steps,owners},world,observations}:finished(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,namespace,owners,world,steps,observations,None{}) case Sch.Failed{Sch.Schedule{namespace,_,steps,owners},world,error,observations}:finished(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,namespace,owners,world,steps,observations,Some{error}) case Sch.Rejected{Sch.Schedule{namespace,_,steps,owners},world}:finished(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,namespace,owners,world,steps,[],Some{"schedule-rejected"}) def barrier_returned(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,reader:St.Reader,through:Nat,pair:Operation.Owners & W.World) -> Owners & W.World: match pair: case (ordinary,world):(Owners{ordinary,reader,through},world) def barrier(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World) -> Owners & W.World: match owners: case Owners{ordinary,reader,through}:barrier_returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,reader,through,Operation.barrier(~S,~K,~V,~Q,~C,~R,~E,~runner,ordinary,world)) def phase_started(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,id:U32) -> Owners: match owners: case Owners{ordinary,reader,through}:Owners{Operation.phase_started(~S,~K,~V,~Q,~C,~R,~E,~runner,ordinary,id),reader,through} def dispatch_shared(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World,+id:U32) -> Owners & Sys.Outcome,String,Unit>: Ordinary.dispatch(~S,~C,~R,~E,~Owners,~String,~apply(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),~exit(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),~transition(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),~enter(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),phase_started(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,owners,id),world,id) def dispatch(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,owners:Owners,world:W.World,id:U32) -> Owners & Sys.Outcome,String,Unit>: dispatch_shared(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,owners,world,id) def installed(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,world:W.World,build:Sch.Build>) -> ObservedMarkerRun: match build: case Sch.Built{schedule}:returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,Sch.run_with_barrier(~S,~C,~R,~E,~Owners,~String,~dispatch(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),~Ordinary.condition(~S,~C,~R,~E),~barrier(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame),schedule,world)) case Sch.Invalid{owners}:finished(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,0,owners,world,[],[],Some{"invalid"}) def checked(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,namespace:U32,reader:St.Reader,entries:List<&1,B.Scheduled>,pair:W.World & List<&2,Q>,trace:Facts.State) -> ObservedMarkerRun: match pair: case (world,[]):installed(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,world,Ordinary.install(~S,~C,~R,~E,~Owners,~String,declaration,namespace,Owners{Operation.Pending{entries,trace},reader,0n})) case (world,missing):ObservedMarkerRun{reader,Operation.MarkerResult{B.Returned{B.Bundle{namespace,entries},world,B.MissingRequirements{missing}},[],[],trace}} def gathered(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,namespace:U32,reader:St.Reader,world:W.World,pair:List<&1,B.Scheduled> & List<&2,Q>,trace:Facts.State) -> ObservedMarkerRun: match pair: case (entries,needs):checked(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,declaration,namespace,reader,entries,B.missing(~S,~C,~R,~E,~Q,~has,B.collect(~Q,~requirement_same,needs,[]),world),trace) def allowed(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,yes:Bool,namespace:U32,reader:St.Reader,entries:List<&1,B.Scheduled>,world:W.World,trace:Facts.State) -> ObservedMarkerRun: match yes: case False{}:ObservedMarkerRun{reader,Operation.MarkerResult{B.Returned{B.Bundle{namespace,entries},world,B.ForeignBundle{}},[],[],trace}} case True{}:gathered(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,declaration,namespace,reader,world,B.requirements(~S,~K,~V,~Q,~C,~R,~E,~runner,entries),trace) def namespaced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,+namespace:U32,reader:St.Reader,entries:List<&1,B.Scheduled>,pair:W.World & U32,trace:Facts.State) -> ObservedMarkerRun: match reader pair: case St.Reader{+owner,id}, (world,+actual):allowed(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,declaration,Bool.and(U32.is_eq(namespace,actual),U32.is_eq(owner,actual)),namespace,St.Reader{owner,id},entries,world,trace) def run_observed(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~observed:Facts.State -> W.World -> H.Invocation -> Sys.Outcome,String,Unit> & Facts.State,~name:String,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,bundle:B.Bundle,reader:St.Reader,world:W.World,trace:Facts.State) -> ObservedMarkerRun: match bundle: case B.Bundle{namespace,entries}:namespaced(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~observed,~name,~same,~requirement_same,~has,~frame,declaration,namespace,reader,entries,W.namespace(~S,~C,~R,~E,world),trace) type MarkerRun -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: MarkerRun{reader:St.Reader,result:Classic.MarkerResult} def classic_returned(~S:Data,~K:Data,~V:Data,~Q:Data,~C:Type,~R:Type,~E:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,value:ObservedMarkerRun) -> MarkerRun: match value: case ObservedMarkerRun{reader,Operation.MarkerResult{result,steps,observations,_}}:MarkerRun{reader,Classic.MarkerResult{result,steps,observations}} def run(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,bundle:B.Bundle,reader:St.Reader,world:W.World) -> MarkerRun: classic_returned(~S,~K,~V,~Q,~C,~R,~E,~runner,run_observed(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~Classic.unobserved(~S,~C,~R,~E,~V,~runner),~"",~same,~requirement_same,~has,~frame,declaration,bundle,reader,world,Facts.Off{})) # Normal application construction allocates its marker reader through World.register. type Application -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: Application{world:W.World,bundle:B.Bundle,reader:St.Reader,declaration:Ordinary.Declaration} type Definition -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: Bound{app:Application} BindRejected{world:W.World,bundle:B.Bundle,declaration:Ordinary.Declaration} def bound(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,namespace:U32,bundle:B.Bundle,declaration:Ordinary.Declaration,pair:W.World & W.Registration) -> Definition: match pair: case (world,W.Registered{id}):Bound{Application{world,bundle,St.Reader{namespace,id},declaration}} case (world,W.RegistrationRejected{_}):BindRejected{world,bundle,declaration} def bind_allowed(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,~initial:OD.Declaration,allowed:Bool,namespace:U32,bundle:B.Bundle,declaration:Ordinary.Declaration,world:W.World) -> Definition: match allowed: case False{}:BindRejected{world,bundle,declaration} case True{}:bound(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~same,~requirement_same,~has,~frame,namespace,bundle,declaration,W.register(~S,~C,~R,~E,world,"machine." ++ OD.name(~S,~K,~V,~R,~Init.take_slot(~S,~K,~V,~R,~take,~put),initial) ++ ".initial-marker",["machine." ++ OD.name(~S,~K,~V,~R,~Init.take_slot(~S,~K,~V,~R,~take,~put),initial) ++ ".transition.read"])) def bind_namespaced(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,~initial:OD.Declaration,bundle:B.Bundle,declaration:Ordinary.Declaration,pair:W.World & U32) -> Definition: match bundle pair: case B.Bundle{+owner,entries}, (world,+namespace):bind_allowed(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~same,~requirement_same,~has,~frame,~initial,U32.is_eq(owner,namespace),namespace,B.Bundle{owner,entries},declaration,world) def bind(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,~initial:OD.Declaration,declaration:Ordinary.Declaration,bundle:B.Bundle,world:W.World) -> Definition: bind_namespaced(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~same,~requirement_same,~has,~frame,~initial,bundle,declaration,W.namespace(~S,~C,~R,~E,world)) type AppRun -> H.Invocation -> Sys.Outcome,String,Unit>> is Type: Applied{app:Application,status:B.Status,steps:List<&2,Sch.Step>,observations:List<&2,Sch.Observation>} RecoveryRequired{declaration:Ordinary.Declaration,result:MarkerRun} def app_returned(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,declaration:Ordinary.Declaration,result:MarkerRun) -> AppRun: match result: case MarkerRun{reader,Classic.MarkerResult{B.Returned{bundle,world,status},steps,observations}}:Applied{Application{world,bundle,reader,declaration},status,steps,observations} case result:RecoveryRequired{declaration,result} def run_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,app:Application) -> AppRun: match app: case Application{world,bundle,reader,+declaration}:app_returned(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~same,~requirement_same,~has,~frame,declaration,run(~S,~K,~V,~R,~take,~put,~C,~E,~Q,~runner,~same,~requirement_same,~has,~frame,declaration,bundle,reader,world)) # Application methods retain marker and handler ownership across ordinary setup. def init_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,~initial:OD.Declaration,~make:W.World -> W.World & V,app:Application) -> Application: match app: case Application{world,bundle,reader,declaration}:Application{Init.init_state(~S,~K,~V,~R,~take,~put,~C,~E,~initial,~make,world),bundle,reader,declaration} def insert_app(~S:Data,~K:Data,~V:Data,~R:Type,~take:R -> R & Init.State,~put:R -> Init.State -> R,~C:Type,~E:Data,~Q:Data,~runner:W.World -> H.Invocation -> Sys.Outcome,String,Unit>,~same:V -> V -> Bool,~requirement_same:Q -> Q -> Bool,~has:W.World -> Q -> W.World & Bool,~frame:W.World -> W.World,~initial:OD.Declaration,app:Application,value:V) -> Application: match app: case Application{world,bundle,reader,declaration}:Application{Init.insert_state(~S,~K,~V,~R,~take,~put,~C,~E,~initial,world,value),bundle,reader,declaration}