module scheme import reader // Vile-specific protection controls for context-transfer changes. These use // detached syntax objects to isolate declaration age from macro alias spelling. // Authored only: this reviewer did not compile or execute these tests on Vile. fn anchor_fence_review_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 anchor_fence_review_identifier(vm &VM, binding SyntaxBinding, context &SyntaxLookupContext, wrap &SyntaxWrap) Value { data := &SyntaxObjectData{ owner: vm.owner context: context tree: &SyntaxTree{ context: context nodes: [SyntaxTreeNode{ kind: .symbol, car: 0 }] identifiers: [SyntaxIdentifier{ name: 'x' raw_name: 'x' binding: binding wrap: wrap context: context }] } } return wrapped_syntax(data, 0) or { panic(err.msg()) } } fn test_anchor_fence_review_same_spelling_preserves_exact_and_canonical_declaration_fences() { mut vm := new() public_slot := vm.bind_global('x', integer(100)) canonical := '\x00~anchor-context-review/canonical/x' exact := '\x00~anchor-context-review/exact/x' old_slot := vm.bind_global(canonical, integer(99)) mut builder := anchor_fence_review_builder(mut vm) mut expansion := SyntaxExpansion{ domain: builder.syntax_mark_domain() } wrap := expansion.transcription_wrap(unsafe { nil }) floor := builder.code.syntax_global_generation_floor() or { panic(err.msg()) } pending := SyntaxBinding{ kind: .global name: 'x' global_slot: public_slot assignable: true introduced: exact introduced_key: canonical introduced_namespace: builder.code.namespace introduced_globals: vm.globals.len introduced_generation: floor } context := builder.capture_syntax_lookup_context() or { panic(err.msg()) } anchor := anchor_fence_review_identifier(vm, pending, context, wrap) copy := datum_to_syntax(anchor, text_value(.symbol, 'x')) or { panic(err.msg()) } copied := (syntax_identifier_info(copy) or { panic(err.msg()) }).binding assert copied.introduced == exact assert copied.introduced_key == canonical assert copied.introduced_globals == pending.introduced_globals assert copied.introduced_generation == floor assert free_syntax_identifier_equal(anchor, copy) or { panic(err.msg()) } assert bound_syntax_identifier_equal(anchor, copy) or { panic(err.msg()) } // Resolution after compiler detachment must still reject the older private x. builder.code.release_compile_borrows() assert runtime_syntax_binding(vm.owner, copied).binding.global_slot == public_slot generation := vm.owner.syntax_generation container_store(mut vm.globals, old_slot, integer(123)) assert vm.owner.syntax_generation == generation assert runtime_syntax_binding(vm.owner, copied).binding.global_slot == public_slot // A real declaration can reuse the old slot and still cross the birth fence. assert vm.bind_global(canonical, integer(42)) == old_slot assert runtime_syntax_binding(vm.owner, copied).binding.global_slot == old_slot assert vm.globals[public_slot].whole() == 100 } fn test_anchor_fence_review_old_import_rejected_but_fresh_private_alias_can_use_old_provider() { mut vm := new() provider := vm.new_environment() or { panic(err.msg()) } vm.define_in(provider, 'source-x', integer(42)) or { panic(err.msg()) } provider_space := vm.environment_space(provider) or { panic(err.msg()) } original := vm.namespace_binding(provider_space, 'source-x') public_slot := vm.bind_global('x', integer(100)) canonical := '\x00~anchor-context-review/old-import/x' exact := '\x00~anchor-context-review/new-import/x' vm.install_import(unsafe { nil }, NamespaceImport{ name: canonical, binding: original }) mut builder := anchor_fence_review_builder(mut vm) mut expansion := SyntaxExpansion{ domain: builder.syntax_mark_domain() } wrap := expansion.transcription_wrap(unsafe { nil }) floor := builder.code.syntax_global_generation_floor() or { panic(err.msg()) } pending := SyntaxBinding{ kind: .global name: 'x' global_slot: public_slot assignable: true introduced: exact introduced_key: canonical introduced_namespace: builder.code.namespace introduced_globals: vm.globals.len introduced_generation: floor } context := builder.capture_syntax_lookup_context() or { panic(err.msg()) } anchor := anchor_fence_review_identifier(vm, pending, context, wrap) copy := datum_to_syntax(anchor, text_value(.symbol, 'x')) or { panic(err.msg()) } copied := (syntax_identifier_info(copy) or { panic(err.msg()) }).binding assert copied.introduced_globals == pending.introduced_globals assert copied.introduced_generation == floor builder.code.release_compile_borrows() assert runtime_syntax_binding(vm.owner, copied).binding.global_slot == public_slot assert !(free_syntax_identifier_equal(copy, vm.eval_in('(syntax source-x)', provider) or { panic(err.msg()) }) or { panic(err.msg()) }) // The fresh destination declaration, not the old provider slot, crosses the // fence. The pre-existing canonical import must remain insufficient by itself. assert original.global_slot < copied.introduced_globals vm.install_import(unsafe { nil }, NamespaceImport{ name: exact, binding: original }) alias_location := syntax_global_location(vm.owner, unsafe { nil }, exact) or { panic('missing imported alias location') } assert alias_location.generation >= floor assert runtime_syntax_binding(vm.owner, copied).binding.global_slot == original.global_slot assert !runtime_syntax_binding(vm.owner, copied).binding.assignable assert free_syntax_identifier_equal(anchor, copy) or { panic(err.msg()) } assert vm.globals[public_slot].whole() == 100 }