Skip to content

Commit 433fbe8

Browse files
committed
auto merge of #8329 : michaelwoerister/rust/lexical_scopes_alt, r=graydon
This pull request re-implements handling of visibility scopes and source code positions in debug info. It should now be very stable and properly handle + variable shadowing + expanded code (macros and the new for-loop de-sugaring, for example) + variables in the middle of nested scopes + bindings declared in the head of match statement arms. all of which did not work at all or did not work reliably before. Those interested in a more detailed description of the problems at hand, I kindly refer to http://michaelwoerister.github.io/2013/08/03/visibility-scopes.html Why doesn't the `populate_scope_map()` function use `syntax::visit`? Because it would not improve this particular AST walker (see: michaelwoerister@69dc790#commitcomment-3781426) Cheers, Michael
2 parents 9f37932 + 983cc77 commit 433fbe8

20 files changed

+2195
-156
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ use middle::trans::expr;
214214
use middle::trans::glue;
215215
use middle::trans::tvec;
216216
use middle::trans::type_of;
217+
use middle::trans::debuginfo;
217218
use middle::ty;
218219
use util::common::indenter;
219220
use util::ppaux::{Repr, vec_map_to_str};
@@ -385,6 +386,7 @@ struct BindingInfo {
385386
llmatch: ValueRef,
386387
trmode: TransBindingMode,
387388
id: ast::NodeId,
389+
span: span,
388390
ty: ty::t,
389391
}
390392

@@ -1305,7 +1307,7 @@ fn insert_lllocals(bcx: @mut Block,
13051307
BindArgument => bcx.fcx.llargs
13061308
};
13071309

1308-
for (_, &binding_info) in bindings_map.iter() {
1310+
for (&ident, &binding_info) in bindings_map.iter() {
13091311
let llval = match binding_info.trmode {
13101312
// By value bindings: use the stack slot that we
13111313
// copied/moved the value into
@@ -1325,6 +1327,14 @@ fn insert_lllocals(bcx: @mut Block,
13251327

13261328
debug!("binding %? to %s", binding_info.id, bcx.val_to_str(llval));
13271329
llmap.insert(binding_info.id, llval);
1330+
1331+
if bcx.sess().opts.extra_debuginfo {
1332+
debuginfo::create_match_binding_metadata(bcx,
1333+
ident,
1334+
binding_info.id,
1335+
binding_info.ty,
1336+
binding_info.span);
1337+
}
13281338
}
13291339
return bcx;
13301340
}
@@ -1771,7 +1781,7 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::pat) -> BindingsMap {
17711781
let ccx = bcx.ccx();
17721782
let tcx = bcx.tcx();
17731783
let mut bindings_map = HashMap::new();
1774-
do pat_bindings(tcx.def_map, pat) |bm, p_id, _s, path| {
1784+
do pat_bindings(tcx.def_map, pat) |bm, p_id, span, path| {
17751785
let ident = path_to_ident(path);
17761786
let variable_ty = node_id_type(bcx, p_id);
17771787
let llvariable_ty = type_of::type_of(ccx, variable_ty);
@@ -1793,8 +1803,11 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::pat) -> BindingsMap {
17931803
}
17941804
};
17951805
bindings_map.insert(ident, BindingInfo {
1796-
llmatch: llmatch, trmode: trmode,
1797-
id: p_id, ty: variable_ty
1806+
llmatch: llmatch,
1807+
trmode: trmode,
1808+
id: p_id,
1809+
span: span,
1810+
ty: variable_ty
17981811
});
17991812
}
18001813
return bindings_map;

src/librustc/middle/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::stmt) -> @mut Block {
11031103
}
11041104

11051105
let mut bcx = cx;
1106-
debuginfo::update_source_pos(cx, s.span);
11071106

11081107
match s.node {
11091108
ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => {
@@ -1634,7 +1633,8 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16341633
param_substs: param_substs,
16351634
span: sp,
16361635
path: path,
1637-
ccx: ccx
1636+
ccx: ccx,
1637+
debug_context: None,
16381638
};
16391639
fcx.llenv = unsafe {
16401640
llvm::LLVMGetParam(llfndecl, fcx.env_arg_pos() as c_uint)
@@ -1933,7 +1933,7 @@ pub fn trans_fn(ccx: @mut CrateContext,
19331933
attrs,
19341934
output_type,
19351935
|fcx| {
1936-
if ccx.sess.opts.extra_debuginfo
1936+
if ccx.sess.opts.debuginfo
19371937
&& fcx_has_nonzero_span(fcx) {
19381938
debuginfo::create_function_metadata(fcx);
19391939
}

src/librustc/middle/trans/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use middle::trans::build;
2323
use middle::trans::datum;
2424
use middle::trans::glue;
2525
use middle::trans::write_guard;
26+
use middle::trans::debuginfo;
2627
use middle::ty::substs;
2728
use middle::ty;
2829
use middle::typeck;
@@ -226,7 +227,10 @@ pub struct FunctionContext {
226227
path: path,
227228

228229
// This function's enclosing crate context.
229-
ccx: @mut CrateContext
230+
ccx: @mut CrateContext,
231+
232+
// Used and maintained by the debuginfo module.
233+
debug_context: Option<~debuginfo::FunctionDebugContext>
230234
}
231235

232236
impl FunctionContext {

src/librustc/middle/trans/controlflow.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use middle::trans::base::*;
1919
use middle::trans::build::*;
2020
use middle::trans::callee;
2121
use middle::trans::common::*;
22-
use middle::trans::debuginfo;
2322
use middle::trans::expr;
2423
use middle::trans::type_of::*;
2524
use middle::ty;
@@ -38,12 +37,10 @@ pub fn trans_block(bcx: @mut Block, b: &ast::Block, dest: expr::Dest) -> @mut Bl
3837
let _icx = push_ctxt("trans_block");
3938
let mut bcx = bcx;
4039
for s in b.stmts.iter() {
41-
debuginfo::update_source_pos(bcx, b.span);
4240
bcx = trans_stmt(bcx, *s);
4341
}
4442
match b.expr {
4543
Some(e) => {
46-
debuginfo::update_source_pos(bcx, e.span);
4744
bcx = expr::trans_into(bcx, e, dest);
4845
}
4946
None => {

0 commit comments

Comments
 (0)