import Base import ./entity_allocator.bend as A import ./relation_types.bend as T import ./execution_relation_operation.bend as O import ./execution_relation_store.bend as Store import ./execution_composer_layout.bend as Layout import ./lifecycle.bend as Life import ./change_tick.bend as Tick # The shared barrier validates full route, origin, descriptor policy and grant # before taking this exact canonical slot. No caller chooses a replacement graph. def refreshed(~S:Data,~descriptor:T.Descriptor,~key:String,~origin:Layout.Layout,allocator:A.Allocator,stamp:Life.Stamp,operation:O.Operation,result:Store.Store & Store.View) -> A.Allocator & (Layout.ResourceSlot,Store.View>,key,origin> & Store.Receipt): match result: case (store,view):(allocator,(Layout.ResourceSlot{Layout.Viewed{store,view},stamp},Store.Applied{operation})) def refusal_refreshed(~S:Data,~descriptor:T.Descriptor,~key:String,~origin:Layout.Layout,allocator:A.Allocator,stamp:Life.Stamp,operation:O.Operation,reason:Store.Reason,result:Store.Store & Store.View) -> A.Allocator & (Layout.ResourceSlot,Store.View>,key,origin> & Store.Receipt): match result: case (store,view):(allocator,(Layout.ResourceSlot{Layout.Viewed{store,view},stamp},Store.Refused{operation,reason})) def returned(~S:Data,~descriptor:T.Descriptor,~key:String,~origin:Layout.Layout,tick:Tick.Tick,stamp:Life.Stamp,priorView:Store.View,result:A.Allocator & (Store.Store & Store.Receipt)) -> A.Allocator & (Layout.ResourceSlot,Store.View>,key,origin> & Store.Receipt): match result: case (allocator,(store,Store.Applied{operation})):refreshed(~S,~descriptor,~key,~origin,allocator,Life.after_write(True{},True{},stamp,tick),operation,Store.project(~S,~descriptor,store)) case (allocator,(store,Store.Refused{operation,reason})):refusal_refreshed(~S,~descriptor,~key,~origin,allocator,stamp,operation,reason,Store.project(~S,~descriptor,store)) def apply(~S:Data,~descriptor:T.Descriptor,~key:String,~origin:Layout.Layout,namespace:U32,allocator:A.Allocator,slot:Layout.ResourceSlot,Store.View>,key,origin>,operation:O.Operation,tick:Tick.Tick) -> A.Allocator & (Layout.ResourceSlot,Store.View>,key,origin> & Store.Receipt): match slot: case Layout.ResourceSlot{Layout.Viewed{store,view},stamp}:returned(~S,~descriptor,~key,~origin,tick,stamp,view,Store.apply(~S,~descriptor,namespace,allocator,store,operation))