Skip to content

Track lent-through references as ShallowExclusive and announce all value drops - #175

Open
JonasAlaif wants to merge 3 commits into
mainfrom
shallow-exclusive-refs
Open

Track lent-through references as ShallowExclusive and announce all value drops#175
JonasAlaif wants to merge 3 commits into
mainfrom
shallow-exclusive-refs

Conversation

@JonasAlaif

Copy link
Copy Markdown
Contributor

Consumers that do exact resource accounting need two guarantees from the PCG's output that previously did not hold: Write capability must unambiguously mean "the place holds no value", and every transition into Write must be announced as an op on the statement or edge where it happens.

Changes

  • Weaken still-exclusive leaves when collapsing to write capability (obtain step 2): a collapse-to-W (an overwrite, or StorageDead of e.g. a partially-moved local) now emits Weaken(E→W) for each leaf that still holds its value, so the emitted Collapse meets its guarantee that all packed-up places hold exactly the given capability. Related to Unsound restoration to E capability after expiry of conditional borrow #137.

  • Downgrade a mutably-derefed reference to ShallowExclusive, not Write: a reference whose pointee is reborrowed still holds its own value (the pointer stays readable and overwritable); only the permission through the dereference is given up, which is exactly ShallowExclusive. All transitions out of e are announced: overwrites and storage-deads weaken e→W, and loan expiry restores from e. This also resolves the previous todo!() in the (e, _) join arms.

  • Announce value drops at CFG joins: joining a lent-through (e) or read (R) place with a side that moved the value out now labels the place (so labelled reads resolve to the join point) and announces the drop instead of performing it silently: the e side emits Weaken(e→W), and the R side emits a restore to E followed by an ordinary Weaken(E→W). Owned weakens are now constructed through checked helpers that assert the capability strictly decreases, upholding RepackOp::Weaken's _.1 > _.2 guarantee.

@JonasAlaif

Copy link
Copy Markdown
Contributor Author

I decided that reusing the ShallowExclusive thing is fine. Even though the semantic meaning is different, one can look at the type of the node itself to determine the semantics (i.e. & (mut) vs Box)

…bility

A collapse to write capability (an overwrite, or a StorageDead of e.g. a
partially-moved local) packs up leaves that may still hold exclusive
capability. Announce the capability drop with an explicit weaken for each
such leaf, so that Collapse meets its guarantee that all packed-up places
hold exactly the given capability. Related to #137.

Owned weakens are now constructed through checked helpers
(RepackOp::weaken / RepackOp::weaken_for_storage_dead) that assert the
capability strictly decreases, and existing emission sites are routed
through them. Also expose place_capability, local_is_expanded and the
RegainedCapability accessors for consumers.
@JonasAlaif
JonasAlaif force-pushed the shallow-exclusive-refs branch from 9768fec to d719f5b Compare August 13, 2026 12:19
A reference whose pointee is reborrowed still holds its own value: the
pointer itself stays readable and overwritable; only the permission
through the dereference is given up. That is exactly ShallowExclusive,
so use it instead of silently dropping the reference to Write. All
transitions out of ShallowExclusive are announced: overwrites and
storage-deads weaken e -> W, and loan expiry restores from e. This also
resolves the todo!() in the ShallowExclusive join arms: joining with a
moved-out (Write) side labels the place and announces the value drop.
A place that was lent for reading reaches a join in a stale Read state
(restore_place deliberately skips Read places when a read expansion
dies), while the other side moved the value out. The joined state can
only be Write, so the value still held on the read side is dropped by
the join. Announce this as a restoration to Exclusive (the lending has
ended) followed by an ordinary strictly-decreasing weaken to Write,
after labelling the place so old-value references resolve to the join
point.
@JonasAlaif
JonasAlaif force-pushed the shallow-exclusive-refs branch from d719f5b to 039081d Compare August 13, 2026 12:24
@zgrannan

Copy link
Copy Markdown
Collaborator

@JonasAlaif This looks good to me at a high level, could you add a regression test (perhaps the motivating example)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants