Skip to content

Commit

Permalink
auto merge of #8329 : michaelwoerister/rust/lexical_scopes_alt, r=gra…
Browse files Browse the repository at this point in the history
…ydon

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
  • Loading branch information
bors committed Aug 13, 2013
2 parents 9f37932 + 983cc77 commit 433fbe8
Show file tree
Hide file tree
Showing 20 changed files with 2,195 additions and 156 deletions.
21 changes: 17 additions & 4 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ use middle::trans::expr;
use middle::trans::glue;
use middle::trans::tvec;
use middle::trans::type_of;
use middle::trans::debuginfo;
use middle::ty;
use util::common::indenter;
use util::ppaux::{Repr, vec_map_to_str};
Expand Down Expand Up @@ -385,6 +386,7 @@ struct BindingInfo {
llmatch: ValueRef,
trmode: TransBindingMode,
id: ast::NodeId,
span: span,
ty: ty::t,
}

Expand Down Expand Up @@ -1305,7 +1307,7 @@ fn insert_lllocals(bcx: @mut Block,
BindArgument => bcx.fcx.llargs
};

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

debug!("binding %? to %s", binding_info.id, bcx.val_to_str(llval));
llmap.insert(binding_info.id, llval);

if bcx.sess().opts.extra_debuginfo {
debuginfo::create_match_binding_metadata(bcx,
ident,
binding_info.id,
binding_info.ty,
binding_info.span);
}
}
return bcx;
}
Expand Down Expand Up @@ -1771,7 +1781,7 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::pat) -> BindingsMap {
let ccx = bcx.ccx();
let tcx = bcx.tcx();
let mut bindings_map = HashMap::new();
do pat_bindings(tcx.def_map, pat) |bm, p_id, _s, path| {
do pat_bindings(tcx.def_map, pat) |bm, p_id, span, path| {
let ident = path_to_ident(path);
let variable_ty = node_id_type(bcx, p_id);
let llvariable_ty = type_of::type_of(ccx, variable_ty);
Expand All @@ -1793,8 +1803,11 @@ fn create_bindings_map(bcx: @mut Block, pat: @ast::pat) -> BindingsMap {
}
};
bindings_map.insert(ident, BindingInfo {
llmatch: llmatch, trmode: trmode,
id: p_id, ty: variable_ty
llmatch: llmatch,
trmode: trmode,
id: p_id,
span: span,
ty: variable_ty
});
}
return bindings_map;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,6 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::stmt) -> @mut Block {
}

let mut bcx = cx;
debuginfo::update_source_pos(cx, s.span);

match s.node {
ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => {
Expand Down Expand Up @@ -1634,7 +1633,8 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
param_substs: param_substs,
span: sp,
path: path,
ccx: ccx
ccx: ccx,
debug_context: None,
};
fcx.llenv = unsafe {
llvm::LLVMGetParam(llfndecl, fcx.env_arg_pos() as c_uint)
Expand Down Expand Up @@ -1933,7 +1933,7 @@ pub fn trans_fn(ccx: @mut CrateContext,
attrs,
output_type,
|fcx| {
if ccx.sess.opts.extra_debuginfo
if ccx.sess.opts.debuginfo
&& fcx_has_nonzero_span(fcx) {
debuginfo::create_function_metadata(fcx);
}
Expand Down
6 changes: 5 additions & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use middle::trans::build;
use middle::trans::datum;
use middle::trans::glue;
use middle::trans::write_guard;
use middle::trans::debuginfo;
use middle::ty::substs;
use middle::ty;
use middle::typeck;
Expand Down Expand Up @@ -226,7 +227,10 @@ pub struct FunctionContext {
path: path,

// This function's enclosing crate context.
ccx: @mut CrateContext
ccx: @mut CrateContext,

// Used and maintained by the debuginfo module.
debug_context: Option<~debuginfo::FunctionDebugContext>
}

impl FunctionContext {
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use middle::trans::base::*;
use middle::trans::build::*;
use middle::trans::callee;
use middle::trans::common::*;
use middle::trans::debuginfo;
use middle::trans::expr;
use middle::trans::type_of::*;
use middle::ty;
Expand All @@ -38,12 +37,10 @@ pub fn trans_block(bcx: @mut Block, b: &ast::Block, dest: expr::Dest) -> @mut Bl
let _icx = push_ctxt("trans_block");
let mut bcx = bcx;
for s in b.stmts.iter() {
debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s);
}
match b.expr {
Some(e) => {
debuginfo::update_source_pos(bcx, e.span);
bcx = expr::trans_into(bcx, e, dest);
}
None => {
Expand Down
Loading

0 comments on commit 433fbe8

Please sign in to comment.