Skip to content

debuginfo: Proper handling of lexical scopes and variable shadowing. #8329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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