Skip to content

Field accesses in debuginfo are treated as real uses of the base local #77454

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jonas-schievink opened this issue Oct 2, 2020 · 3 comments · Fixed by #79080
Closed

Field accesses in debuginfo are treated as real uses of the base local #77454

jonas-schievink opened this issue Oct 2, 2020 · 3 comments · Fixed by #79080
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

MIR may contain debuginfo like this after inlining:

    scope 1 {
        debug x => _3;                   // in scope 1 at $DIR/inline-closure-captures.rs:11:9: 11:10
        scope 2 {
            debug _q => _10;             // in scope 2 at $DIR/inline-closure-captures.rs:11:14: 11:16
            debug q => (*((*_6).0: &i32)); // in scope 2 at $DIR/inline-closure-captures.rs:10:23: 10:24
            debug t => (*((*_6).1: &T)); // in scope 2 at $DIR/inline-closure-captures.rs:10:17: 10:18
            let mut _9: T;               // in scope 2 at $DIR/inline-closure-captures.rs:12:5: 12:9
        }
    }

Here, the field access (*_6).0 is treated like a use of the _6 local in MIR visitors (using PlaceContext::NonMutatingUse), even though it is not an actual use of _6.

Instead, it should be using PlaceContext::NonUse(NonUseContext::VarDebugInfo).

@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. A-mir-opt Area: MIR optimizations labels Oct 2, 2020
@jyn514 jyn514 added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Oct 2, 2020
@camelid camelid self-assigned this Nov 15, 2020
@camelid
Copy link
Member

camelid commented Nov 15, 2020

@jonas-schievink Can you describe where the change needs to be made? The visit method for debuginfo seems to be correct:

fn super_var_debug_info(&mut self,
var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) {
let VarDebugInfo {
name: _,
source_info,
place,
} = var_debug_info;
self.visit_source_info(source_info);
let location = START_BLOCK.start_location();
self.visit_place(
place,
PlaceContext::NonUse(NonUseContext::VarDebugInfo),
location,
);
}

It shells out to visit_place with PlaceContext::NonUse(NonUseContext::VarDebugInfo), and visit_place then shells out through some other methods to visit_projection_elem. visit_projection_elem isn't getting the PlaceContext that visit_place was called with (I guess because the context of a projection is potentially different than that of the local it's projecting), but it seems to do nothing for field accesses:

match elem {
PlaceElem::Index(local) => {
let mut new_local = local;
self.visit_local(
&mut new_local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
location,
);
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
}
PlaceElem::Deref
| PlaceElem::Field(..)
| PlaceElem::ConstantIndex { .. }
| PlaceElem::Subslice { .. }
| PlaceElem::Downcast(..) => None,
}

So what part should I change? Thanks!

@jonas-schievink
Copy link
Contributor Author

Looks like the problem is here:

context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};

@camelid
Copy link
Member

camelid commented Nov 15, 2020

Okay, thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants