| 1 | module scheme |
| 2 | |
| 3 | import reader |
| 4 | |
| 5 | // Independent failed-capture recovery oracles. Authored, not executed here. |
| 6 | fn review_recovery_builder(mut vm VM) &Builder { |
| 7 | code := vm.new_code(reader.read_all('') or { panic(err.msg()) }, vm.next_context(), unsafe { nil }, '') |
| 8 | return &Builder{ code: code, function: &Function{ code: code } } |
| 9 | } |
| 10 | |
| 11 | fn review_expect_invalid_detached_capture(mut builder Builder) { |
| 12 | if _ := builder.capture_syntax_lookup_context() { |
| 13 | assert false, 'invalid detached lexical row unexpectedly froze' |
| 14 | } else { |
| 15 | assert err is EvalError |
| 16 | assert err.msg().contains('invalid detached lexical syntax binding'), err.msg() |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | fn test_independent_private_snapshot_recovers_updates_after_later_row_freeze_failure() { |
| 21 | mut vm := new() |
| 22 | mut builder := review_recovery_builder(mut vm) |
| 23 | mut code := builder.code |
| 24 | a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'a-origin', global_slot: 7 } }) or { panic(err.msg()) } |
| 25 | first := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 26 | prior := code.generated.aliases[a] |
| 27 | code.generated.set_alias(a, IdentifierAlias{ ...prior, binding: SyntaxBinding{ ...prior.binding, global_slot: 8 } }) |
| 28 | bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'bad-origin', slot: 0 } }) or { panic(err.msg()) } |
| 29 | review_expect_invalid_detached_capture(mut builder) |
| 30 | code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 9 } }) |
| 31 | recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 32 | assert recovered.binding(a).global_slot == 8 |
| 33 | assert recovered.binding(bad).global_slot == 9 |
| 34 | assert first.binding(a).global_slot == 7 |
| 35 | assert first.binding(bad).unbound |
| 36 | code.release_compile_borrows() |
| 37 | } |
| 38 | |
| 39 | fn test_independent_private_snapshot_recovers_first_attempt_with_owned_rows_and_no_prior_snapshot() { |
| 40 | mut vm := new() |
| 41 | mut builder := review_recovery_builder(mut vm) |
| 42 | mut code := builder.code |
| 43 | a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'first-origin', global_slot: 7 } }) or { panic(err.msg()) } |
| 44 | bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'bad-origin', slot: 0 } }) or { panic(err.msg()) } |
| 45 | review_expect_invalid_detached_capture(mut builder) |
| 46 | // A second failure must not make the preceding successful row disappear either. |
| 47 | review_expect_invalid_detached_capture(mut builder) |
| 48 | code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 9 } }) |
| 49 | recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 50 | assert recovered.binding(a).global_slot == 7 |
| 51 | assert recovered.binding(bad).global_slot == 9 |
| 52 | repeated := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 53 | assert repeated.binding(a).global_slot == 7 |
| 54 | assert repeated.binding(bad).global_slot == 9 |
| 55 | code.release_compile_borrows() |
| 56 | } |
| 57 | |
| 58 | fn test_independent_private_snapshot_recovers_new_rows_after_failed_binary_carries() { |
| 59 | mut vm := new() |
| 60 | mut builder := review_recovery_builder(mut vm) |
| 61 | mut code := builder.code |
| 62 | a := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'old-origin', global_slot: 7 } }) or { panic(err.msg()) } |
| 63 | first := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 64 | prior := code.generated.aliases[a] |
| 65 | code.generated.set_alias(a, IdentifierAlias{ ...prior, binding: SyntaxBinding{ ...prior.binding, global_slot: 8 } }) |
| 66 | mut added := []string{} |
| 67 | for i in 0 .. 33 { |
| 68 | added << (code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'new-origin-${i}', global_slot: i + 10 } }) or { panic(err.msg()) }) |
| 69 | } |
| 70 | bad := code.identifier_alias(IdentifierAlias{ binding: SyntaxBinding{ kind: .lexical, name: 'last-invalid-origin', slot: 0 } }) or { panic(err.msg()) } |
| 71 | review_expect_invalid_detached_capture(mut builder) |
| 72 | code.generated.set_alias(bad, IdentifierAlias{ binding: SyntaxBinding{ kind: .global, name: 'repaired-origin', global_slot: 50 } }) |
| 73 | recovered := builder.capture_syntax_lookup_context() or { panic(err.msg()) } |
| 74 | assert recovered.binding(a).global_slot == 8 |
| 75 | assert recovered.binding(bad).global_slot == 50 |
| 76 | assert first.binding(a).global_slot == 7 |
| 77 | assert first.binding(bad).unbound |
| 78 | for i, name in added { |
| 79 | assert recovered.binding(name).global_slot == i + 10 |
| 80 | assert first.binding(name).unbound |
| 81 | } |
| 82 | code.release_compile_borrows() |
| 83 | } |
| 84 | |