1 import Base 2 import ./restore_data.bend as R 3 import ./snapshot_leaf.bend as Leaf 4 import ./ordinary_declaration.bend as Identity 5 import ./persistence_declaration.bend as Decl 6 import ./decode_data.bend as D 7 import ./column.bend as Col 8 import ./world.bend as W 9 import ./owner_product.bend as Product 10 11 # Called only after complete staging and capacity admission. Old payloads leave 12 # scope here; no inverse, destructor or finalizer callback is executed. 13 def component_cleared(~S:Data,~P:Type,~identity:Identity.Declaration,~project:P -> P & D.Raw,declaration:Decl.Constructed,+handle:W.Handle,observed:Col.SwapOutcome) -> Leaf.Component & List<&2,R.Change>: 14 match observed: 15 case Col.Accepted{column,Some{owner}}:(Leaf.Component{column,declaration},[R.Removed{handle,Identity.key(~S,~P,identity)}]) 16 case Col.Accepted{column,None{}}:(Leaf.Component{column,declaration},[]) 17 case Col.Rejected{column,_}:(Leaf.Component{column,declaration},[]) 18 def component(~S:Data,~P:Type,~identity:Identity.Declaration,~project:P -> P & D.Raw,owner:Leaf.Component,+handle:W.Handle) -> Leaf.Component & List<&2,R.Change>: 19 match owner: 20 case Leaf.Component{column,declaration}:component_cleared(~S,~P,~identity,~project,declaration,handle,Col.clear(~S,~P,column,W.handle_index(~S,handle))) 21 def transient_cleared(~S:Data,~P:Type,~identity:Identity.Declaration,declaration:Decl.Transient,+handle:W.Handle,observed:Col.SwapOutcome) -> Leaf.TransientComponent & List<&2,R.Change>: 22 match observed: 23 case Col.Accepted{column,Some{owner}}:(Leaf.TransientComponent{column,declaration},[R.Removed{handle,Identity.key(~S,~P,identity)}]) 24 case Col.Accepted{column,None{}}:(Leaf.TransientComponent{column,declaration},[]) 25 case Col.Rejected{column,_}:(Leaf.TransientComponent{column,declaration},[]) 26 def transient_component_owned(~S:Data,~P:Type,~identity:Identity.Declaration,owner:Leaf.TransientComponent,+handle:W.Handle) -> Leaf.TransientComponent & List<&2,R.Change>: 27 match owner: 28 case Leaf.TransientComponent{column,declaration}:transient_cleared(~S,~P,~identity,declaration,handle,Col.clear(~S,~P,column,W.handle_index(~S,handle))) 29 def transient_component(~S:Data,~P:Type,~identity:Identity.Declaration,owner:Leaf.TransientComponent,handle:W.Handle) -> Leaf.TransientComponent & List<&2,R.Change>: 30 transient_component_owned(~S,~P,~identity,owner,handle) 31 def unit(~S:Data,owner:Unit,handle:W.Handle) -> Unit & List<&2,R.Change>:(owner,[]) 32 def product_join(~S:Data,~LC:Type,~RC:Type,left:LC,events:List<&2,R.Change>,observed:RC & List<&2,R.Change>) -> Product.Owner & List<&2,R.Change>: 33 match observed: 34 case (right,more):(Product.Owner{left,right},List.append(&2,R.Change,events,more)) 35 def product_left(~S:Data,~LC:Type,~RC:Type,~right:RC -> W.Handle -> RC & List<&2,R.Change>,owner:RC,handle:W.Handle,observed:LC & List<&2,R.Change>) -> Product.Owner & List<&2,R.Change>: 36 match observed: 37 case (left,events):product_join(~S,~LC,~RC,left,events,right(owner,handle)) 38 def product(~S:Data,~LC:Type,~RC:Type,~left:LC -> W.Handle -> LC & List<&2,R.Change>,~right:RC -> W.Handle -> RC & List<&2,R.Change>,owner:Product.Owner,+handle:W.Handle) -> Product.Owner & List<&2,R.Change>: 39 match owner: 40 case Product.Owner{a,b}:product_left(~S,~LC,~RC,~right,b,handle,left(a,handle))