1 import Base 2 import ./execution_composer_layout.bend as Layout 3 import ./execution_relation_context.bend as Context 4 import ./execution_relation_resource_publication.bend as Resource 5 import ./execution_relation_store.bend as Store 6 import ./execution_relation_operation.bend as O 7 import ./execution_resource_policy.bend as Policy 8 import ./relation_types.bend as T 9 import ./world.bend as W 10 import ./deferred_command.bend as Deferred 11 import ./clock_state.bend as Clock 12 import ./execution_lifecycle_notices.bend as Notice 13 import ./change_tick.bend as Tick 14 import ./entity_allocator.bend as Allocator 15 16 # World fields outside allocator/resources remain actual affine owners here. 17 type Frame<-S:Data,-C:Type,-WR:Type,-E:Data> is Type: 18 Frame{namespace:U32,columns:C,events:List<&2,E>,pending:List>>,registrations:List<&2,W.RegistrationMeta>,nextSystem:U32,clock:Clock.State,lifecycle:Notice.Journal} 19 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): 20 match frame result: 21 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)) 22 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): 23 match allowed binding world: 24 case False{} binding world:(world,(binding,Store.Refused{operation,Store.NamespaceMismatch{}})) 25 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)) 26 # The protected proof is about the selected canonical leaf's actual policy. 27 # No body, callback, clock advance, second queue, or caller-supplied graph exists. 28 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): 29 match binding world: 30 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)