Skip to content

Commit bc3424b

Browse files
authored
Rollup merge of rust-lang#56278 - eddyb:mir-debuginfo-proof, r=nikomatsakis
Future-proof MIR for dedicated debuginfo. This is rust-lang#56231 without the last commit (the one that actually moves to `VarDebuginfo`). Nothing should be broken, but it should no longer depend on debuginfo for anything else. r? @nikomatsakis
2 parents e938c2b + c3ca9a3 commit bc3424b

File tree

28 files changed

+318
-254
lines changed

28 files changed

+318
-254
lines changed

src/librustc/mir/mod.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::hir::def::{CtorKind, Namespace};
66
use crate::hir::def_id::DefId;
7-
use crate::hir::{self, HirId, InlineAsm as HirInlineAsm};
7+
use crate::hir::{self, InlineAsm as HirInlineAsm};
88
use crate::mir::interpret::{ConstValue, InterpError, Scalar};
99
use crate::mir::visit::MirVisitable;
1010
use rustc_apfloat::ieee::{Double, Single};
@@ -138,16 +138,20 @@ pub struct Mir<'tcx> {
138138
/// If this MIR was built for a constant, this will be 0.
139139
pub arg_count: usize,
140140

141-
/// Names and capture modes of all the closure upvars, assuming
142-
/// the first argument is either the closure or a reference to it.
143-
pub upvar_decls: Vec<UpvarDecl>,
144-
145141
/// Mark an argument local (which must be a tuple) as getting passed as
146142
/// its individual components at the LLVM level.
147143
///
148144
/// This is used for the "rust-call" ABI.
149145
pub spread_arg: Option<Local>,
150146

