Skip to content

Commit 619d7c3

Browse files
committed
Associate names with types introduced by items
Issue #828 This is not a full solution yet. To really get sane error messages, we'll also have to guess the name to apply to literals, which seems non-trivial.
1 parent 60acae4 commit 619d7c3

File tree

7 files changed

+128
-184
lines changed

7 files changed

+128
-184
lines changed

src/comp/metadata/decoder.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,12 @@ fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt,
107107
}
108108
let tp = ebml::get_doc(item, tag_items_data_item_type);
109109
let def_parser = bind parse_external_def_id(this_cnum, extres, _);
110-
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
111-
def_parser, tcx);
110+
let t = parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
111+
def_parser, tcx);
112+
if family_names_type(item_family(item)) {
113+
t = ty::mk_named(tcx, t, @item_name(item));
114+
}
115+
t
112116
}
113117

114118
fn item_ty_param_kinds(item: ebml::doc) -> [ast::kind] {
@@ -307,6 +311,10 @@ fn family_has_type_params(fam_ch: u8) -> bool {
307311
};
308312
}
309313

314+
fn family_names_type(fam_ch: u8) -> bool {
315+
alt fam_ch as char { 'y' | 't' { true } _ { false } }
316+
}
317+
310318
fn read_path(d: ebml::doc) -> {path: str, pos: uint} {
311319
let desc = ebml::doc_data(d);
312320
let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u);

src/comp/metadata/encoder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
314314
encode_family(ebml_w, 'y' as u8);
315315
encode_type_param_kinds(ebml_w, tps);
316316
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
317+
encode_name(ebml_w, item.ident);
317318
ebml::end_tag(ebml_w);
318319
}
319320
item_tag(variants, tps) {
@@ -322,6 +323,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
322323
encode_family(ebml_w, 't' as u8);
323324
encode_type_param_kinds(ebml_w, tps);
324325
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
326+
encode_name(ebml_w, item.ident);
325327
for v: variant in variants {
326328
encode_variant_id(ebml_w, local_def(v.node.id));
327329
}
@@ -336,6 +338,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
336338
encode_family(ebml_w, 'y' as u8);
337339
encode_type_param_kinds(ebml_w, tps);
338340
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
341+
encode_name(ebml_w, item.ident);
339342
encode_symbol(ecx, ebml_w, item.id);
340343
ebml::end_tag(ebml_w);
341344

@@ -356,6 +359,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
356359
encode_family(ebml_w, 'y' as u8);
357360
encode_type_param_kinds(ebml_w, tps);
358361
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
362+
encode_name(ebml_w, item.ident);
359363
ebml::end_tag(ebml_w);
360364

361365
index += [{val: ctor_id, pos: ebml_w.writer.tell()}];

src/comp/middle/resolve.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,6 @@ fn find_impls_in_item(i: @ast::item, &impls: [@_impl],
17121712
}
17131713
}
17141714

1715-
// FIXME[impl] we should probably cache this
17161715
fn find_impls_in_mod(e: env, m: def, &impls: [@_impl],
17171716
name: option::t<ident>) {
17181717
alt m {

src/comp/middle/trans.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,10 @@ fn get_derived_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool,
10371037

10381038
type get_tydesc_result = {kind: tydesc_kind, result: result};
10391039

1040-
fn get_tydesc(cx: @block_ctxt, orig_t: ty::t, escapes: bool,
1040+
fn get_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool,
10411041
storage: ty_param_storage, &static_ti: option::t<@tydesc_info>)
10421042
-> get_tydesc_result {
10431043

1044-
let t = ty::strip_cname(bcx_tcx(cx), orig_t);
1045-
10461044
// Is the supplied type a type param? If so, return the passed-in tydesc.
10471045
alt ty::type_param(bcx_tcx(cx), t) {
10481046
some(id) {
@@ -1051,8 +1049,8 @@ fn get_tydesc(cx: @block_ctxt, orig_t: ty::t, escapes: bool,
10511049
} else {
10521050
bcx_tcx(cx).sess.span_bug(cx.sp,
10531051
"Unbound typaram in get_tydesc: " +
1054-
"orig_t = " +
1055-
ty_to_str(bcx_tcx(cx), orig_t) +
1052+
"t = " +
1053+
ty_to_str(bcx_tcx(cx), t) +
10561054
" ty_param = " +
10571055
uint::str(id));
10581056
}
@@ -1071,11 +1069,8 @@ fn get_tydesc(cx: @block_ctxt, orig_t: ty::t, escapes: bool,
10711069
ret {kind: tk_static, result: rslt(cx, info.tydesc)};
10721070
}
10731071

1074-
fn get_static_tydesc(cx: @block_ctxt, orig_t: ty::t, ty_params: [uint],
1072+
fn get_static_tydesc(cx: @block_ctxt, t: ty::t, ty_params: [uint],
10751073
is_obj_body: bool) -> @tydesc_info {
1076-
let t = ty::strip_cname(bcx_tcx(cx), orig_t);
1077-
1078-
10791074
alt bcx_ccx(cx).tydescs.find(t) {
10801075
some(info) { ret info; }
10811076
none. {

0 commit comments

Comments
 (0)