Skip to content

Commit 1cf364f

Browse files
committed
---
yaml --- r: 11865 b: refs/heads/master c: 4650e8b h: refs/heads/master i: 11863: 46459b5 v: v3
1 parent 5e73056 commit 1cf364f

File tree

8 files changed

+74
-47
lines changed

8 files changed

+74
-47
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: 8f84d4c8b6305c960cf51c35a5ea38697d7fa530
2+
refs/heads/master: 4650e8bcf404d4c27dbbd5446a56fb066ada30f9
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ fn visit_ids(item: ast::inlined_item, vfn: fn@(ast::node_id)) {
135135

136136
visit_item: fn@(i: @ast::item) {
137137
vfn(i.id);
138+
alt i.node {
139+
ast::item_res(_, _, _, d_id, c_id) { vfn(d_id); vfn(c_id); }
140+
_ {}
141+
}
138142
},
139143

140144
visit_local: fn@(l: @ast::local) {

trunk/src/rustc/metadata/encoder.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
339339
}
340340

341341
let tcx = ecx.ccx.tcx;
342-
let must_write = alt item.node {
343-
item_enum(_, _) | item_res(_, _, _, _, _) { true }
344-
_ { false }
345-
};
342+
let must_write = alt item.node { item_enum(_, _) { true } _ { false } };
346343
if !must_write && !ecx.reachable.contains_key(item.id) { ret false; }
347344

348345
alt item.node {
@@ -419,6 +416,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
419416
encode_name(ebml_w, item.ident);
420417
if tps.len() == 0u {
421418
encode_symbol(ecx, ebml_w, item.id);
419+
} else {
420+
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
422421
}
423422
encode_path(ebml_w, path, ast_map::path_name(item.ident));
424423
ebml_w.end_tag();
@@ -533,7 +532,7 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
533532
ecx.ccx.tcx.items.items {|key, val|
534533
let where = ebml_w.writer.tell();
535534
let written = alt val {
536-
middle::ast_map::node_item(i, path) {
535+
middle::ast_map::node_item(i, path) if i.id == key {
537536
encode_info_for_item(ecx, ebml_w, i, index, *path)
538537
}
539538
middle::ast_map::node_native_item(i, _, path) {

trunk/src/rustc/metadata/reachable.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import middle::{resolve, ast_map, typeck};
99
import syntax::ast::*;
10-
import syntax::visit;
10+
import syntax::{visit, ast_util};
1111
import syntax::ast_util::def_id_of_def;
1212
import front::attr;
1313
import std::map::hashmap;
@@ -22,7 +22,9 @@ type ctx = {ccx: @middle::trans::common::crate_ctxt,
2222
fn find_reachable(ccx: @middle::trans::common::crate_ctxt, crate_mod: _mod)
2323
-> map {
2424
let rmap = std::map::int_hash();
25-
traverse_public_mod({ccx: ccx, rmap: rmap}, crate_mod);
25+
let cx = {ccx: ccx, rmap: rmap};
26+
traverse_public_mod(cx, crate_mod);
27+
traverse_all_resources(cx, crate_mod);
2628
rmap
2729
}
2830

@@ -124,3 +126,17 @@ fn traverse_inline_body(cx: ctx, body: blk) {
124126
with *visit::default_visitor()
125127
}));
126128
}
129+
130+
fn traverse_all_resources(cx: ctx, crate_mod: _mod) {
131+
visit::visit_mod(crate_mod, ast_util::dummy_sp(), 0, cx, visit::mk_vt(@{
132+
visit_expr: {|_e, _cx, _v|},
133+
visit_item: {|i, cx, v|
134+
visit::visit_item(i, cx, v);
135+
alt i.node {
136+
item_res(_, _, _, _, _) { traverse_public_item(cx, i); }
137+
_ {}
138+
}
139+
}
140+
with *visit::default_visitor()
141+
}));
142+
}

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,24 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
859859
build_return(bcx);
860860
}
861861

862+
fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
863+
-> ValueRef {
864+
let did = if did.crate != ast::local_crate && substs.len() > 0u {
865+
maybe_instantiate_inline(ccx, did)
866+
} 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+
}
878+
}
879+
862880
fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
863881
inner_t: ty::t, tps: [ty::t]) -> block {
864882
let ccx = bcx.ccx();
@@ -869,16 +887,11 @@ fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
869887
with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) {|bcx|
870888
let {bcx, val: valptr} = GEP_tup_like(bcx, tup_ty, rs, [0, 1]);
871889
// Find and call the actual destructor.
872-
let dtor_addr = common::get_res_dtor(ccx, did, inner_t);
890+
let dtor_addr = get_res_dtor(ccx, did, tps);
873891
let args = [bcx.fcx.llretptr, null_env_ptr(bcx)];
874-
for tp in tps {
875-
let td = get_tydesc_simple(bcx, tp);
876-
args += [td.val];
877-
bcx = td.bcx;
878-
}
879892
// Kludge to work around the fact that we know the precise type of the
880-
// value here, but the dtor expects a type that still has opaque
881-
// pointers for type variables.
893+
// value here, but the dtor expects a type that might have opaque
894+
// boxes and such.
882895
let val_llty = lib::llvm::fn_ty_param_tys
883896
(llvm::LLVMGetElementType
884897
(llvm::LLVMTypeOf(dtor_addr)))[args.len()];
@@ -1997,13 +2010,20 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
19972010
}
19982011

19992012
let tpt = ty::lookup_item_type(ccx.tcx, fn_id);
2000-
let mono_ty = ty::substitute_type_params(ccx.tcx, substs, tpt.ty);
2001-
let llfty = type_of_fn_from_ty(ccx, mono_ty, 0u);
2013+
let item_ty = tpt.ty;
20022014

20032015
let map_node = ccx.tcx.items.get(fn_id.node);
20042016
// Get the path so that we can create a symbol
20052017
let (pt, name) = alt map_node {
2006-
ast_map::node_item(i, pt) { (pt, i.ident) }
2018+
ast_map::node_item(i, pt) {
2019+
alt i.node {
2020+
ast::item_res(_, _, _, dtor_id, _) {
2021+
item_ty = ty::node_id_to_type(ccx.tcx, dtor_id);
2022+
}
2023+
_ {}
2024+
}
2025+
(pt, i.ident)
2026+
}
20072027
ast_map::node_variant(v, _, pt) { (pt, v.node.name) }
20082028
ast_map::node_method(m, _, pt) { (pt, m.ident) }
20092029
// We can't monomorphize native functions
@@ -2015,6 +2035,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
20152035
}
20162036
_ { fail "unexpected node type"; }
20172037
};
2038+
let mono_ty = ty::substitute_type_params(ccx.tcx, substs, item_ty);
2039+
let llfty = type_of_fn_from_ty(ccx, mono_ty, 0u);
2040+
20182041
let pt = *pt + [path_name(ccx.names(name))];
20192042
let s = mangle_exported_name(ccx, pt, mono_ty);
20202043
let lldecl = decl_cdecl_fn(ccx.llmod, s, llfty);
@@ -2027,6 +2050,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
20272050
trans_fn(ccx, pt, decl, body, lldecl, no_self, psubsts, fn_id.node,
20282051
none);
20292052
}
2053+
ast_map::node_item(@{node: ast::item_res(d, _, body, d_id, _), _}, _) {
2054+
trans_fn(ccx, pt, d, body, lldecl, no_self, psubsts, d_id, none);
2055+
}
20302056
ast_map::node_variant(v, enum_item, _) {
20312057
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
20322058
let this_tv = option::get(vec::find(*tvs, {|tv|

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,6 @@ fn revoke_clean(cx: block, val: ValueRef) {
298298
}
299299
}
300300

301-
fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, inner_t: ty::t)
302-
-> ValueRef {
303-
if did.crate == ast::local_crate {
304-
ret base::get_item_val(ccx, did.node);
305-
}
306-
307-
let param_bounds = ty::lookup_item_type(ccx.tcx, did).bounds;
308-
let nil_res = ty::mk_nil(ccx.tcx);
309-
let fn_mode = ast::expl(ast::by_ref);
310-
let f_t = type_of::type_of_fn(ccx, [{mode: fn_mode, ty: inner_t}],
311-
nil_res, (*param_bounds).len());
312-
ret base::get_extern_const(ccx.externs, ccx.llmod,
313-
csearch::get_symbol(ccx.sess.cstore,
314-
did), f_t);
315-
}
316-
317301
enum block_kind {
318302
// A scope at the end of which temporary values created inside of it are
319303
// cleaned up. May correspond to an actual block in the language, but also

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import std::map::hashmap;
2121

2222
import ty_ctxt = middle::ty::ctxt;
2323

24-
type res_info = {did: ast::def_id, t: ty::t};
24+
type res_info = {did: ast::def_id, tps: [ty::t]};
2525

2626
type ctxt =
2727
{mutable next_tag_id: u16,
@@ -67,15 +67,13 @@ fn hash_res_info(ri: res_info) -> uint {
6767
h += ri.did.crate as uint;
6868
h *= 33u;
6969
h += ri.did.node as uint;
70-
h *= 33u;
71-
h += ty::type_id(ri.t);
70+
for t in ri.tps {
71+
h *= 33u;
72+
h += ty::type_id(t);
73+
}
7274
ret h;
7375
}
7476

75-
fn eq_res_info(a: res_info, b: res_info) -> bool {
76-
ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t;
77-
}
78-
7977
fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) ->
8078
ValueRef {
8179
let llglobal =
@@ -278,7 +276,7 @@ fn mk_ctxt(llmod: ModuleRef) -> ctxt {
278276
pad: 0u16,
279277
tag_id_to_index: common::new_def_hash(),
280278
mutable tag_order: [],
281-
resources: interner::mk(hash_res_info, eq_res_info),
279+
resources: interner::mk(hash_res_info, {|a, b| a == b}),
282280
llshapetablesty: llshapetablesty,
283281
llshapetables: llshapetables};
284282
}
@@ -391,7 +389,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
391389
}
392390
ty::ty_res(did, raw_subt, tps) {
393391
let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
394-
let ri = {did: did, t: subt};
392+
let ri = {did: did, tps: tps};
395393
let id = interner::intern(ccx.shape_cx.resources, ri);
396394

397395
s += [shape_res];
@@ -553,7 +551,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
553551
let len = interner::len(ccx.shape_cx.resources);
554552
while i < len {
555553
let ri = interner::get(ccx.shape_cx.resources, i);
556-
dtors += [trans::common::get_res_dtor(ccx, ri.did, ri.t)];
554+
dtors += [trans::base::get_res_dtor(ccx, ri.did, ri.tps)];
557555
i += 1u;
558556
}
559557

trunk/src/rustc/syntax/fold.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
289289
item_res(fold_fn_decl(decl, fld),
290290
fold_ty_params(typms, fld),
291291
fld.fold_block(body),
292-
did,
293-
cid)
292+
fld.new_id(did),
293+
fld.new_id(cid))
294294
}
295295
};
296296
}

0 commit comments

Comments
 (0)