module scheme import reader // Independent failed-capture recovery oracles. Authored, not executed here. fn review_recovery_builder(mut vm VM) &Builder { code := vm.new_code(reader.read_all('') or { panic(err.msg()) }, vm.next_context(), unsafe { nil }, '') return &Builder{ code: code, function: &Function{ code: code } } } fn review_expect_invalid_detached_capture(mut builder Builder) { if _ := builder.capture_syntax_lookup_context() { assert false, 'invalid detached lexical row unexpectedly froze' } else { assert err is EvalError assert err.msg().contains('invalid detached lexical syntax binding'), err.msg() } } fn test_independent_private_snapshot_recovers_updates_after_later_row_freeze_failure() { mut vm := new() mut builder := review_recovery_builder(mut vm) mut code := builder.code a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'a-origin', global_slot: 7 } }) or { panic(err.msg()) } first := builder.capture_syntax_lookup_context() or { panic(err.msg()) } prior := code.generated.aliases[a] code.generated.set_alias(a, IdentifierAlias{ ...prior, binding: SyntaxBinding{ ...prior.binding, global_slot: 8 } }) bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'bad-origin', slot: 0 } }) or { panic(err.msg()) } review_expect_invalid_detached_capture(mut builder) code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 9 } }) recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } assert recovered.binding(a).global_slot == 8 assert recovered.binding(bad).global_slot == 9 assert first.binding(a).global_slot == 7 assert first.binding(bad).unbound code.release_compile_borrows() } fn test_independent_private_snapshot_recovers_first_attempt_with_owned_rows_and_no_prior_snapshot() { mut vm := new() mut builder := review_recovery_builder(mut vm) mut code := builder.code a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'first-origin', global_slot: 7 } }) or { panic(err.msg()) } bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'bad-origin', slot: 0 } }) or { panic(err.msg()) } review_expect_invalid_detached_capture(mut builder) // A second failure must not make the preceding successful row disappear either. review_expect_invalid_detached_capture(mut builder) code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 9 } }) recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } assert recovered.binding(a).global_slot == 7 assert recovered.binding(bad).global_slot == 9 repeated := builder.capture_syntax_lookup_context() or { panic(err.msg()) } assert repeated.binding(a).global_slot == 7 assert repeated.binding(bad).global_slot == 9 code.release_compile_borrows() } fn test_independent_private_snapshot_recovers_new_rows_after_failed_binary_carries() { mut vm := new() mut builder := review_recovery_builder(mut vm) mut code := builder.code a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'old-origin', global_slot: 7 } }) or { panic(err.msg()) } first := builder.capture_syntax_lookup_context() or { panic(err.msg()) } prior := code.generated.aliases[a] code.generated.set_alias(a, IdentifierAlias{ ...prior, binding: SyntaxBinding{ ...prior.binding, global_slot: 8 } }) mut added := []string{} for i in 0 .. 33 { added << (code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'new-origin-${i}', global_slot: i + 10 } }) or { panic(err.msg()) }) } bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'last-invalid-origin', slot: 0 } }) or { panic(err.msg()) } review_expect_invalid_detached_capture(mut builder) code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 50 } }) recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } assert recovered.binding(a).global_slot == 8 assert recovered.binding(bad).global_slot == 50 assert first.binding(a).global_slot == 7 assert first.binding(bad).unbound for i, name in added { assert recovered.binding(name).global_slot == i + 10 assert first.binding(name).unbound } code.release_compile_borrows() }