Skip to content

Support leak check for new style region constraint - #164350

Open
adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:abby_leak_check2
Open

adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:abby_leak_check2

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

To support snapshot-based leak check, we need to record the VisibleForLeakCheck field for each leaf registering.
We can't merge visibilities since that's lossy and can't be rolled back.
A separate list is used to record all info that's lost in solver region constraint deduplication. It's unfortunate but necessary in my view.

Close rust-lang/project-assumptions-on-binders#30
Close rust-lang/project-assumptions-on-binders#56

r? Boxyuwu

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 15, 2026
@rustbot

rustbot commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Boxyuwu is currently at their maximum review capacity.
They may take a while to respond.

Comment on lines +775 to +776
// FIXME: unsure about whether the inherited `VisibleForLeakCheck` is correct.
candidates.push(RegionOutlives(ub, lb, visible_for_leak_check, ()));

@adwinwhite adwinwhite Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure about whether the inheriting is correct 🤔

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep seems right to me

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@adwinwhite
adwinwhite force-pushed the abby_leak_check2 branch 2 times, most recently from a2eaf90 to ce951ee Compare November 25, 2026 13:01
'b: 'a,
'a: 'b,
'b: 'a,
}

@adwinwhite adwinwhite Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should make region constraint comparison order insenstitive in the DSL.

View changes since the review

@adwinwhite
adwinwhite marked this pull request as ready for review November 25, 2026 13:11
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2026
@BoxyUwU

BoxyUwU commented Nov 25, 2026

Copy link
Copy Markdown
Member

not certain I understand the reason why this is the solution arrived at so just gonna ramble a bit and you can tell me if I'm understanding correctly or not xd

So as far as I can tell the main difficulty here is snapshot-based leak checks, which look at UndoLog stuff to build the region graph it then checks.

This is a difficulty because we need to make sure to actually have an UndoLog entry for everything we have for old style constraints otherwise we'll get a behavioural difference. That gives us one important consideration that you mentioned in your other PR, about how registering already-registered constraints must result in an UndoLog entry so that leak check sees it. There's also the case of registering 'a: 'a which does nothing but I don't think those edges would matter for leak check.


As far as I understand it the solution in this PR is to:

  • Introduce a new set of leaf region constraints to the storage which doesn't have deduplication behaviour and tracks whether the leaf is duplicated with another leaf
  • Introduce a new UndoLog::AddSolverLeafRegionConstraint which pushes to both the actual And as well as the undeduplicated one in the storage

This allows you to implement proper undo behaviour for the UndoLog variant by looking at the undeduplicated storage to tell if its a duplicate or not. And you also just have an UndoLog entry even when there are duplicates now which lets leak check retain the old style constraint behaviour.


I have few thoughts on this where I'm not sure if I'm missing something.

First, why do we wish to store VisibleForLeakCheck out of band in the region constraint storage instead of as part of RegionConstraint. I could imagine doing it to avoid polluting or_constraint stuff with VisibleForLeakCheck? Or maybe there are places other than the region constraint storage where we store region constraints and some of them dont care for VisibleForLeakCheck (e.g. borrowck)?

It feels unexpected to me for it to not be part of RegionConstraint but unsure if I'm missing some reason why that's difficult :3

The other thing is that I would ideally prefer not to have a separate list of leaf constraints to track the IsDuplicated stuff 🤔 Why is it difficult to put IsDuplicated as a flag on the UndoLog entry that marks it as a no-op to undo. There's a comment on the region constraint storage stating that we can do this once VisibleForLeakCheck is gone, but I don't understand why we can't do that already ✨

@adwinwhite

adwinwhite commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

not certain I understand the reason why this is the solution arrived at

Oh, I felt the PR description was too short but couldn't realize what was missing. This is the missing part.

so just gonna ramble a bit and you can tell me if I'm understanding correctly or not xd

Yeah, your understanding is totally correct, I think.

First, why do we wish to store VisibleForLeakCheck out of band in the region constraint storage instead of as part of RegionConstraint

The main reason is that even if we store it in the region constraint storage, we still have to track un-deduplicated VisibleForLeakCheck somewhere to support undo log rollback. Merging VisibleForLeakChecks is not a reversible operation.
The second reason is that it complicates the deduplication when constructing And. We have to erase the VisibleForLeakChecks when checking whether a new leaf is a duplicate. Similar to what we did for spans previously.
The third reason is that it adds a lot of boilerplate to region constraint handling when we actually only have a few places that care about VisibleForLeakCheck.

