-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Check coroutine upvars in dtorck constraint #144156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Yeah, I guess the resume ty doesn't need to be checked since although it can contain lifetimes, it would need to be stored in a witness ty to actually be dropped (since it doesn't have its own storage) and so it's redundant wrt the witness part of this drop check. |
bde52d9
to
a6cc0fe
Compare
compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs
Outdated
Show resolved
Hide resolved
a6cc0fe
to
f2e14da
Compare
compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs
Outdated
Show resolved
Hide resolved
f2e14da
to
f1410f8
Compare
Tweaked the comment a bit more and implemented the modified check that only requires the upvars be drop-live if there are no drops in the interior. |
Also tweaked this comment to use "interior" rather than flopping between "witness" and "interior". TBH i kinda prefer that name over witness, and at least for the purposes of this explanation it makes it clear that it's types that are local to the body of the coroutine. |
f1410f8
to
9b0b433
Compare
Also added a test for the upvar breakage. |
Hi @rust-lang/types, I previously assumed that every type stored in a coroutine is part of its witness. This assumption caused us to only require things to be live when dropping the coroutine if the witness required drop in #117134. This is not the case as we may capture upvars by value. These upvars are not considered part of the witness, but still need to get dropped when dropping the coroutine. This PR updates the comment to better explain what's going on and fixes this issue. We now require all upvars to be drop-live regardless of whether the coroutine witness has anything that needs to be drop. @rfcbot fcp merge I think we should still do a crater run? |
Team member @lcnr has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@bors2 try |
Check coroutine upvars in dtorck constraint
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
☔ The latest upstream changes (presumably #144458) made this pull request unmergeable. Please resolve the merge conflicts. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@rustbot author |
9b0b433
to
a223099
Compare
a223099
to
560e5dc
Compare
@rustbot ready |
@bors r+ |
Rollup of 5 pull requests Successful merges: - #135331 (Reject relaxed bounds inside associated type bounds (ATB)) - #144156 (Check coroutine upvars in dtorck constraint) - #145091 (`NllRegionVariableOrigin` remove `from_forall`) - #145194 (Ignore coroutine witness type region args in auto trait confirmation) - #145225 (Fix macro infinite recursion test to not trigger warning about semicolon in expr) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144156 - compiler-errors:dtorck-upvars, r=lcnr Check coroutine upvars in dtorck constraint Fix #144155. This PR fixes an unsoundness where we were not considering coroutine upvars as drop-live if the coroutine interior types (witness types) had nothing which required drop. In the case that the coroutine does not have any interior types that need to be dropped, then we don't need to treat all of the upvars as use-live; instead, this PR uses the same logic as closures, and descends into the upvar types to collect anything that must be drop-live. The rest of this PR is reworking the comment to explain the behavior here. r? `@lcnr` or reassign 😸 --- Just some thoughts --- a proper fix for this whole situation would be to consider `TypingMode` in the `needs_drop` function, and just calling `coroutine_ty.needs_drop(tcx, typing_env)` in the dtorck constraint check. During MIR building, we should probably use a typing mode that stalls the local coroutines and considers them to be unconditionally drop, or perhaps just stall *all* coroutines in analysis mode. Then in borrowck mode, we can re-check `needs_drop` but descend into witness types properly. #144158 implements this experimentally. This is a pretty involved fix, and conflicts with some in-flight changes (#144157) that I have around removing coroutine witnesses altogether. I'm happy to add a FIXME to rework this whole approach, but I don't want to block this quick fix since it's obviously more correct than the status-quo.
Fix #144155.
This PR fixes an unsoundness where we were not considering coroutine upvars as drop-live if the coroutine interior types (witness types) had nothing which required drop.
In the case that the coroutine does not have any interior types that need to be dropped, then we don't need to treat all of the upvars as use-live; instead, this PR uses the same logic as closures, and descends into the upvar types to collect anything that must be drop-live. The rest of this PR is reworking the comment to explain the behavior here.
r? @lcnr or reassign 😸
Just some thoughts --- a proper fix for this whole situation would be to consider
TypingMode
in theneeds_drop
function, and just callingcoroutine_ty.needs_drop(tcx, typing_env)
in the dtorck constraint check.During MIR building, we should probably use a typing mode that stalls the local coroutines and considers them to be unconditionally drop, or perhaps just stall all coroutines in analysis mode. Then in borrowck mode, we can re-check
needs_drop
but descend into witness types properly. #144158 implements this experimentally.This is a pretty involved fix, and conflicts with some in-flight changes (#144157) that I have around removing coroutine witnesses altogether. I'm happy to add a FIXME to rework this whole approach, but I don't want to block this quick fix since it's obviously more correct than the status-quo.