import Base import ./execution_composer_layout.bend as Layout import ./execution_relation_context.bend as Context import ./execution_relation_resource_publication.bend as Resource import ./execution_relation_store.bend as Store import ./execution_relation_operation.bend as O import ./execution_resource_policy.bend as Policy import ./relation_types.bend as T import ./world.bend as W import ./deferred_command.bend as Deferred import ./clock_state.bend as Clock import ./execution_lifecycle_notices.bend as Notice import ./change_tick.bend as Tick import ./entity_allocator.bend as Allocator # World fields outside allocator/resources remain actual affine owners here. type Frame<-S:Data,-C:Type,-WR:Type,-E:Data> is Type: Frame{namespace:U32,columns:C,events:List<&2,E>,pending:List>>,registrations:List<&2,W.RegistrationMeta>,nextSystem:U32,clock:Clock.State,lifecycle:Notice.Journal} def restored(-S:Data,-C:Type,-WR:Type,-E:Data,-Binding:Type,binding:Binding,frame:Frame,result:Allocator.Allocator & (WR & Store.Receipt)) -> W.World & (Binding & Store.Receipt): match frame result: case Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle}, (allocator,(resources,receipt)):(W.World{namespace,allocator,columns,resources,events,pending,registrations,nextSystem,clock,lifecycle},(binding,receipt)) def checked(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},allowed:Bool,binding:Context.Binding,world:W.World,operation:O.Operation,tick:Tick.Tick) -> W.World & (Context.Binding & Store.Receipt): match allowed binding world: case False{} binding world:(world,(binding,Store.Refused{operation,Store.NamespaceMismatch{}})) case True{} Context.Binding{+context} W.World{+namespace,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle}:restored(S,C,WR,E,Context.Binding,Context.Binding{context},Frame{namespace,columns,events,pending,registrations,nextSystem,clock,lifecycle},Resource.apply(~S,~WR,~resources,~same,~route,~valid,~descriptor,~payload,~view,context,namespace,allocator,owners,operation,tick)) # The protected proof is about the selected canonical leaf's actual policy. # No body, callback, clock advance, second queue, or caller-supplied graph exists. def apply(~S:Data,~C:Type,~WR:Type,~E:Data,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor,~payload:{Layout.payload(resources,route) == Store.Store : Type},~view:{Layout.view(resources,route) == Store.View : Data},~protected:{Layout.policy(resources,route) == Policy.ProtectedRelation{S,descriptor} : Policy.Policy},binding:Context.Binding,world:W.World,operation:O.Operation,tick:Tick.Tick) -> W.World & (Context.Binding & Store.Receipt): match binding world: case Context.Binding{Context.Context{+expected}} W.World{+actual,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle}:checked(~S,~C,~WR,~E,~resources,~same,~route,~valid,~descriptor,~payload,~view,~protected,U32.is_eq(expected,actual),Context.Binding{Context.Context{expected}},W.World{actual,allocator,columns,owners,events,pending,registrations,nextSystem,clock,lifecycle},operation,tick)