Skip to main content

load_state

Function load_state 

Source
pub fn load_state<C: ContextAccess + ?Sized>(
    program: &Program,
    ctx: &mut C,
    save: &SaveState,
) -> LoadReport
Expand description

Reconcile a SaveState into a flow’s context, returning a LoadReport of anything that couldn’t be applied. Globals are matched by name; visit/turn counts by id. Tolerant of story patches: unknown globals are reported, scopes the program no longer has retain their saved counts harmlessly in the live context. Note one deliberate change from the pre-F6.1b Story methods: such stale entries are not re-emitted by a subsequent save_state (which enumerates the current program’s containers, not the live maps) — ghost counts from older program versions no longer round-trip through saves indefinitely.

M-3 rehydration miss-path lookup (docs/modules-spec.md §5): a visit/turn-count id, or a divert-target/fn-token/closure-target id embedded inside a saved global’s value, that the current program doesn’t recognize is looked up in the compiled #@was alias table before being treated as genuinely gone — a knot/stitch/module rename that recorded #@was rebinds saved state deterministically instead of orphaning it under the stale id. Still unresolved after that (only checked, and only reported, for a program that carries alias-table entries at all — an ordinary content edit with no #@was stays exactly as silent as before M-3) surfaces a teaching message in LoadReport::unresolved_renames.

A saved global whose own name no longer matches any current global slot gets the same treatment before being dropped: save.global_ids carries the name’s save-time DefinitionId (declared-module identity is (module, name)-hashed, so the bare name string alone can’t reconstruct it — this is what makes a VAR/CONST/LIST rename inside a declared module different from a bare knot rename), which is looked up in the alias table exactly like an address/global-pointer id. A resolved rename rebinds silently to the renamed slot; still unresolved (no id recorded — an older save predating this field — or no matching alias) falls back to LoadReport::unknown_globals, same as before M-3.

Writes go through ContextAccess, so on a ContextView they route by scope exactly like any other write: a World-scoped unit lands in the shared World, a Local-scoped unit in the flow’s own FlowLocal override layer.