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

Rollup of 6 pull requests #138884

Closed
wants to merge 14 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions compiler/rustc_mir_build/src/builder/matches/mod.rs
Original file line number Diff line number Diff line change
@@ -13,13 +13,13 @@ use std::sync::Arc;
use rustc_abi::VariantIdx;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::{BindingMode, ByRef};
use rustc_hir::{BindingMode, ByRef, LetStmt, LocalSource, Node};
use rustc_middle::bug;
use rustc_middle::middle::region;
use rustc_middle::mir::{self, *};
use rustc_middle::thir::{self, *};
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
use rustc_span::{BytePos, Pos, Span, Symbol};
use rustc_span::{BytePos, Pos, Span, Symbol, sym};
use tracing::{debug, instrument};

use crate::builder::ForGuard::{self, OutsideGuard, RefWithinGuard};
@@ -2796,13 +2796,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
)))),
};
let for_arm_body = self.local_decls.push(local);
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(for_arm_body.into()),
composite: None,
argument_index: None,
});
if self.should_emit_debug_info_for_binding(name, var_id) {
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(for_arm_body.into()),
composite: None,
argument_index: None,
});
}
let locals = if has_guard.0 {
let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
// This variable isn't mutated but has a name, so has to be
@@ -2815,18 +2817,42 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
BindingForm::RefForGuard,
))),
});
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(ref_for_guard.into()),
composite: None,
argument_index: None,
});
if self.should_emit_debug_info_for_binding(name, var_id) {
self.var_debug_info.push(VarDebugInfo {
name,
source_info: debug_source_info,
value: VarDebugInfoContents::Place(ref_for_guard.into()),
composite: None,
argument_index: None,
});
}
LocalsForNode::ForGuard { ref_for_guard, for_arm_body }
} else {
LocalsForNode::One(for_arm_body)
};
debug!(?locals);
self.var_indices.insert(var_id, locals);
}

/// Some bindings are introduced when producing HIR from the AST and don't
/// actually exist in the source. Skip producing debug info for those when
/// we can recognize them.
fn should_emit_debug_info_for_binding(&self, name: Symbol, var_id: LocalVarId) -> bool {
// For now we only recognize the output of desugaring assigns.
if name != sym::lhs {
return true;
}

let tcx = self.tcx;
for (_, node) in tcx.hir_parent_iter(var_id.0) {
// FIXME(khuey) at what point is it safe to bail on the iterator?
// Can we stop at the first non-Pat node?
if matches!(node, Node::LetStmt(&LetStmt { source: LocalSource::AssignDesugar(_), .. }))
{
return false;
}
}

true
}
}
18 changes: 18 additions & 0 deletions tests/codegen/assign-desugar-debuginfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ compile-flags: -g -Zmir-opt-level=0

#![crate_type = "lib"]

#[inline(never)]
fn swizzle(a: u32, b: u32, c: u32) -> (u32, (u32, u32)) {
(b, (c, a))
}

pub fn work() {
let mut a = 1;
let mut b = 2;
let mut c = 3;
(a, (b, c)) = swizzle(a, b, c);
println!("{a} {b} {c}");
}

// CHECK-NOT: !DILocalVariable(name: "lhs",