1 import Base 2 3 # Source-derived from exact concrete-v3 closure a4672d11; see extraction.json. 4 type Selection is Data: 5 Required{} 6 Present{} 7 Absent{} 8 Optional{} 9 type MetadataColumns<-F: Data> is Type: 10 MetadataColumns{live: Array, flags: Array>, added: Array, changed: Array} 11 type Rows<-M: Type,-A: Type,-F: Data> is Type: 12 Rows{main: Array>, aux: Array>, metadata: MetadataColumns, capacity: U32, depth: Nat, high_water: U32} 13 14 def selected(-F: Data,selection: Selection,flag: Maybe<&2,F>) -> Bool: 15 match selection flag: 16 case Present{} None{}: False{} 17 case Absent{} Some{_}: False{} 18 case _ _: True{} 19 type PrototypeHandoffRows<-Schema:Data,-M:Type> is Type: 20 HandoffNil{} 21 HandoffCon{id:U32,owner:M,rest:PrototypeHandoffRows} 22 type PrototypeHandoffState<-Schema:Data,-M:Type,-A:Type,-F:Data> is Type: 23 PrototypeHandoffState{main:Array>,aux:Array>,live:Array,flags:Array>,added:Array,changed:Array,values:PrototypeHandoffRows} 24 def prototype_handoff_restore_state(-Schema:Data,-M:Type,-A:Type,-F:Data,+id:U32,+namespace:U32,aux:Array>,live:Array,flags:Array>,added:Array,changed:Array,values:PrototypeHandoffRows,result:Array> & Maybe) -> PrototypeHandoffState: 25 match result: 26 case Tuple{main,None{}}: PrototypeHandoffState{main,aux,live,flags,added,changed,values} 27 case Tuple{main,Some{owner}}: PrototypeHandoffState{main,aux,live,flags,added,changed,HandoffCon{id,owner,values}} 28 def prototype_handoff_inspect_state(-Schema:Data,-M:Type,-A:Type,-F:Data,+id:U32,+namespace:U32,main:Array>,aux:Array>,live:Array,flags:Array>,added:Array,changed:Array,values:PrototypeHandoffRows) -> PrototypeHandoffState: 29 prototype_handoff_restore_state(Schema,M,A,F,id,namespace,aux,live,flags,added,changed,values,Array.swap(Maybe,main,U32.sub(id,1),None{})) 30 31 def prototype_handoff_struct_idx_selected(~Schema: Data,~M: Type,~A: Type,~F: Data,include: Bool,+id: U32,namespace: U32,main: Array>,aux: Array>,live: Array,flags: Array>,added: Array,changed: Array,values: PrototypeHandoffRows,flag: Maybe<&2,F>) -> PrototypeHandoffState: 32 match include: 33 case False{}: PrototypeHandoffState{main,aux,live,flags,added,changed,values} 34 case True{}: prototype_handoff_inspect_state(Schema,M,A,F,id,namespace,main,aux,live,flags,added,changed,values) 35 36 def prototype_handoff_struct_idx_metadata(~Schema: Data,~M: Type,~A: Type,~F: Data,id: U32,namespace: U32,selection: Selection,main: Array>,aux: Array>,values: PrototypeHandoffRows,live: Array,added: Array,changed: Array,value: Bool,result: Array> & Maybe<&2,F>) -> PrototypeHandoffState: 37 match value result: 38 case False{} Tuple{flags,_}: PrototypeHandoffState{main,aux,live,flags,added,changed,values} 39 case True{} Tuple{flags,+flag}: prototype_handoff_struct_idx_selected(~Schema,~M,~A,~F,selected(F,selection,flag),id,namespace,main,aux,live,flags,added,changed,values,flag) 40 41 def prototype_handoff_struct_cols_live(~Schema: Data,~M: Type,~A: Type,~F: Data,+id: U32,namespace: U32,selection: Selection,main: Array>,aux: Array>,values: PrototypeHandoffRows,flags: Array>,added: Array,changed: Array,result: Array & Bool) -> PrototypeHandoffState: 42 match result: 43 case Tuple{live,False{}}: PrototypeHandoffState{main,aux,live,flags,added,changed,values} 44 case Tuple{live,True{}}: prototype_handoff_struct_idx_metadata(~Schema,~M,~A,~F,id,namespace,selection,main,aux,values,live,added,changed,True{},Array.get(Maybe<&2,F>,flags,U32.sub(id,1))) 45 46 def prototype_handoff_struct_idx_advance(~Schema: Data,~M: Type,~A: Type,~F: Data,valid: Bool,+id: U32,namespace: U32,selection: Selection,state: PrototypeHandoffState) -> PrototypeHandoffState: 47 match valid state: 48 case False{} state: state 49 case True{} PrototypeHandoffState{main,aux,live,flags,added,changed,values}: 50 prototype_handoff_struct_cols_live(~Schema,~M,~A,~F,id,namespace,selection,main,aux,values,flags,added,changed,Array.get(Bool,live,U32.sub(id,1))) 51 52 def prototype_handoff_finish_forward(-Schema:Data,-M:Type,-A:Type,-F:Data,capacity:U32,depth:Nat,high:U32,state:PrototypeHandoffState) -> Rows & PrototypeHandoffRows: 53 match state: 54 case PrototypeHandoffState{main,aux,live,flags,added,changed,values}: (Rows{main,aux,MetadataColumns{live,flags,added,changed},capacity,depth,high},values) 55 def prototype_handoff_struct_idx_go(~Schema: Data,~M: Type,~A: Type,~F: Data,remaining: Nat,+id: U32,+capacity: U32,+depth: Nat,+high: U32,+selection: Selection,+namespace: U32,state: PrototypeHandoffState) -> Rows & PrototypeHandoffRows: 56 match remaining: 57 case 0n: prototype_handoff_finish_forward(Schema,M,A,F,capacity,depth,high,state) 58 case 1n++rest: prototype_handoff_struct_idx_go(~Schema,~M,~A,~F,rest,U32.sub(id,1),capacity,depth,high,selection,namespace,prototype_handoff_struct_idx_advance(~Schema,~M,~A,~F,Bool.and((0 < id : U32),(id <= capacity : U32)),id,namespace,selection,state)) 59 60 def prototype_handoff_read_rows(~Schema: Data,~M: Type,~A: Type,~F: Data,rows: Rows,selection: Selection,namespace: U32) -> Rows & PrototypeHandoffRows: 61 match rows: 62 case Rows{main,aux,MetadataColumns{live,flags,added,changed},capacity,depth,+high}: 63 prototype_handoff_struct_idx_go(~Schema,~M,~A,~F,U32.to_nat(high),high,capacity,depth,high,selection,namespace,PrototypeHandoffState{main,aux,live,flags,added,changed,HandoffNil{}}) 64 65 66 def prototype_handoff_recover_go(-Schema:Data,-M:Type,rows:PrototypeHandoffRows,columns:Array>,ids:List<&2,U32>) -> Array> & List<&2,U32>: 67 match rows: 68 case HandoffNil{}: (columns,List.reverse(&2,U32,ids)) 69 case HandoffCon{+id,owner,rest}: prototype_handoff_recover_go(Schema,M,rest,Array.set(Maybe,columns,U32.sub(id,1),Some{owner}),id <> ids) 70 def prototype_handoff_recover(-Schema:Data,-M:Type,rows:PrototypeHandoffRows,columns:Array>) -> Array> & List<&2,U32>: 71 prototype_handoff_recover_go(Schema,M,rows,columns,[]) 72 73 74