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

Fix cycle error only occurring with -Zdump-mir #134498

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Dec 19, 2024

fixes #134205

During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).

Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Dec 19, 2024
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Thanks, the impl changes look good to me, however the MIR test differences I don't know well -- it feels like some mir-opt tests actually do want the alloc contents to be in the dump (but that -Zdump-mir as-is might be insufficient?).

Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: could you slightly elaborate what this test intends to check (i.e. just the PR description)?

@oli-obk
Copy link
Contributor Author

oli-obk commented Dec 19, 2024

it feels like some mir-opt tests actually do want the alloc contents to be in the dump (but that -Zdump-mir as-is might be insufficient?).

yea. I think we can make some (most) of these work again by just avoiding the evaluation if we're in a const context, I'll give it a shot

@jieyouxu jieyouxu self-assigned this Dec 19, 2024
@jieyouxu jieyouxu 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 Dec 19, 2024
@jieyouxu jieyouxu removed their assignment Dec 19, 2024
@oli-obk oli-obk force-pushed the push-wmxynprsyxvr branch from 5518ddb to 55b6063 Compare January 7, 2025 10:43
@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2025

@rustbot ready

r? compiler

Yea, the fix is now much more targeted and I couldn't come up with a situation where it could cause cycles through a non-const function

@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 Jan 7, 2025
@rustbot rustbot assigned compiler-errors and unassigned Nadrieril Jan 7, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Doesn't this still cycle when building the .after.mir after optimized mir is done building? Can you test this with -Zdump-mir locally?

@compiler-errors
Copy link
Member

The comment that I left in the issue also noted that the last dump of MIR needs to happen outside of the query itself. As long as we are dumping MIR from within a query, this has the potential to be cyclical?

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 7, 2025

Hypothetically yes, but to get the optimized MIR from the const eval queries we'd need to have something that checks the optimized MIR for body-leaky information like "does this have panics after optimizations?". I see no other way we'd end up getting the optimized MIR from const eval without that being a bug, so invoking const eval is fine from optimized MIR (as it only uses mir_for_ctfe).

It would be more consistent to just never dump the statics as I had it previously, as then the MIR of a const fn and a normal fn would be the same if the constness was the only difference.

Doesn't this still cycle when building the .after.mir after optimized mir is done building? Can you test this with -Zdump-mir locally?

no, I get

// MIR for `thing` after runtime-optimized

fn thing() -> &Thing {
    let mut _0: &Thing;

    bb0: {
        _0 = const {alloc3: &Thing};
        return;
    }
}

alloc3 (static: MUTUALLY_RECURSIVE, size: 8, align: 8) {
    ╾─────alloc3<imm>─────╼                         │ ╾──────╼
}

in dump_mir_cycle.thing.006-000.runtime-optimized.after.mir

@oli-obk oli-obk force-pushed the push-wmxynprsyxvr branch 3 times, most recently from 325a742 to aabbc61 Compare January 9, 2025 09:24
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 13, 2025

📌 Commit 15c01eb has been approved by compiler-errors

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 13, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 13, 2025
…ler-errors

Fix cycle error only occurring with -Zdump-mir

fixes rust-lang#134205

During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).

Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 13, 2025
…ler-errors

Fix cycle error only occurring with -Zdump-mir

fixes rust-lang#134205

During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).

Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 13, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#134498 (Fix cycle error only occurring with -Zdump-mir)
 - rust-lang#135440 (rm unnecessary `OpaqueTypeDecl` wrapper)
 - rust-lang#135441 (Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024)
 - rust-lang#135444 (Update books)
 - rust-lang#135451 (Remove code duplication when hashing query result and interning node)
 - rust-lang#135452 (bootstrap: fix outdated feature name in comment)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#134498 (Fix cycle error only occurring with -Zdump-mir)
 - rust-lang#134977 (Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion)
 - rust-lang#135390 (Re-added regression test for rust-lang#122638)
 - rust-lang#135393 (uefi: helpers: Introduce OwnedDevicePath)
 - rust-lang#135440 (rm unnecessary `OpaqueTypeDecl` wrapper)
 - rust-lang#135441 (Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024)
 - rust-lang#135444 (Update books)
 - rust-lang#135450 (Fix emscripten-wasm-eh with unwind=abort)
 - rust-lang#135452 (bootstrap: fix outdated feature name in comment)
 - rust-lang#135454 (llvm: Allow sized-word rather than ymmword in tests)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 81f7429 into rust-lang:master Jan 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2025
Rollup merge of rust-lang#134498 - oli-obk:push-wmxynprsyxvr, r=compiler-errors

Fix cycle error only occurring with -Zdump-mir

fixes rust-lang#134205

During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).

Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
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.

-Zdump-mir introduces cycle in static containing static reference
6 participants