Repository navigation
Bad MIR spans #99854
Copy link
Copy link
Open
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Activity
This is trivially false in the face of macros and MIR function inlining, right?
#[inline(always)] fn inline_me() -> u32 { 42 } pub fn root() -> u32 { inline_me() }
when compiled with nightly and optimizations enabled gives the following MIR:
fn root() -> u32 { let mut _0: u32; // return place in scope 0 at src/lib.rs:6:18: 6:21 scope 1 (inlined inline_me) { // at src/lib.rs:7:5: 7:16 } bb0: { _0 = const 42_u32; // scope 1 at src/lib.rs:3:5: 3:7 return; // scope 0 at src/lib.rs:8:2: 8:2 } }
_0 = const 42_u32;here is not contained insideroot.Good point, I did not consider this. I guess then the assertion should not be added, and the spans from outside should be better dealt with (I am not sure how that would look like though).
cc @oli-obk
Yea, I think we should not use relative offsets unless the span is within the function's span. Basically fallback to just the original span in that case
Reacted by noraThat sounds good, I'll improve that.
There are still a few issues that should be improved: #99908 (comment)
@rustbot label +A-mir
- addedA-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
on Mar 31, 2023 - addedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Apr 5, 2023
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
In #99780 (comment), I tried to add an assertion in the span formatting function to validate that the span for the
mir::Body.spanspan always contains all spans of MIR statements/terminators.But this assertion failed for many tests. One such case was for associated constants.
We should investigate all the cases where the MIR body span is not fully correct, and add the assertion back in.