Skip to content

Dispatch MIR pipeline by BodyOwnerKind instead of const context#155808

Open
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_155803
Open

Dispatch MIR pipeline by BodyOwnerKind instead of const context#155808
lapla-cogito wants to merge 1 commit intorust-lang:mainfrom
lapla-cogito:issue_155803

Conversation

@lapla-cogito
Copy link
Copy Markdown
Contributor

@lapla-cogito lapla-cogito commented Apr 26, 2026

fixes #155803

Since e8a4611, hir_body_const_context() returns the parent's const context for a const closure. However inner_optimized_mir() and inner_mir_for_ctfe() were using hir_body_const_context() to decide which MIR pipeline a body goes through. With the new semantics, a const closure nested in a const item gets classified as a constant, so under -Clink-dead-code we either hit "do not use optimized_mir for constants" or steal a body that optimized_mir still needs.

r? oli-obk (since you authored the commit mentioned above, feel free to reroll)

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Apr 26, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 26, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@oli-obk
Copy link
Copy Markdown
Contributor

oli-obk commented Apr 26, 2026

Hmmm. We shouldn't ever invoke optimized_mir on const closures defined in const items I think?

Tho I guess with an opaque type as the const's type we could indeed return a const closure. Or just via a const item of fn ptr type?

I'll need to think about this some more, but if you have any thoughts about it lmk. Please add tests for both of these situations, too.

@rust-log-analyzer

This comment has been minimized.

@lapla-cogito
Copy link
Copy Markdown
Contributor Author

lapla-cogito commented Apr 26, 2026

We shouldn't ever invoke optimized_mir on const closures defined in const items I think?

Is this because const items are only evaluated during CTFE (IIUC)? If so, the examples you mention are counterexamples.

Tho I guess with an opaque type as the const's type we could indeed return a const closure. Or just via a const item of fn ptr type?

I've added a test for the fn ptr type variant, which causes an ICE on current nightly. I also tried opaque-type variants, but they were rejected by unrelated checks before reaching the ICE path 🤔
Therefore, I think there's now a stronger case for invoking optimized_mir on const closures defined inside const items. Thanks.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: do not use optimized_mir for constants: Const { inline: false }

4 participants