Skip to content

Commit 9e5cfe7

Browse files
committed
---
yaml --- r: 11866 b: refs/heads/master c: 2c8c50d h: refs/heads/master v: v3
1 parent 1cf364f commit 9e5cfe7

File tree

7 files changed

+71
-46
lines changed

7 files changed

+71
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 4650e8bcf404d4c27dbbd5446a56fb066ada30f9
2+
refs/heads/master: 2c8c50d6cb1d7cce0f597dd60daf2a5109b9c0de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/metadata/astencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fn visit_ids(item: ast::inlined_item, vfn: fn@(ast::node_id)) {
137137
vfn(i.id);
138138
alt i.node {
139139
ast::item_res(_, _, _, d_id, c_id) { vfn(d_id); vfn(c_id); }
140+
ast::item_enum(vs, _) { for v in vs { vfn(v.node.id); } }
140141
_ {}
141142
}
142143
},

trunk/src/rustc/metadata/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const tag_items_data_item_symbol: uint = 0x0du;
2828

2929
const tag_items_data_item_variant: uint = 0x0eu;
3030

31-
const tag_items_data_item_enum_id: uint = 0x0fu;
31+
const tag_items_data_parent_item: uint = 0x0fu;
3232

3333
const tag_index: uint = 0x11u;
3434

@@ -62,6 +62,8 @@ const tag_crate_dep: uint = 0x26u;
6262

6363
const tag_crate_hash: uint = 0x28u;
6464

65+
const tag_parent_item: uint = 0x29u;
66+
6567
const tag_mod_impl: uint = 0x30u;
6668

6769
const tag_item_method: uint = 0x31u;

trunk/src/rustc/metadata/csearch.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export get_type;
1919
export get_impl_iface;
2020
export get_impl_method;
2121
export get_item_path;
22-
export maybe_get_item_ast;
22+
export maybe_get_item_ast, found_ast, found, found_parent, not_found;
2323

2424
fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str {
2525
let cdata = cstore::get_crate_data(cstore, def.crate).data;
@@ -80,11 +80,17 @@ fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
8080
[ast_map::path_mod(cdata.name)] + path
8181
}
8282

