Skip to content

Commit e945b28

Browse files
committed
trans: pass essential information from trans_closure to debuginfo.
1 parent 35a6e6a commit e945b28

File tree

4 files changed

+124
-262
lines changed

4 files changed

+124
-262
lines changed

src/librustc_trans/base.rs

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,15 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14001400
pub fn new(ccx: &'blk CrateContext<'blk, 'tcx>,
14011401
llfndecl: ValueRef,
14021402
fn_ty: FnType,
1403-
instance: Option<Instance<'tcx>>,
1403+
definition: Option<(Instance<'tcx>,
1404+
&ty::FnSig<'tcx>,
1405+
Abi,
1406+
&ty::Generics<'tcx>,
1407+
Option<ast::Name>)>,
14041408
block_arena: &'blk TypedArena<common::BlockS<'blk, 'tcx>>)
14051409
-> FunctionContext<'blk, 'tcx> {
1406-
let (param_substs, def_id) = match instance {
1407-
Some(instance) => {
1410+
let (param_substs, def_id) = match definition {
1411+
Some((instance, _, _, _, _)) => {
14081412
common::validate_substs(instance.substs);
14091413
(instance.substs, Some(instance.def))
14101414
}
@@ -1416,10 +1420,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14161420
let local_id = def_id.and_then(|id| ccx.tcx().map.as_local_node_id(id));
14171421

14181422
debug!("FunctionContext::new({})",
1419-
instance.map_or(String::new(), |i| i.to_string()));
1420-
1421-
let debug_context = debuginfo::create_function_debug_context(ccx,
1422-
inlined_id.unwrap_or(ast::DUMMY_NODE_ID), param_substs, llfndecl);
1423+
definition.map_or(String::new(), |d| d.0.to_string()));
14231424

14241425
let cfg = inlined_id.map(|id| build_cfg(ccx.tcx(), id));
14251426
let nested_returns = if let Some((blk_id, Some(ref cfg))) = cfg {
@@ -1431,10 +1432,11 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14311432
let check_attrs = |attrs: &[ast::Attribute]| {
14321433
let default_to_mir = ccx.sess().opts.debugging_opts.orbit;
14331434
let invert = if default_to_mir { "rustc_no_mir" } else { "rustc_mir" };
1434-
default_to_mir ^ attrs.iter().any(|item| item.check_name(invert))
1435+
(default_to_mir ^ attrs.iter().any(|item| item.check_name(invert)),
1436+
attrs.iter().any(|item| item.check_name("no_debug")))
14351437
};
14361438

1437-
let use_mir = if let Some(id) = local_id {
1439+
let (use_mir, no_debug) = if let Some(id) = local_id {
14381440
check_attrs(ccx.tcx().map.attrs(id))
14391441
} else if let Some(def_id) = def_id {
14401442
check_attrs(&ccx.sess().cstore.item_attrs(def_id))
@@ -1448,6 +1450,18 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14481450
None
14491451
};
14501452

1453+
let span = inlined_id.and_then(|id| ccx.tcx().map.opt_span(id));
1454+
1455+
let debug_context = if let (false, Some(definition)) = (no_debug, definition) {
1456+
let (instance, sig, abi, generics, name) = definition;
1457+
debuginfo::create_function_debug_context(ccx, instance, sig,
1458+
abi, generics, name,
1459+
span.unwrap_or(DUMMY_SP),
1460+
llfndecl)
1461+
} else {
1462+
debuginfo::empty_function_debug_context(ccx)
1463+
};
1464+
14511465
FunctionContext {
14521466
needs_ret_allocas: nested_returns && mir.is_none(),
14531467
mir: mir,
@@ -1462,7 +1476,7 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
14621476
lldropflag_hints: RefCell::new(DropFlagHintsMap::new()),
14631477
fn_ty: fn_ty,
14641478
param_substs: param_substs,
1465-
span: inlined_id.and_then(|id| ccx.tcx().map.opt_span(id)),
1479+
span: span,
14661480
block_arena: block_arena,
14671481
lpad_arena: TypedArena::new(),
14681482
ccx: ccx,
@@ -1815,8 +1829,10 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18151829
llfndecl: ValueRef,
18161830
instance: Instance<'tcx>,
18171831
inlined_id: ast::NodeId,
1818-
fn_ty: FnType,
1832+
sig: &ty::FnSig<'tcx>,
18191833
abi: Abi,
1834+
generics: &ty::Generics<'tcx>,
1835+
name: Option<ast::Name>,
18201836
closure_env: closure::ClosureEnv) {
18211837
ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);
18221838

@@ -1829,14 +1845,19 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18291845

18301846
debug!("trans_closure(..., {})", instance);
18311847

1848+
let fn_ty = FnType::new(ccx, abi, sig, &[]);
1849+
18321850
let (arena, fcx): (TypedArena<_>, FunctionContext);
18331851
arena = TypedArena::new();
1834-
fcx = FunctionContext::new(ccx, llfndecl, fn_ty, Some(instance), &arena);
1852+
fcx = FunctionContext::new(ccx, llfndecl, fn_ty,
1853+
Some((instance, sig, abi, generics, name)), &arena);
18351854

18361855
if fcx.mir.is_some() {
18371856
return mir::trans_mir(&fcx);
18381857
}
18391858

1859+
debuginfo::fill_scope_map_for_function(&fcx, decl, body, inlined_id);
1860+
18401861
// cleanup scope for the incoming arguments
18411862
let fn_cleanup_debug_loc = debuginfo::get_cleanup_debug_loc_for_ast_node(
18421863
ccx, inlined_id, body.span, true);
@@ -1891,10 +1912,8 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18911912
}
18921913
}
18931914

1894-
let ret_debug_loc = DebugLoc::At(fn_cleanup_debug_loc.id, fn_cleanup_debug_loc.span);
1895-
18961915
// Insert the mandatory first few basic blocks before lltop.
1897-
fcx.finish(bcx, ret_debug_loc);
1916+
fcx.finish(bcx, fn_cleanup_debug_loc.debug_loc());
18981917
}
18991918

19001919
/// Creates an LLVM function corresponding to a source language function.
@@ -1907,25 +1926,27 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
19071926
let _s = StatRecorder::new(ccx, ccx.tcx().node_path_str(id));
19081927
debug!("trans_fn(param_substs={:?})", param_substs);
19091928
let _icx = push_ctxt("trans_fn");
1910-
let fn_ty = ccx.tcx().node_id_to_type(id);
1911-
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &fn_ty);
1912-
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
1913-
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
1914-
let abi = fn_ty.fn_abi();
1915-
let fn_ty = FnType::new(ccx, abi, &sig, &[]);
19161929
let def_id = if let Some(&def_id) = ccx.external_srcs().borrow().get(&id) {
19171930
def_id
19181931
} else {
19191932
ccx.tcx().map.local_def_id(id)
19201933
};
1934+
let scheme = ccx.tcx().lookup_item_type(def_id);
1935+
let fn_ty = scheme.ty;
1936+
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), param_substs, &fn_ty);
1937+
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
1938+
let sig = infer::normalize_associated_type(ccx.tcx(), &sig);
1939+
let abi = fn_ty.fn_abi();
19211940
trans_closure(ccx,
19221941
decl,
19231942
body,
19241943
llfndecl,
19251944
Instance::new(def_id, param_substs),
19261945
id,
1927-
fn_ty,
1946+
&sig,
19281947
abi,
1948+
&scheme.generics,
1949+
Some(ccx.tcx().item_name(def_id)),
19291950
closure::ClosureEnv::NotClosure);
19301951
}
19311952

src/librustc_trans/closure.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,21 @@ pub fn trans_closure_expr<'a, 'tcx>(dest: Dest<'a, 'tcx>,
234234
output: sig.output,
235235
variadic: false
236236
};
237-
let fn_ty = FnType::new(ccx, Abi::RustCall, &sig, &[]);
237+
238+
// This is not quite right. It should actually inherit
239+
// the generics of the enclosing function.
240+
let generics = ty::Generics::empty();
238241

239242
trans_closure(ccx,
240243
decl,
241244
body,
242245
llfn,
243246
Instance::new(closure_def_id, param_substs),
244247
id,
245-
fn_ty,
248+
&sig,
246249
Abi::RustCall,
250+
&generics,
251+
None,
247252
ClosureEnv::Closure(closure_def_id, id));
248253

249254
// Don't hoist this to the top of the function. It's perfectly legitimate

0 commit comments

Comments
 (0)