Skip to content

Commit 55c938b

Browse files
committed
Only build debuginfo blocks for blocks that appear in the program text
I.e. a set of curly braces, not everything that creates a block context in the trans pass. Issue #1694
1 parent 0ec92a4 commit 55c938b

File tree

6 files changed

+104
-81
lines changed

6 files changed

+104
-81
lines changed

src/comp/middle/debuginfo.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import trans::common::*;
77
import trans::base;
88
import trans::build::B;
99
import middle::ty;
10-
import syntax::{ast, codemap};
10+
import syntax::{ast, codemap, ast_util};
1111
import codemap::span;
1212
import ast::ty;
1313
import pat_util::*;
@@ -224,8 +224,17 @@ fn line_from_span(cm: codemap::codemap, sp: span) -> uint {
224224
codemap::lookup_char_pos(cm, sp.lo).line
225225
}
226226

227-
fn create_block(cx: @block_ctxt, sp: span) -> @metadata<block_md> {
228-
//let cache = get_cache(bcx_ccx(cx));
227+
fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
228+
let cache = get_cache(bcx_ccx(cx));
229+
let cx = cx;
230+
while option::is_none(cx.block_span) {
231+
alt cx.parent {
232+
parent_none { fail "BAD"; /*break;*/ }
233+
parent_some(b) { cx = b; }
234+
}
235+
}
236+
let sp = option::get(cx.block_span);
237+
229238
let start = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
230239
sp.lo);
231240
let fname = start.filename;
@@ -240,25 +249,25 @@ fn create_block(cx: @block_ctxt, sp: span) -> @metadata<block_md> {
240249
}*/
241250

242251
let parent = alt cx.parent {
243-
parent_none { create_function(cx.fcx, sp).node }
244-
parent_some(bcx) { create_block(bcx, sp).node }
252+
parent_none { create_function(cx.fcx).node }
253+
parent_some(bcx) { create_block(bcx).node }
245254
};
246255
let file_node = create_file(bcx_ccx(cx), fname);
247-
/*let unique_id = alt cache.find(LexicalBlockTag) {
256+
let unique_id = alt cache.find(LexicalBlockTag) {
248257
option::some(v) { vec::len(v) as int }
249258
option::none { 0 }
250-
};*/
259+
};
251260
let lldata = [lltag(tg),
252261
parent,
253262
lli32(start.line as int),
254263
lli32(start.col as int),
255-
file_node.node/*,
256-
lli32(unique_id)*/
264+
file_node.node,
265+
lli32(unique_id)
257266
];
258-
let val = llmdnode(lldata);
259-
let mdval = @{node: val, data: {start: start, end: end}};
260-
//update_cache(cache, tg, block_metadata(mdval));
261-
ret mdval;
267+
let val = llmdnode(lldata);
268+
let mdval = @{node: val, data: {start: start, end: end}};
269+
//update_cache(cache, tg, block_metadata(mdval));
270+
ret mdval;
262271
}
263272

264273
fn size_and_align_of<T>() -> (int, int) {
@@ -642,8 +651,8 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
642651
let tymd = create_ty(cx, ty, local.node.ty);
643652
let filemd = create_file(cx, loc.filename);
644653
let context = alt bcx.parent {
645-
parent_none { create_function(bcx.fcx, local.span).node }
646-
parent_some(_) { create_block(bcx, local.span).node }
654+
parent_none { create_function(bcx.fcx).node }
655+
parent_some(_) { create_block(bcx).node }
647656
};
648657
let mdnode = create_var(tg, context, name, filemd.node,
649658
loc.line as int, tymd.node);
@@ -684,7 +693,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
684693
let ty = base::node_id_type(cx, arg.id);
685694
let tymd = create_ty(cx, ty, arg.ty);
686695
let filemd = create_file(cx, loc.filename);
687-
let context = create_function(bcx.fcx, sp);
696+
let context = create_function(bcx.fcx);
688697
let mdnode = create_var(tg, context.node, arg.ident, filemd.node,
689698
loc.line as int, tymd.node);
690699
let mdval = @{node: mdnode, data: {id: arg.id}};
@@ -704,7 +713,7 @@ fn update_source_pos(cx: @block_ctxt, s: span) {
704713
ret;
705714
}
706715
let cm = bcx_ccx(cx).sess.codemap;
707-
let blockmd = create_block(cx, s);
716+
let blockmd = create_block(cx);
708717
let loc = codemap::lookup_char_pos(cm, s.lo);
709718
let scopedata = [lli32(loc.line as int),
710719
lli32(loc.col as int),
@@ -714,14 +723,15 @@ fn update_source_pos(cx: @block_ctxt, s: span) {
714723
llvm::LLVMSetCurrentDebugLocation(trans::build::B(cx), dbgscope);
715724
}
716725

717-
fn create_function(fcx: @fn_ctxt, sp: span) -> @metadata<subprogram_md> {
726+
fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
718727
let cx = fcx_ccx(fcx);
719728
let dbg_cx = option::get(cx.dbg_cx);
720729

721730
#debug("~~");
722731
log(debug, fcx.id);
723732

724-
//log(debug, codemap::span_to_str(sp, cx.sess.codemap));
733+
let sp = option::get(fcx.span);
734+
log(debug, codemap::span_to_str(sp, cx.sess.codemap));
725735

726736
let (ident, ret_ty, id) = alt cx.ast_map.get(fcx.id) {
727737
ast_map::node_item(item) {
@@ -754,12 +764,12 @@ fn create_function(fcx: @fn_ctxt, sp: span) -> @metadata<subprogram_md> {
754764
log(debug, ident);
755765
log(debug, id);
756766

757-
/*let cache = get_cache(cx);
767+
let cache = get_cache(cx);
758768
alt cached_metadata::<@metadata<subprogram_md>>(
759769
cache, SubprogramTag, {|md| md.data.id == id}) {
760770
option::some(md) { ret md; }
761771
option::none {}
762-
}*/
772+
}
763773

764774
let path = str::connect(fcx.lcx.path + [ident], "::");
765775

@@ -805,6 +815,6 @@ fn create_function(fcx: @fn_ctxt, sp: span) -> @metadata<subprogram_md> {
805815
let val = llmdnode(fn_metadata);
806816
add_named_metadata(cx, "llvm.dbg.sp", val);
807817
let mdval = @{node: val, data: {id: id}};
808-
//update_cache(cache, SubprogramTag, subprogram_metadata(mdval));
818+
update_cache(cache, SubprogramTag, subprogram_metadata(mdval));
809819
ret mdval;
810820
}

src/comp/middle/trans/alt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import lib::llvm::llvm;
66
import lib::llvm::llvm::{ValueRef, BasicBlockRef};
77
import pat_util::*;
88
import build::*;
9-
import base::{new_sub_block_ctxt, new_scope_block_ctxt, load_if_immediate};
9+
import base::{new_sub_block_ctxt, new_scope_block_ctxt,
10+
new_real_block_ctxt, load_if_immediate};
1011
import syntax::ast;
1112
import syntax::ast_util;
1213
import syntax::ast_util::{dummy_sp};
@@ -651,7 +652,8 @@ fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms_: [ast::arm],
651652
let arms = normalize_arms(bcx_tcx(cx), arms_);
652653

653654
for a: ast::arm in arms {
654-
let body = new_scope_block_ctxt(er.bcx, "case_body");
655+
let body = new_real_block_ctxt(er.bcx, "case_body",
656+
a.body.span);
655657
let id_map = pat_util::pat_id_map(bcx_tcx(cx), a.pats[0]);
656658
bodies += [body];
657659
for p: @ast::pat in a.pats {

0 commit comments

Comments
 (0)