The other thing is that I would ideally prefer not to have a separate list of leaf constraints to track the IsDuplicated stuff 🤔 Why is it difficult to put IsDuplicated as a flag on the UndoLog entry that marks it as a no-op to undo. There's a comment on the region constraint storage stating that we can do this once VisibleForLeakCheck is gone, but I don't understand why we can't do that already ✨

We can totally put IsDuplicate on the undo log entry. I put it in the separate list simply because it leaks less abby_storage details out. And now that we must have a separate list due to VisibleForLeakCheck, we can use it a little more.

Another solution I tried is putting both (VisibleForLeakCheck, index_to_and_constraint) and IsDuplicate on the undo log entry.
This is like treating the undo log as the separate list.
The problem is that we don't push log entries if we're not in a snapshot, so the visibility info is lost.

@BoxyUwU

BoxyUwU commented Nov 26, 2026

Copy link
Copy Markdown
Member

I put it in the separate list simply because it leaks less abby_storage details out

Ah interesting that makes sense. I think of it kinda from the other direction- the reason we cant deduplicate is because we always need an UndoLog entry, and we always need an UndoLog entry because of snapshot-based leak checks. So to me the IsDuplicate feels very fundamentally tied to the leak check.

Having it be in the storage feels like leaking leak check details into the storage whereas having it in the UndoLog just feels like leaking leak check details into the UndoLog which feels more-fine because leak check does weird things with UndoLog anyway ✨

The third reason is that it adds a lot of boilerplate to region constraint handling when we actually only have a few places that care about VisibleForLeakCheck.

this makes sense to me 🤔 thinking of visible for leak check as a thing the storage associates with each constraint, instead of a thing on each constraint, actually seems kinda nice conceptually to me. especially with one of my ideas about reworking the existing storage to be more of a "list of constraints" rather than one big combined constraint.


I think that in the short term I would quite like us to clean up the storage to have it just be a Vec<(VisibleForLeakCheck, RegionConstraint<TyCtxt<'tcx>>)> (maybe we'd move the Span information out too?). And when we do this I think it would also be fine to just have duplicate entries in the Vec. Doing that would I think massively clean this up and seems very nice :3

I'm happy to not do that in this PR though because I would really quite like to have leak check support abby constraints 😅 Could you slap a FIXME on leafs_not_deduplicated to point to rust-lang/project-assumptions-on-binders#60 saying we should rework this in the long term 🤔 Also add more of a comment explaining the context we just discussed :3

#[instrument(skip(self), level = "trace")]
fn regions(&mut self, a: Region<I>, b: Region<I>) -> RelateResult<I, Region<I>> {
self.infcx.equate_regions(a, b, VisibleForLeakCheck::Yes, self.span);
if self.cx().assumptions_on_binders() {

@BoxyUwU BoxyUwU Nov 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what got you to catch on to the fact that we were silently dropping constraints here

View changes since the review

@adwinwhite adwinwhite Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests was not working and I was upset :3

@BoxyUwU

BoxyUwU commented Nov 26, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2026
@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@adwinwhite

adwinwhite commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

So to me the IsDuplicate feels very fundamentally tied to the leak check.

We'd still need IsDuplicate somewhere even if we don't have leak check.
Imagine we perform rolling back without IsDuplicate markers. We push leaf-0, push leaf-1, enter a snapshot, push a duplicate leaf-0. Now we have indices [0, 1, | 0] in undo log and rollback is easy since 0 is obviously a duplicate. What if we have indices [0, 1,| 1] or [0, | 1, 1]? We can't decide whether to pop the leafs in the snapshot.

I think that in the short term I would quite like us to clean up the storage to have it just be a Vec<(VisibleForLeakCheck, RegionConstraint<TyCtxt<'tcx>>)> (maybe we'd move the Span information out too?). And when we do this I think it would also be fine to just have duplicate entries in the Vec. Doing that would I think massively clean this up and seems very nice :3

Cool solution to the Or constraints blow up and this deduplication problem ✨

@rust-log-analyzer

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@adwinwhite

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2026

This branch has not been deployed

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make undolog good support VisibleForLeakCheck

4 participants