Skip to content

Sema borrow cleanup leaves scope-depth and creation-site columns stale, breaking NLL #1099

Closed

Description

@ehartford

The C4 final test survey at 6d54088 rejects test/behavior/behav_d27_view_nll_before_owner_consume.w after the last use of an element view. Expected: D27 / §8.4 NLL allows consuming and replacing the owner after the view's last use. Actual: view 'view' may outlive its origin 'owner' at EOF. The previous compiler (90d4858, before the regex lifetime update) accepts the same test.

type Item { value: i32 }
type Owner { items: Vec[Item] }
fn identity(owner: Owner) -> Owner: owner
fn main:
    var owner = Owner { items: Vec.new() }
    owner.items.push(Item { value: 41 })
    let view = owner.items.get(0)
    assert(view.value == 41)
    owner = identity(owner)
    assert(owner.items.get(0).value == 41)

Exact LLDB proof: in Sema.check_fn_body_with_sig_at, borrow_refs, borrow_scope_depths, and borrow_creation_nodes each have length 1 before function setup. At function+880, after the clear loop in SemaCheck.w:2067–2073, their lengths are 0, 1, 1. The loop pops six columns and omits the two newer metadata columns. The closure rollback at SemaCheck.w:14010–14016 duplicates the same incomplete operation.

The later element borrow reads stale depth 2 while current scope depth is 3. LLDB at Sema.expire_dead_borrows_in_block +188 observed w8=2, w24=3, then the +196 branch falls through to the skip at +200. The effect trace correctly reports identity's consuming escape_value parameter; this is corrupted borrow metadata, not a signature ruling.

Fix in progress: use existing remove_borrow_at for whole-row removal in both cleanup paths, and validate column lengths before expiration/removal so inconsistent metadata fails as an internal compiler error. No diagnostic is relaxed. Local proof logs: out/c4-validation/nll-partial-clear-lldb-confirmed.log and nll-depth-skip-lldb.log. No workaround used.

Activity

  1. added a commit that references this issue on Sep 9, 2026
    5d3312b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions