Skip to content
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

Remove coroutine info when building coroutine drop body #120330

Merged

Conversation

compiler-errors
Copy link
Member

Coroutine drop shims are not themselves coroutines, so erase the "coroutine" field from the body so that helper fns like yield_ty and coroutine_kind properly return None for the drop shim.

@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2024

r? @nnethercote

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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. labels Jan 25, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 25, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the no-coroutine-info-in-coroutine-drop-body branch from eca402b to 7f9648d Compare January 25, 2024 03:10
@@ -1,25 +1,4 @@
// MIR for `main::{closure#0}` 0 coroutine_drop
/* coroutine_layout = CoroutineLayout {
Copy link
Member Author

Choose a reason for hiding this comment

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

(Unsurprisingly, coroutine layout is not present in the drop shim body anymore. This does affect the MIR dump, but does not affect the drop's codegen.)

@@ -303,6 +308,7 @@ pub struct Body<'tcx> {
/// and used for debuginfo. Indexed by a `SourceScope`.
pub source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,

/// Additional information carried by a MIR body when it is lowered from a coroutine.
Copy link
Contributor

Choose a reason for hiding this comment

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

Brief mention of when it goes from Some to None would be good.

Copy link
Member Author

@compiler-errors compiler-errors Jan 25, 2024

Choose a reason for hiding this comment

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

So this never goes from Some to None for normal MIR bodies. The only reason it "goes from Some to None" when we're building the coroutine drop shim is because we're cloning the whole MIR body struct (presumably out out of convenience) rather than, for example, just copying the basic blocks and locals into a fresh body.

The idea is that this is just basically "take what we can from the parent MIR body, and then just fix up what is wrong". Other body information is patched up at the same time, such as the source and arg_count, and I don't believe that it makes sense to leave a parallel comment on arg_count, for example.

I can leave a comment on the take call below though.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be great info to put into the comment! E.g. "Some" in the normal case, None only when we're building the coroutine drop shim".

Copy link
Member Author

Choose a reason for hiding this comment

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

None only when we're building the coroutine drop shim

And every other MIR body, not just coroutine drop shims. Which is why I think it feels redundant to note this, since this already says "when it is lowered from a coroutine".

Copy link
Contributor

Choose a reason for hiding this comment

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

The final version looks fine, thanks!

@nnethercote
Copy link
Contributor

r=me with the nits addressed.

@rust-cloud-vms rust-cloud-vms bot force-pushed the no-coroutine-info-in-coroutine-drop-body branch from 7f9648d to 56fe4d6 Compare January 25, 2024 03:27
@rust-cloud-vms rust-cloud-vms bot force-pushed the no-coroutine-info-in-coroutine-drop-body branch from 56fe4d6 to 07b7c77 Compare January 25, 2024 04:44
@compiler-errors
Copy link
Member Author

that should be sufficient

@bors r=nnethercote

@bors
Copy link
Contributor

bors commented Jan 25, 2024

📌 Commit 07b7c77 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 25, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 25, 2024
…in-coroutine-drop-body, r=nnethercote

Remove coroutine info when building coroutine drop body

Coroutine drop shims are not themselves coroutines, so erase the "`coroutine`" field from the body so that helper fns like `yield_ty` and `coroutine_kind` properly return `None` for the drop shim.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#118208 (Rewrite the BTreeMap cursor API using gaps)
 - rust-lang#120099 (linker: Refactor library linking methods in `trait Linker`)
 - rust-lang#120165 (Switch `NonZero` alias direction.)
 - rust-lang#120288 (Bump `askama` version)
 - rust-lang#120306 (Clean up after clone3 removal from pidfd code (docs and tests))
 - rust-lang#120316 (Don't call `walk_` functions directly if there is an equivalent `visit_` method)
 - rust-lang#120330 (Remove coroutine info when building coroutine drop body)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 25, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#118208 (Rewrite the BTreeMap cursor API using gaps)
 - rust-lang#120099 (linker: Refactor library linking methods in `trait Linker`)
 - rust-lang#120288 (Bump `askama` version)
 - rust-lang#120306 (Clean up after clone3 removal from pidfd code (docs and tests))
 - rust-lang#120316 (Don't call `walk_` functions directly if there is an equivalent `visit_` method)
 - rust-lang#120330 (Remove coroutine info when building coroutine drop body)
 - rust-lang#120332 (Remove unused struct)
 - rust-lang#120338 (Fix links to [strict|exposed] provenance sections of `[std|core]::ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4bca954 into rust-lang:master Jan 26, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2024
Rollup merge of rust-lang#120330 - compiler-errors:no-coroutine-info-in-coroutine-drop-body, r=nnethercote

Remove coroutine info when building coroutine drop body

Coroutine drop shims are not themselves coroutines, so erase the "`coroutine`" field from the body so that helper fns like `yield_ty` and `coroutine_kind` properly return `None` for the drop shim.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants