1 import Base 2 import ./change_tick.bend as Tick 3 import ./restore_graph_data.bend as GraphData 4 import ./restore_graph_validation.bend as Validation 5 import ./restore_graph_machine.bend as Machine 6 import ./restore_graph_world.bend as Install 7 import ./restore_data.bend as R 8 import ./restore_schema.bend as Schema 9 import ./restore_public.bend as Basic 10 import ./restore_prepare.bend as Prepare 11 import ./restore_apply.bend as Apply 12 import ./relation_commands.bend as Relation 13 import ./relation_types.bend as G 14 import ./relation_failure_reader.bend as Declaration 15 import ./owner_product.bend as Product 16 import ./snapshot_data.bend as Snapshot 17 import ./world.bend as W 18 import ./decode_data.bend as D 19 import ./entity_key.bend as Key 20 type Owner R.Position -> D.Field -> State & R.Dispatch,-release:State -> State,-clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,-insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,Recovery:Type,-commit:State -> State,-takeRecovery:State -> State & Recovery,-machineRead:Machines -> Machines & List<&2,D.Field>,-machineCheck:D.Field -> Machine.Dispatch,-machineClear:Machines -> Machines,-machineInstall:Machines -> List<&2,D.Field> -> Machines> is Type: 21 Owner{basic:Basic.Owner,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema} 22 type Error is Data: 23 BasicError{error:R.Error} 24 GraphError{error:GraphData.Error} 25 type Returned is Type: 26 Restored{world:World,owner:Owner,recovery:Recovery,bindings:List<&2,R.Binding>} 27 Rejected{world:World,owner:Owner,recovery:Recovery,input:GraphData.Snapshot,error:Error} 28 MissingBinding{world:World,owner:Owner,recovery:Recovery,saved:Key.Key} 29 def owned(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,basic:Basic.Owner,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema) -> Owner: 30 Owner{basic,relations,machines} 31 def rejected_recovery(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,input:GraphData.Snapshot,error:Error,result:State & Recovery) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 32 match result: 33 case (state,recovery):Rejected{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,input,error} 34 def reject(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,input:GraphData.Snapshot,error:Error) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 35 rejected_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,input,error,takeRecovery(release(state))) 36 def finish_recovery(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,bindings:List<&2,R.Binding>,missing:Maybe<&2,Key.Key>,result:State & Recovery) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 37 match missing result: 38 case None{},(state,recovery):Restored{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,bindings} 39 case Some{saved},(state,recovery):MissingBinding{world,Owner{Basic.Owner{schema,state},relations,machines},recovery,saved} 40 def finished(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,bindings:List<&2,R.Binding>,state:State,result:Install.Installed,Product.Owner,E>>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 41 match result: 42 case Install.MissingBinding{world,saved}:finish_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,bindings,Some{saved},takeRecovery(commit(state))) 43 case Install.Installed{world}:finish_recovery(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,bindings,None{},takeRecovery(commit(state))) 44 def applied(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,input:GraphData.Snapshot,graph:G.Graph,fields:List<&2,D.Field>,result:Apply.ApplyResult,Product.Owner,E,State,Custom>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 45 match result: 46 case Apply.Refused{world,state,_,error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,BasicError{error}) 47 case Apply.Applied{world,state,+bindings}:finished(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,bindings,state,Install.install(~S,~C,~Resources,~Machines,~E,~machineClear,~machineInstall,world,graph,fields,bindings)) 48 def machine_checked(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,+schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,+input:GraphData.Snapshot,graph:G.Graph,fields:List<&2,D.Field>,error:Maybe<&2,GraphData.Error>) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 49 match input error: 50 case input Some{error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,GraphError{error}) 51 case GraphData.Snapshot{+basic,+relationFields,+machineFields} None{}:applied(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,GraphData.Snapshot{basic,relationFields,machineFields},graph,fields,Apply.apply(~S,~Relation.Store,~Product.Owner,~E,~State,~Custom,~release,~clear,~insert,~emit,world,R.Ready{state,basic})) 52 def graph_checked(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,state:State,+input:GraphData.Snapshot,result:GraphData.GraphResult) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 53 match input result: 54 case input GraphData.Rejected{error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,GraphError{error}) 55 case GraphData.Snapshot{+basic,+relationFields,+machineFields} GraphData.Accepted{graph}:machine_checked(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,state,GraphData.Snapshot{basic,relationFields,machineFields},graph,machineFields,Machine.validate(~machineCheck,machineFields)) 56 def prepared(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,schema:Schema.Schema,Product.Owner,State,Custom,stage,release,clear,insert,Recovery,commit,takeRecovery>,+relations:List<&2,Declaration.Declaration>,machines:Machine.Schema,world:W.World,Product.Owner,E>,+input:GraphData.Snapshot,result:R.Prepared) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 57 match input result: 58 case input R.Refused{state,_,error}:reject(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,schema,relations,machines,world,state,input,BasicError{error}) 59 case GraphData.Snapshot{Snapshot.Snapshot{+version,+floor,+entities,+resources},+relationFields,+machineFields} R.Ready{state,_}:graph_checked(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,state,GraphData.Snapshot{Snapshot.Snapshot{version,floor,entities,resources},relationFields,machineFields},Validation.validate(~S,relationFields,entities,relations)) 60 def run(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~E:Data,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clear:Relation.Store -> W.Handle -> Relation.Store & List<&2,R.Change>,~insert:Relation.Store -> Product.Owner -> State -> List<&2,R.Binding> -> Tick.Tick -> (Relation.Store & Product.Owner) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,~machineRead:Machines -> Machines & List<&2,D.Field>,~machineCheck:D.Field -> Machine.Dispatch,~machineClear:Machines -> Machines,~machineInstall:Machines -> List<&2,D.Field> -> Machines,~emit:R.Change -> E,owner:Owner,world:W.World,Product.Owner,E>,+input:GraphData.Snapshot) -> Returned,Product.Owner,E>,Owner,Recovery,Custom>: 61 match owner input: 62 case Owner{Basic.Owner{schema,state},relations,machines} GraphData.Snapshot{+basic,+relationFields,+machineFields}:prepared(~S,~C,~Resources,~Machines,~E,~State,~Custom,~stage,~release,~clear,~insert,~Recovery,~commit,~takeRecovery,~machineRead,~machineCheck,~machineClear,~machineInstall,~emit,schema,relations,machines,world,GraphData.Snapshot{basic,relationFields,machineFields},Prepare.prepare(~State,~Custom,~stage,~release,state,basic))