83+
enum found_ast {
84+
found(ast::inlined_item),
85+
found_parent(ast::def_id, ast::inlined_item),
86+
not_found,
87+
}
88+
8389
// Finds the AST for this item in the crate metadata, if any. If the item was
8490
// not marked for inlining, then the AST will not be present and hence none
8591
// will be returned.
8692
fn maybe_get_item_ast(tcx: ty::ctxt, maps: maps, def: ast::def_id)
87-
-> option<ast::inlined_item> {
93+
-> found_ast {
8894
let cstore = tcx.sess.cstore;
8995
let cdata = cstore::get_crate_data(cstore, def.crate);
9096
decoder::maybe_get_item_ast(cdata, tcx, maps, def.node)

trunk/src/rustc/metadata/decoder.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ fn item_symbol(item: ebml::doc) -> str {
9696
ret str::from_bytes(ebml::doc_data(sym));
9797
}
9898

99-
fn variant_enum_id(d: ebml::doc) -> ast::def_id {
100-
let tagdoc = ebml::get_doc(d, tag_items_data_item_enum_id);
101-
ret parse_def_id(ebml::doc_data(tagdoc));
99+
fn item_parent_item(d: ebml::doc) -> option<ast::def_id> {
100+
let found = none;
101+
ebml::tagged_docs(d, tag_items_data_parent_item) {|did|
102+
found = some(parse_def_id(ebml::doc_data(did)));
103+
}
104+
found
102105
}
103106

104107
fn variant_disr_val(d: ebml::doc) -> option<int> {
@@ -230,7 +233,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
230233
'm' { ast::def_mod(did) }
231234
'n' { ast::def_native_mod(did) }
232235
'v' {
233-
let tid = variant_enum_id(item);
236+
let tid = option::get(item_parent_item(item));
234237
tid = {crate: cnum, node: tid.node};
235238
ast::def_variant(tid, did)
236239
}
@@ -278,10 +281,26 @@ fn get_item_path(cdata: cmd, id: ast::node_id) -> ast_map::path {
278281
}
279282

280283
fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt, maps: maps,
281-
id: ast::node_id) -> option<ast::inlined_item> {
284+
id: ast::node_id) -> csearch::found_ast {
282285
let item_doc = lookup_item(id, cdata.data);
283286
let path = vec::init(item_path(item_doc));
284-
astencode::decode_inlined_item(cdata, tcx, maps, path, item_doc)
287+
alt astencode::decode_inlined_item(cdata, tcx, maps, path, item_doc) {
288+
some(ii) { csearch::found(ii) }
289+
none {
290+
alt item_parent_item(item_doc) {
291+
some(did) {
292+
let did = translate_def_id(cdata, did);
293+
let parent_item = lookup_item(did.node, cdata.data);
294+
alt astencode::decode_inlined_item(cdata, tcx, maps, path,
295+
parent_item) {
296+
some(ii) { csearch::found_parent(did, ii) }
297+
none { csearch::not_found }
298+
}
299+
}
300+
none { csearch::not_found }
301+
}
302+
}
303+
}
285304
}
286305

287306
fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)

trunk/src/rustc/metadata/encoder.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
241241
ebml_w.end_tag();
242242
}
243243

244-
fn encode_enum_id(ebml_w: ebml::writer, id: def_id) {
245-
ebml_w.start_tag(tag_items_data_item_enum_id);
244+
fn encode_parent_item(ebml_w: ebml::writer, id: def_id) {
245+
ebml_w.start_tag(tag_items_data_parent_item);
246246
ebml_w.writer.write(str::bytes(def_to_str(id)));
247247
ebml_w.end_tag();
248248
}
@@ -260,7 +260,7 @@ fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
260260
encode_def_id(ebml_w, local_def(variant.node.id));
261261
encode_family(ebml_w, 'v');
262262
encode_name(ebml_w, variant.node.name);
263-
encode_enum_id(ebml_w, local_def(id));
263+
encode_parent_item(ebml_w, local_def(id));
264264
encode_type(ecx, ebml_w,
265265
node_id_to_type(ecx.ccx.tcx, variant.node.id));
266266
if vec::len(variant.node.args) > 0u && ty_params.len() == 0u {
@@ -397,6 +397,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
397397
for v: variant in variants {
398398
encode_variant_id(ebml_w, local_def(v.node.id));
399399
}
400+
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
400401
encode_path(ebml_w, path, ast_map::path_name(item.ident));
401402
ebml_w.end_tag();
402403
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
@@ -414,11 +415,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
414415
encode_type_param_bounds(ebml_w, ecx, tps);
415416
encode_type(ecx, ebml_w, ty::ty_fn_ret(fn_ty));
416417
encode_name(ebml_w, item.ident);
417-
if tps.len() == 0u {
418-
encode_symbol(ecx, ebml_w, item.id);
419-
} else {
420-
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
421-
}
418+
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
422419
encode_path(ebml_w, path, ast_map::path_name(item.ident));
423420
ebml_w.end_tag();
424421

@@ -428,9 +425,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
428425
encode_family(ebml_w, 'f');
429426
encode_type_param_bounds(ebml_w, ecx, tps);
430427
encode_type(ecx, ebml_w, fn_ty);
431-
if tps.len() == 0u {
432-
encode_symbol(ecx, ebml_w, ctor_id);
433-
}
428+
encode_parent_item(ebml_w, local_def(item.id));
434429
encode_path(ebml_w, path, ast_map::path_name(item.ident));
435430
ebml_w.end_tag();
436431
}

trunk/src/rustc/middle/trans/base.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -864,17 +864,8 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
864864
let did = if did.crate != ast::local_crate && substs.len() > 0u {
865865
maybe_instantiate_inline(ccx, did)
866866
} else { did };
867-
if did.crate == ast::local_crate {
868-
option::get(monomorphic_fn(ccx, did, substs, none))
869-
} else {
870-
assert substs.len() == 0u;
871-
let nil = ty::mk_nil(ccx.tcx);
872-
let arg = {mode: ast::expl(ast::by_ref),
873-
ty: ty::mk_mut_ptr(ccx.tcx, nil)};
874-
let f_t = type_of::type_of_fn(ccx, [arg], nil, 0u);
875-
get_extern_const(ccx.externs, ccx.llmod,
876-
csearch::get_symbol(ccx.sess.cstore, did), f_t)
877-
}
867+
assert did.crate == ast::local_crate;
868+
option::get(monomorphic_fn(ccx, did, substs, none))
878869
}
879870

880871
fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
@@ -2094,22 +2085,34 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
20942085
}
20952086
some(none) { fn_id } // Not inlinable
20962087
none { // Not seen yet
2097-
alt csearch::maybe_get_item_ast(ccx.tcx, ccx.maps, fn_id) {
2098-
none { ccx.external.insert(fn_id, none); fn_id }
2099-
some(ast::ii_item(item)) {
2100-
#debug["maybe_instantiate_inline(%s): inlining to local id %d",
2101-
ty::item_path_str(ccx.tcx, fn_id),
2102-
item.id];
2088+
alt check csearch::maybe_get_item_ast(ccx.tcx, ccx.maps, fn_id) {
2089+
csearch::not_found {
2090+
ccx.external.insert(fn_id, none);
2091+
fn_id
2092+
}
2093+
csearch::found(ast::ii_item(item)) {
21032094
ccx.external.insert(fn_id, some(item.id));
21042095
trans_item(ccx, *item);
21052096
local_def(item.id)
21062097
}
2107-
some(ast::ii_method(impl_did, mth)) {
2108-
#debug["maybe_instantiate_inline(%s): \
2109-
inlining method of %s to %d",
2110-
ty::item_path_str(ccx.tcx, fn_id),
2111-
ty::item_path_str(ccx.tcx, impl_did),
2112-
mth.id];
2098+
csearch::found_parent(parent_id, ast::ii_item(item)) {
2099+
ccx.external.insert(parent_id, some(item.id));
2100+
let my_id = 0;
2101+
alt check item.node {
2102+
ast::item_enum(_, _) {
2103+
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
2104+
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
2105+
vec::iter2(*vs_here, *vs_there) {|here, there|
2106+
if there.id == fn_id { my_id = here.id.node; }
2107+
ccx.external.insert(there.id, some(here.id.node));
2108+
}
2109+
}
2110+
ast::item_res(_, _, _, _, ctor_id) { my_id = ctor_id; }
2111+
}
2112+
trans_item(ccx, *item);
2113+
local_def(my_id)
2114+
}
2115+
csearch::found(ast::ii_method(impl_did, mth)) {
21132116
ccx.external.insert(fn_id, some(mth.id));
21142117
compute_ii_method_info(ccx, impl_did, mth) {|ty, bounds, path|
21152118
if bounds.len() == 0u {
@@ -2143,8 +2146,7 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
21432146
// monomorphized and non-monomorphized functions at the moment. If
21442147
// monomorphizing becomes the only approach, this'll be much simpler.
21452148
if (option::is_some(substs) || tys.len() > 0u) &&
2146-
fn_id.crate == ast::local_crate &&
2147-
!vec::any(tys, {|t| ty::type_has_params(t)}) {
2149+
fn_id.crate == ast::local_crate {
21482150
let mono = alt substs {
21492151
some((stys, vtables)) {
21502152
if (stys.len() + tys.len()) > 0u {

0 commit comments

Comments
 (0)