Skip to content

Commit 090ad6f

Browse files
committed
Auto merge of #27346 - dotdash:closure_dbg, r=michaelwoerister
Closure variables represent the closure environment, not the closure function, so the identifier used to ensure that the debuginfo is unique for each kind of closure needs to be based on the closure upvars and not the function signature.
2 parents ddbce11 + 218eccf commit 090ad6f

File tree

2 files changed

+30
-50
lines changed

2 files changed

+30
-50
lines changed

src/librustc_trans/trans/debuginfo/metadata.rs

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
2626
use metadata::csearch;
2727
use middle::pat_util;
2828
use middle::subst::{self, Substs};
29-
use middle::infer;
3029
use rustc::ast_map;
3130
use trans::{type_of, adt, machine, monomorphize};
3231
use trans::common::{self, CrateContext, FunctionContext, Block};
@@ -287,12 +286,18 @@ impl<'tcx> TypeMap<'tcx> {
287286
}
288287
}
289288
},
290-
ty::TyClosure(def_id, ref substs) => {
291-
let infcx = infer::normalizing_infer_ctxt(cx.tcx(), &cx.tcx().tables);
292-
let closure_ty = infcx.closure_type(def_id, substs);
293-
self.get_unique_type_id_of_closure_type(cx,
294-
closure_ty,
295-
&mut unique_type_id);
289+
ty::TyClosure(_, ref substs) if substs.upvar_tys.is_empty() => {
290+
push_debuginfo_type_name(cx, type_, false, &mut unique_type_id);
291+
},
292+
ty::TyClosure(_, ref substs) => {
293+
unique_type_id.push_str("closure ");
294+
for upvar_type in &substs.upvar_tys {
295+
let upvar_type_id =
296+
self.get_unique_type_id_of_type(cx, upvar_type);
297+
let upvar_type_id =
298+
self.get_unique_type_id_as_string(upvar_type_id);
299+
unique_type_id.push_str(&upvar_type_id[..]);
300+
}
296301
},
297302
_ => {
298303
cx.sess().bug(&format!("get_unique_type_id_of_type() - unexpected type: {:?}",
@@ -361,49 +366,6 @@ impl<'tcx> TypeMap<'tcx> {
361366
}
362367
}
363368

364-
fn get_unique_type_id_of_closure_type<'a>(&mut self,
365-
cx: &CrateContext<'a, 'tcx>,
366-
closure_ty: ty::ClosureTy<'tcx>,
367-
unique_type_id: &mut String) {
368-
let ty::ClosureTy { unsafety,
369-
ref sig,
370-
abi: _ } = closure_ty;
371-
372-
if unsafety == ast::Unsafety::Unsafe {
373-
unique_type_id.push_str("unsafe ");
374-
}
375-
376-
unique_type_id.push_str("|");
377-
378-
let sig = cx.tcx().erase_late_bound_regions(sig);
379-
380-
for &parameter_type in &sig.inputs {
381-
let parameter_type_id =
382-
self.get_unique_type_id_of_type(cx, parameter_type);
383-
let parameter_type_id =
384-
self.get_unique_type_id_as_string(parameter_type_id);
385-
unique_type_id.push_str(&parameter_type_id[..]);
386-
unique_type_id.push(',');
387-
}
388-
389-
if sig.variadic {
390-
unique_type_id.push_str("...");
391-
}
392-
393-
unique_type_id.push_str("|->");
394-
395-
match sig.output {
396-
ty::FnConverging(ret_ty) => {
397-
let return_type_id = self.get_unique_type_id_of_type(cx, ret_ty);
398-
let return_type_id = self.get_unique_type_id_as_string(return_type_id);
399-
unique_type_id.push_str(&return_type_id[..]);
400-
}
401-
ty::FnDiverging => {
402-
unique_type_id.push_str("!");
403-
}
404-
}
405-
}
406-
407369
// Get the UniqueTypeId for an enum variant. Enum variants are not really
408370
// types of their own, so they need special handling. We still need a
409371
// UniqueTypeId for them, since to debuginfo they *are* real types.

src/test/debuginfo/basic-types-metadata.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@
4646
// gdb-check:type = [...] (*)([...])
4747
// gdb-command:info functions _yyy
4848
// gdb-check:[...]![...]_yyy([...]);
49+
// gdb-command:ptype closure_0
50+
// gdb-check: type = struct closure {
51+
// gdb-check: <no data fields>
52+
// gdb-check: }
53+
// gdb-command:ptype closure_1
54+
// gdb-check: type = struct closure {
55+
// gdb-check: bool *__0;
56+
// gdb-check: }
57+
// gdb-command:ptype closure_2
58+
// gdb-check: type = struct closure {
59+
// gdb-check: bool *__0;
60+
// gdb-check: isize *__1;
61+
// gdb-check: }
62+
63+
//
4964
// gdb-command:continue
5065

5166
#![allow(unused_variables)]
@@ -68,6 +83,9 @@ fn main() {
6883
let f32: f32 = 2.5;
6984
let f64: f64 = 3.5;
7085
let fnptr : fn() = _zzz;
86+
let closure_0 = || {};
87+
let closure_1 = || { b; };
88+
let closure_2 = || { if b { i } else { i }; };
7189
_zzz(); // #break
7290
if 1 == 1 { _yyy(); }
7391
}

0 commit comments

Comments
 (0)