Skip to content

free region visitor for liveness marking regions dead and polonius alpha soundness #153215

@lqd

Description

@lqd

This tracks the work to fix a soundness issue between the free region liveness visitor and polonius (the model in general and the polonius alpha in its current implementation) as seen in UI tests under edition 2024 and -Zpolonius=next:

  • tests/ui/impl-trait/alias-liveness/rpit-hide-lifetime-for-swap.rs
  • tests/ui/impl-trait/hidden-lifetimes.rs

Both tests exercise the same issue and codepaths for our purpose here, one of these is actually a superset of the other.

The free region visitor for liveness is coarse with respect to unused regions, and can mark only the region that is outlived by the opaque type as live, but not the regions that outlive it. This is fine under NLLs, but not with the location-sensitive-liveness-based-analysis artist known as polonius: the polonius alpha propagates loans in the CFG as a traversal, according to liveness and outlives constraints, and encountering only dead regions at a point can cause to miss errors, by definition. The loan will not be marked live, and an illegal access error is an invalidation of a live loan.

(The old datalog implementation doesn't suffer from this issue by chance: it reimplements liveness and hasn't been updated to try to ignore unused regions captured by an opaque type. Yes, that previous implementation now rejects the stable code relying on this new behavior. Code that is more common with the new edition 2024 capture rules, and use<> bounds.)

This behavior is due to this branch, but by now, stable code relies on unused lifetimes being marked dead by it, and we can't go back.

Our expectation is that fixing an opaque type unsoundness with the new solver will create the prerequisites to use in the liveness visitor and fix the current issue, by having a way to be less coarse in the selection of regions to consider unused and mark dead. The draft fix for that issue is #152051.

This issue is to ensure this doesn't slip through, and mostly to be able to mark these two tests as known-bug and be aware when anything changes here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.NLL-poloniusIssues related for using Polonius in the borrow checkerT-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions