Skip to content

Commit b3f06c7

Browse files
committedJan 27, 2012
Stop passing spans to middle::trans functions that don't need them
Removes a bunch of (eventually) unused arguments. Makes span passing to debuginfo explicit, instead of relying on the (usually incorrect) spans held in the contexts. Closes #1439
1 parent ad5e609 commit b3f06c7

9 files changed

+164
-224
lines changed
 

‎src/comp/middle/debuginfo.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import middle::trans_common::*;
77
import middle::trans_build::B;
88
import middle::ty;
99
import syntax::{ast, codemap};
10+
import codemap::span;
1011
import ast::ty;
1112
import pat_util::*;
1213
import util::ppaux::ty_to_str;
@@ -218,17 +219,17 @@ fn create_file(cx: @crate_ctxt, full_path: str) -> @metadata<file_md> {
218219
ret mdval;
219220
}
220221

221-
fn line_from_span(cm: codemap::codemap, sp: codemap::span) -> uint {
222+
fn line_from_span(cm: codemap::codemap, sp: span) -> uint {
222223
codemap::lookup_char_pos(cm, sp.lo).line
223224
}
224225

225-
fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
226+
fn create_block(cx: @block_ctxt, sp: span) -> @metadata<block_md> {
226227
let cache = get_cache(bcx_ccx(cx));
227228
let start = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
228-
cx.sp.lo);
229+
sp.lo);
229230
let fname = start.filename;
230231
let end = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
231-
cx.sp.hi);
232+
sp.hi);
232233
let tg = LexicalBlockTag;
233234
alt cached_metadata::<@metadata<block_md>>(
234235
cache, tg,
@@ -238,8 +239,8 @@ fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
238239
}
239240

240241
let parent = alt cx.parent {
241-
trans_common::parent_none { create_function(cx.fcx).node }
242-
trans_common::parent_some(bcx) { create_block(cx).node }
242+
trans_common::parent_none { create_function(cx.fcx, sp).node }
243+
trans_common::parent_some(bcx) { create_block(cx, sp).node }
243244
};
244245
let file_node = create_file(bcx_ccx(cx), fname);
245246
let unique_id = alt cache.find(LexicalBlockTag) {
@@ -317,7 +318,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
317318
ret mdval;
318319
}
319320

320-
fn create_pointer_type(cx: @crate_ctxt, t: ty::t, span: codemap::span,
321+
fn create_pointer_type(cx: @crate_ctxt, t: ty::t, span: span,
321322
pointee: @metadata<tydesc_md>)
322323
-> @metadata<tydesc_md> {
323324
let tg = PointerTypeTag;
@@ -391,7 +392,7 @@ fn add_member(cx: @struct_ctxt, name: str, line: int, size: int, align: int,
391392
}
392393

393394
fn create_record(cx: @crate_ctxt, t: ty::t, fields: [ast::ty_field],
394-
span: codemap::span) -> @metadata<tydesc_md> {
395+
span: span) -> @metadata<tydesc_md> {
395396
let fname = filename_from_span(cx, span);
396397
let file_node = create_file(cx, fname);
397398
let scx = create_structure(file_node,
@@ -411,7 +412,7 @@ fn create_record(cx: @crate_ctxt, t: ty::t, fields: [ast::ty_field],
411412
}
412413

413414
fn create_boxed_type(cx: @crate_ctxt, outer: ty::t, _inner: ty::t,
414-
span: codemap::span, boxed: @metadata<tydesc_md>)
415+
span: span, boxed: @metadata<tydesc_md>)
415416
-> @metadata<tydesc_md> {
416417
//let tg = StructureTypeTag;
417418
/*let cache = cx.llmetadata;
@@ -537,7 +538,7 @@ fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
537538
option::none {}
538539
}*/
539540

540-
fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: codemap::span) -> @ast::ty {
541+
fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: span) -> @ast::ty {
541542
let ty = alt ty::struct(ccx_tcx(cx), t) {
542543
ty::ty_nil { ast::ty_nil }
543544
ty::ty_bot { ast::ty_bot }
@@ -602,7 +603,7 @@ fn create_ty(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
602603
};
603604
}
604605

605-
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
606+
fn filename_from_span(cx: @crate_ctxt, sp: span) -> str {
606607
codemap::lookup_char_pos(cx.sess.codemap, sp.lo).filename
607608
}
608609

@@ -633,15 +634,15 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
633634
let name = path_to_ident(alt pat_util::normalize_pat(bcx_tcx(bcx),
634635
local.node.pat).node {
635636
ast::pat_ident(ident, _) { ident /*XXX deal w/ optional node binding*/ }
636-
});
637+
});
637638
let loc = codemap::lookup_char_pos(cx.sess.codemap,
638639
local.span.lo);
639640
let ty = trans::node_id_type(cx, local.node.id);
640641
let tymd = create_ty(cx, ty, local.node.ty);
641642
let filemd = create_file(cx, loc.filename);
642643
let context = alt bcx.parent {
643-
trans_common::parent_none { create_function(bcx.fcx).node }
644-
trans_common::parent_some(_) { create_block(bcx).node }
644+
trans_common::parent_none { create_function(bcx.fcx, local.span).node }
645+
trans_common::parent_some(_) { create_block(bcx, local.span).node }
645646
};
646647
let mdnode = create_var(tg, context, name, filemd.node,
647648
loc.line as int, tymd.node);
@@ -662,7 +663,7 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
662663
ret mdval;
663664
}
664665

665-
fn create_arg(bcx: @block_ctxt, arg: ast::arg)
666+
fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
666667
-> @metadata<argument_md> unsafe {
667668
let fcx = bcx_fcx(bcx);
668669
let cx = fcx_ccx(fcx);
@@ -678,11 +679,11 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
678679
ast_map::node_arg(_, n) { n - 2u }
679680
};*/
680681
let loc = codemap::lookup_char_pos(cx.sess.codemap,
681-
fcx.sp.lo);
682+
sp.lo);
682683
let ty = trans::node_id_type(cx, arg.id);
683684
let tymd = create_ty(cx, ty, arg.ty);
684685
let filemd = create_file(cx, loc.filename);
685-
let context = create_function(bcx.fcx);
686+
let context = create_function(bcx.fcx, sp);
686687
let mdnode = create_var(tg, context.node, arg.ident, filemd.node,
687688
loc.line as int, tymd.node);
688689
let mdval = @{node: mdnode, data: {id: arg.id}};
@@ -697,12 +698,12 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg)
697698
ret mdval;
698699
}
699700

700-
fn update_source_pos(cx: @block_ctxt, s: codemap::span) {
701+
fn update_source_pos(cx: @block_ctxt, s: span) {
701702
if !bcx_ccx(cx).sess.opts.debuginfo {
702703
ret;
703704
}
704705
let cm = bcx_ccx(cx).sess.codemap;
705-
let blockmd = create_block(cx);
706+
let blockmd = create_block(cx, s);
706707
let loc = codemap::lookup_char_pos(cm, s.lo);
707708
let scopedata = [lli32(loc.line as int),
708709
lli32(loc.col as int),
@@ -712,14 +713,14 @@ fn update_source_pos(cx: @block_ctxt, s: codemap::span) {
712713
llvm::LLVMSetCurrentDebugLocation(trans_build::B(cx), dbgscope);
713714
}
714715

715-
fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
716+
fn create_function(fcx: @fn_ctxt, sp: span) -> @metadata<subprogram_md> {
716717
let cx = fcx_ccx(fcx);
717718
let dbg_cx = option::get(cx.dbg_cx);
718719

719720
#debug("~~");
720721
log(debug, fcx.id);
721722

722-
log(debug, codemap::span_to_str(fcx.sp, cx.sess.codemap));
723+
log(debug, codemap::span_to_str(sp, cx.sess.codemap));
723724

724725
let (ident, ret_ty, id) = alt cx.ast_map.get(fcx.id) {
725726
ast_map::node_item(item) {
@@ -763,7 +764,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
763764
}
764765

765766
let loc = codemap::lookup_char_pos(cx.sess.codemap,
766-
fcx.sp.lo);
767+
sp.lo);
767768
let file_node = create_file(cx, loc.filename).node;
768769
let key = cx.item_symbols.contains_key(fcx.id) ? fcx.id : id;
769770
let mangled = cx.item_symbols.get(key);

‎src/comp/middle/shape.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
135135
// (Could add a postcondition to type_contains_params,
136136
// once we implement Issue #586.)
137137
check (trans_common::type_has_static_size(ccx, elem_t));
138-
let llty = trans::type_of(ccx, dummy_sp(), elem_t);
138+
let llty = trans::type_of(ccx, elem_t);
139139
min_size += llsize_of_real(ccx, llty);
140140
min_align += llalign_of_real(ccx, llty);
141141
}
@@ -214,7 +214,7 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
214214
// on enum_variants that would obviate the need for
215215
// this check. (Issue #586)
216216
check (trans_common::type_has_static_size(ccx, typ));
217-
lltys += [trans::type_of(ccx, dummy_sp(), typ)];
217+
lltys += [trans::type_of(ccx, typ)];
218218
}
219219

220220
let llty = trans_common::T_struct(lltys);
@@ -584,7 +584,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
584584
let len = interner::len(ccx.shape_cx.resources);
585585
while i < len {
586586
let ri = interner::get(ccx.shape_cx.resources, i);
587-
dtors += [trans_common::get_res_dtor(ccx, dummy_sp(), ri.did, ri.t)];
587+
dtors += [trans_common::get_res_dtor(ccx, ri.did, ri.t)];
588588
i += 1u;
589589
}
590590

@@ -627,7 +627,7 @@ type tag_metrics = {
627627
fn size_of(bcx: @block_ctxt, t: ty::t) -> result {
628628
let ccx = bcx_ccx(bcx);
629629
if check type_has_static_size(ccx, t) {
630-
rslt(bcx, llsize_of(ccx, trans::type_of(ccx, bcx.sp, t)))
630+
rslt(bcx, llsize_of(ccx, trans::type_of(ccx, t)))
631631
} else {
632632
let { bcx, sz, align: _ } = dynamic_metrics(bcx, t);
633633
rslt(bcx, sz)
@@ -637,7 +637,7 @@ fn size_of(bcx: @block_ctxt, t: ty::t) -> result {
637637
fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
638638
let ccx = bcx_ccx(bcx);
639639
if check type_has_static_size(ccx, t) {
640-
rslt(bcx, llalign_of(ccx, trans::type_of(ccx, bcx.sp, t)))
640+
rslt(bcx, llalign_of(ccx, trans::type_of(ccx, t)))
641641
} else {
642642
let { bcx, sz: _, align } = dynamic_metrics(bcx, t);
643643
rslt(bcx, align)
@@ -647,7 +647,7 @@ fn align_of(bcx: @block_ctxt, t: ty::t) -> result {
647647
fn metrics(bcx: @block_ctxt, t: ty::t) -> metrics {
648648
let ccx = bcx_ccx(bcx);
649649
if check type_has_static_size(ccx, t) {
650-
let llty = trans::type_of(ccx, bcx.sp, t);
650+
let llty = trans::type_of(ccx, t);
651651
{ bcx: bcx, sz: llsize_of(ccx, llty), align: llalign_of(ccx, llty) }
652652
} else {
653653
dynamic_metrics(bcx, t)
@@ -675,7 +675,7 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
675675
}
676676

677677
// Computes the size of the data part of a non-dynamically-sized enum.
678-
fn static_size_of_enum(cx: @crate_ctxt, sp: span, t: ty::t)
678+
fn static_size_of_enum(cx: @crate_ctxt, t: ty::t)
679679
: type_has_static_size(cx, t) -> uint {
680680
if cx.enum_sizes.contains_key(t) { ret cx.enum_sizes.get(t); }
681681
alt ty::struct(cx.tcx, t) {
@@ -696,16 +696,12 @@ fn static_size_of_enum(cx: @crate_ctxt, sp: span, t: ty::t)
696696
// express that with constrained types.
697697
check (type_has_static_size(cx, tup_ty));
698698
let this_size =
699-
llsize_of_real(cx, trans::type_of(cx, sp, tup_ty));
699+
llsize_of_real(cx, trans::type_of(cx, tup_ty));
700700
if max_size < this_size { max_size = this_size; }
701701
}
702702
cx.enum_sizes.insert(t, max_size);
703703
ret max_size;
704704
}
705-
_ {
706-
cx.tcx.sess.span_fatal(
707-
sp, "non-enum passed to static_size_of_enum()");
708-
}
709705
}
710706
}
711707

0 commit comments

Comments
 (0)
Please sign in to comment.