147+
/// Names and capture modes of all the closure upvars, assuming
148+
/// the first argument is either the closure or a reference to it.
149+
// NOTE(eddyb) This is *strictly* a temporary hack for codegen
150+
// debuginfo generation, and will be removed at some point.
151+
// Do **NOT** use it for anything else, upvar information should not be
152+
// in the MIR, please rely on local crate HIR or other side-channels.
153+
pub __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
154+
151155
/// Mark this MIR of a const context other than const functions as having converted a `&&` or
152156
/// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop
153157
/// this conversion from happening and use short circuiting, we will cause the following code
@@ -173,7 +177,7 @@ impl<'tcx> Mir<'tcx> {
173177
local_decls: LocalDecls<'tcx>,
174178
user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
175179
arg_count: usize,
176-
upvar_decls: Vec<UpvarDecl>,
180+
__upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
177181
span: Span,
178182
control_flow_destroyed: Vec<(Span, String)>,
179183
) -> Self {
@@ -197,7 +201,7 @@ impl<'tcx> Mir<'tcx> {
197201
local_decls,
198202
user_type_annotations,
199203
arg_count,
200-
upvar_decls,
204+
__upvar_debuginfo_codegen_only_do_not_use,
201205
spread_arg: None,
202206
span,
203207
cache: cache::Cache::new(),
@@ -431,7 +435,7 @@ impl_stable_hash_for!(struct Mir<'tcx> {
431435
local_decls,
432436
user_type_annotations,
433437
arg_count,
434-
upvar_decls,
438+
__upvar_debuginfo_codegen_only_do_not_use,
435439
spread_arg,
436440
control_flow_destroyed,
437441
span,
@@ -983,16 +987,11 @@ impl<'tcx> LocalDecl<'tcx> {
983987

984988
/// A closure capture, with its name and mode.
985989
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
986-
pub struct UpvarDecl {
990+
pub struct UpvarDebuginfo {
987991
pub debug_name: Name,
988992

989-
/// `HirId` of the captured variable
990-
pub var_hir_id: ClearCrossCrate<HirId>,
991-
992993
/// If true, the capture is behind a reference.
993994
pub by_ref: bool,
994-
995-
pub mutability: Mutability,
996995
}
997996

998997
///////////////////////////////////////////////////////////////////////////
@@ -3156,7 +3155,7 @@ CloneTypeFoldableAndLiftImpls! {
31563155
MirPhase,
31573156
Mutability,
31583157
SourceInfo,
3159-
UpvarDecl,
3158+
UpvarDebuginfo,
31603159
FakeReadCause,
31613160
RetagKind,
31623161
SourceScope,
@@ -3178,7 +3177,7 @@ BraceStructTypeFoldableImpl! {
31783177
local_decls,
31793178
user_type_annotations,
31803179
arg_count,
3181-
upvar_decls,
3180+
__upvar_debuginfo_codegen_only_do_not_use,
31823181
spread_arg,
31833182
control_flow_destroyed,
31843183
span,

src/librustc/mir/tcx.rs

-35
Original file line numberDiff line numberDiff line change
@@ -133,41 +133,6 @@ impl<'tcx> Place<'tcx> {
133133
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
134134
}
135135
}
136-
137-
/// If this is a field projection, and the field is being projected from a closure type,
138-
/// then returns the index of the field being projected. Note that this closure will always
139-
/// be `self` in the current MIR, because that is the only time we directly access the fields
140-
/// of a closure type.
141-
pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
142-
tcx: &TyCtxt<'cx, 'gcx, 'tcx>) -> Option<Field> {
143-
let (place, by_ref) = if let Place::Projection(ref proj) = self {
144-
if let ProjectionElem::Deref = proj.elem {
145-
(&proj.base, true)
146-
} else {
147-
(self, false)
148-
}
149-
} else {
150-
(self, false)
151-
};
152-
153-
match place {
154-
Place::Projection(ref proj) => match proj.elem {
155-
ProjectionElem::Field(field, _ty) => {
156-
let base_ty = proj.base.ty(mir, *tcx).ty;
157-
158-
if (base_ty.is_closure() || base_ty.is_generator()) &&
159-
(!by_ref || mir.upvar_decls[field.index()].by_ref)
160-
{
161-
Some(field)
162-
} else {
163-
None
164-
}
165-
},
166-
_ => None,
167-
}
168-
_ => None,
169-
}
170-
}
171136
}
172137

173138
pub enum RvalueInitializationState {

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
542542
finalize(self)
543543
}
544544

545-
fn debuginfo_upvar_decls_ops_sequence(&self, byte_offset_of_var_in_env: u64) -> [i64; 4] {
545+
fn debuginfo_upvar_ops_sequence(&self, byte_offset_of_var_in_env: u64) -> [i64; 4] {
546546
unsafe {
547547
[llvm::LLVMRustDIBuilderCreateOpDeref(),
548548
llvm::LLVMRustDIBuilderCreateOpPlusUconst(),

src/librustc_codegen_ssa/mir/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,10 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
598598
tmp
599599
}
600600
};
601+
let upvar_debuginfo = &mir.__upvar_debuginfo_codegen_only_do_not_use;
601602
arg_scope.map(|scope| {
602603
// Is this a regular argument?
603-
if arg_index > 0 || mir.upvar_decls.is_empty() {
604+
if arg_index > 0 || upvar_debuginfo.is_empty() {
604605
// The Rust ABI passes indirect variables using a pointer and a manual copy, so we
605606
// need to insert a deref here, but the C ABI uses a pointer and a copy using the
606607
// byval attribute, for which LLVM always does the deref itself,
@@ -638,16 +639,16 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
638639
let (def_id, upvar_substs) = match closure_layout.ty.sty {
639640
ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)),
640641
ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
641-
_ => bug!("upvar_decls with non-closure arg0 type `{}`", closure_layout.ty)
642+
_ => bug!("upvar debuginfo with non-closure arg0 type `{}`", closure_layout.ty)
642643
};
643644
let upvar_tys = upvar_substs.upvar_tys(def_id, tcx);
644645

645646
let extra_locals = {
646-
let upvars = mir.upvar_decls
647+
let upvars = upvar_debuginfo
647648
.iter()
648649
.zip(upvar_tys)
649650
.enumerate()
650-
.map(|(i, (decl, ty))| (i, decl.debug_name, decl.by_ref, ty));
651+
.map(|(i, (upvar, ty))| (i, upvar.debug_name, upvar.by_ref, ty));
651652

652653
let generator_fields = mir.generator_layout.as_ref().map(|generator_layout| {
653654
let (def_id, gen_substs) = match closure_layout.ty.sty {
@@ -656,7 +657,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
656657
};
657658
let state_tys = gen_substs.state_tys(def_id, tcx);
658659

659-
let upvar_count = mir.upvar_decls.len();
660+
let upvar_count = upvar_debuginfo.len();
660661
generator_layout.fields
661662
.iter()
662663
.zip(state_tys)
@@ -673,7 +674,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
673674
for (field, name, by_ref, ty) in extra_locals {
674675
let byte_offset_of_var_in_env = closure_layout.fields.offset(field).bytes();
675676

676-
let ops = bx.debuginfo_upvar_decls_ops_sequence(byte_offset_of_var_in_env);
677+
let ops = bx.debuginfo_upvar_ops_sequence(byte_offset_of_var_in_env);
677678

678679
// The environment and the capture can each be indirect.
679680
let mut ops = if env_ref { &ops[..] } else { &ops[1..] };

src/librustc_codegen_ssa/traits/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait DebugInfoMethods<'tcx>: BackendTypes {
3737
defining_crate: CrateNum,
3838
) -> Self::DIScope;
3939
fn debuginfo_finalize(&self);
40-
fn debuginfo_upvar_decls_ops_sequence(&self, byte_offset_of_var_in_env: u64) -> [i64; 4];
40+
fn debuginfo_upvar_ops_sequence(&self, byte_offset_of_var_in_env: u64) -> [i64; 4];
4141
}
4242

4343
pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {

src/librustc_mir/borrow_check/error_reporting.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
10881088
| LocalKind::Temp => bug!("temporary or return pointer with a name"),
10891089
LocalKind::Var => "local variable ",
10901090
LocalKind::Arg
1091-
if !self.mir.upvar_decls.is_empty()
1091+
if !self.upvars.is_empty()
10921092
&& local == Local::new(1) => {
10931093
"variable captured by `move` "
10941094
}
@@ -1632,11 +1632,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16321632
match proj.elem {
16331633
ProjectionElem::Deref => {
16341634
let upvar_field_projection =
1635-
place.is_upvar_field_projection(self.mir, &self.infcx.tcx);
1635+
self.is_upvar_field_projection(place);
16361636
if let Some(field) = upvar_field_projection {
16371637
let var_index = field.index();
1638-
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
1639-
if self.mir.upvar_decls[var_index].by_ref {
1638+
let name = self.upvars[var_index].name.to_string();
1639+
if self.upvars[var_index].by_ref {
16401640
buf.push_str(&name);
16411641
} else {
16421642
buf.push_str(&format!("*{}", &name));
@@ -1694,10 +1694,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16941694
autoderef = true;
16951695

16961696
let upvar_field_projection =
1697-
place.is_upvar_field_projection(self.mir, &self.infcx.tcx);
1697+
self.is_upvar_field_projection(place);
16981698
if let Some(field) = upvar_field_projection {
16991699
let var_index = field.index();
1700-
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
1700+
let name = self.upvars[var_index].name.to_string();
17011701
buf.push_str(&name);
17021702
} else {
17031703
let field_name = self.describe_field(&proj.base, field);

0 commit comments

Comments
 (0)