Skip to content

Commit ab60c2b

Browse files
committed
---
yaml --- r: 13282 b: refs/heads/master c: d5d7b3b h: refs/heads/master v: v3
1 parent b8f5618 commit ab60c2b

13 files changed

+96
-57
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: 9975ad073acc408ee1bb4fe776daeeb175aa8816
2+
refs/heads/master: d5d7b3b921ffe7d4a1a600206c213fc92826639c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

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

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
22522252
dtor"); }
22532253
};
22542254
trans_class_dtor(ccx, *pt, dtor.node.body,
2255-
dtor.node.id, psubsts, some(hash_id), parent_id, s)
2255+
dtor.node.id, psubsts, some(hash_id), parent_id)
22562256
}
22572257
// Ugh -- but this ensures any new variants won't be forgotten
22582258
ast_map::node_expr(*) { ccx.tcx.sess.bug("Can't monomorphize an expr") }
@@ -2448,19 +2448,7 @@ fn trans_local_var(cx: block, def: ast::def) -> local_var_result {
24482448
}
24492449
ast::def_self(sid) {
24502450
let slf = alt copy cx.fcx.llself {
2451-
some(s) {
2452-
alt option::map(ty::ty_to_def_id(s.t)) {|did|
2453-
ty::ty_dtor(cx.tcx(), did)} {
2454-
some(some(_)) {
2455-
/* self is a class with a dtor, which means we
2456-
have to select out the object itself
2457-
(If any other code does the same thing, that's
2458-
a bug */
2459-
GEPi(cx, cast_self(cx, s), [0u, 1u])
2460-
}
2461-
_ { cast_self(cx, s) }
2462-
}
2463-
}
2451+
some(s) { cast_self(cx, s) }
24642452
none { cx.sess().bug("trans_local_var: reference to self \
24652453
out of context"); }
24662454
};
@@ -2535,17 +2523,29 @@ fn trans_rec_field(bcx: block, base: @ast::expr,
25352523

25362524
fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
25372525
field: ast::ident, sp: span) -> lval_result {
2526+
let mut deref = false;
25382527
let fields = alt ty::get(ty).struct {
25392528
ty::ty_rec(fs) { fs }
25402529
ty::ty_class(did, substs) {
2530+
if option::is_some(ty::ty_dtor(bcx.tcx(), did)) {
2531+
deref = true;
2532+
}
25412533
ty::class_items_as_fields(bcx.tcx(), did, substs)
25422534
}
25432535
// Constraint?
25442536
_ { bcx.tcx().sess.span_bug(sp, "trans_rec_field:\
25452537
base expr has non-record type"); }
25462538
};
25472539
let ix = field_idx_strict(bcx.tcx(), sp, field, fields);
2548-
let val = GEPi(bcx, val, [0u, ix]);
2540+
2541+
/* self is a class with a dtor, which means we
2542+
have to select out the object itself
2543+
(If any other code does the same thing, that's
2544+
a bug */
2545+
let val = if deref {
2546+
GEPi(bcx, GEPi(bcx, val, [0u, 1u]), [0u, ix])
2547+
}
2548+
else { GEPi(bcx, val, [0u, ix]) };
25492549

25502550
ret {bcx: bcx, val: val, kind: owned};
25512551
}
@@ -4887,9 +4887,8 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
48874887
fn trans_class_dtor(ccx: @crate_ctxt, path: path,
48884888
body: ast::blk,
48894889
dtor_id: ast::node_id, substs: option<param_substs>,
4890-
hash_id: option<mono_id>, parent_id: ast::def_id,
4891-
// mangled exported name for dtor
4892-
s: str) -> ValueRef {
4890+
hash_id: option<mono_id>, parent_id: ast::def_id)
4891+
-> ValueRef {
48934892
let tcx = ccx.tcx;
48944893
/* Look up the parent class's def_id */
48954894
let mut class_ty = ty::lookup_item_type(tcx, parent_id).ty;
@@ -4903,6 +4902,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
49034902
let lldty = T_fn([T_ptr(type_of(ccx, ty::mk_nil(tcx))),
49044903
T_ptr(type_of(ccx, class_ty))],
49054904
llvm::LLVMVoidType());
4905+
let s = get_dtor_symbol(ccx, path, dtor_id);
49064906
/* Register the dtor as a function. It has external linkage */
49074907
let lldecl = decl_internal_cdecl_fn(ccx.llmod, s, lldty);
49084908
lib::llvm::SetLinkage(lldecl, lib::llvm::ExternalLinkage);
@@ -4912,9 +4912,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
49124912
option::iter(hash_id) {|h_id|
49134913
ccx.monomorphized.insert(h_id, lldecl);
49144914
}
4915-
/* Register the symbol for the dtor, and generate the code for its
4916-
body */
4917-
ccx.item_symbols.insert(dtor_id, s);
4915+
/* Translate the dtor body */
49184916
trans_fn(ccx, path, ast_util::dtor_dec(),
49194917
body, lldecl, impl_self(class_ty), substs, dtor_id);
49204918
lldecl
@@ -4997,11 +4995,8 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
49974995
get_item_val(ccx, ctor.node.id), psubsts,
49984996
ctor.node.id, local_def(item.id), ctor.span);
49994997
option::iter(m_dtor) {|dtor|
5000-
let s = mangle_exported_name(ccx, *path +
5001-
[path_name(ccx.names("dtor"))],
5002-
ty::node_id_to_type(ccx.tcx, dtor.node.id));
50034998
trans_class_dtor(ccx, *path, dtor.node.body,
5004-
dtor.node.id, none, none, local_def(item.id), s);
4999+
dtor.node.id, none, none, local_def(item.id));
50055000
};
50065001
}
50075002
// If there are ty params, the ctor will get monomorphized
@@ -5162,8 +5157,21 @@ fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
51625157
} + [path_name(i.ident)]
51635158
}
51645159

5160+
/* If there's already a symbol for the dtor with <id>, return it;
5161+
otherwise, create one and register it, returning it as well */
5162+
fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id) -> str {
5163+
alt ccx.item_symbols.find(id) {
5164+
some(s) { s }
5165+
none {
5166+
let s = mangle_exported_name(ccx, path +
5167+
[path_name(ccx.names("dtor"))], ty::node_id_to_type(ccx.tcx, id));
5168+
ccx.item_symbols.insert(id, s);
5169+
s
5170+
}
5171+
}
5172+
}
5173+
51655174
fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5166-
#debug("get_item_val: %d", id);
51675175
let tcx = ccx.tcx;
51685176
alt ccx.item_vals.find(id) {
51695177
some(v) { v }
@@ -5242,11 +5250,8 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
52425250
let lldty = T_fn([T_ptr(type_of(ccx, ty::mk_nil(tcx))),
52435251
T_ptr(type_of(ccx, class_ty))],
52445252
llvm::LLVMVoidType());
5245-
/* The symbol for the dtor should have already been registered */
5246-
let s: str = alt ccx.item_symbols.find(id) {
5247-
some(s) { s }
5248-
none { ccx.sess.bug("in get_item_val, dtor is unbound"); }
5249-
};
5253+
let s = get_dtor_symbol(ccx, *pt, dt.node.id);
5254+
52505255
/* Make the declaration for the dtor */
52515256
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, lldty);
52525257
lib::llvm::SetLinkage(llfn, lib::llvm::ExternalLinkage);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ fn traverse_def_id(cx: ctx, did: def_id) {
6363
ast_map::node_method(_, impl_id, _) { traverse_def_id(cx, impl_id); }
6464
ast_map::node_native_item(item, _, _) { cx.rmap.insert(item.id, ()); }
6565
ast_map::node_variant(v, _, _) { cx.rmap.insert(v.node.id, ()); }
66+
// If it's a class ctor, consider the parent reachable
67+
ast_map::node_ctor(_, _, ast_map::class_ctor(_, parent_id), _) {
68+
traverse_def_id(cx, parent_id);
69+
}
6670
_ {}
6771
}
6872
}

trunk/src/snapshots.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
S 2012-06-05 fec3b91
2+
winnt-i386 36348a2b016f25d9e3b7e1a8814a352c18123839
3+
linux-x86_64 7308f0eb3d6a9985c14dfbbde7e1f9eb901cc966
4+
linux-i386 d4c1e1733fd30945f96ae67dbc10289f2a9ec380
5+
freebsd-x86_64 d0ee6054d7d8320d64aa4dbb9b041537fa2665d5
6+
macos-x86_64 652501172b4fee6631f595c90538fd95914ef444
7+
macos-i386 5c54b5ecf54cc2631fdd48caa326ab44b5a2e494
8+
19
S 2012-06-04 7213274
210
winnt-i386 94b9414433fd83c086b349ded3159f0541aace16
311
linux-x86_64 eb9cf0de4cc09e8b8bfcf741eff4b20510e13a5b

trunk/src/test/run-fail/morestack2.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ fn getbig_call_c_and_fail(i: int) {
2020
}
2121
}
2222

23-
resource and_then_get_big_again(_i: ()) {
23+
class and_then_get_big_again {
24+
new() {}
25+
drop {
2426
fn getbig(i: int) {
2527
if i != 0 {
2628
getbig(i - 1);
2729
}
2830
}
2931
getbig(10000);
32+
}
3033
}
3134

3235
fn main() {
3336
task::spawn {||
34-
let r = and_then_get_big_again(());
37+
let r = and_then_get_big_again();
3538
getbig_call_c_and_fail(10000);
3639
};
3740
}

trunk/src/test/run-fail/morestack3.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
use std;
66

77
fn getbig_and_fail(&&i: int) {
8-
let r = and_then_get_big_again(@0);
8+
let _r = and_then_get_big_again();
99
if i != 0 {
1010
getbig_and_fail(i - 1);
1111
} else {
1212
fail;
1313
}
1414
}
1515

16-
resource and_then_get_big_again(_i: @int) {
16+
class and_then_get_big_again {
17+
new() {}
18+
drop {
1719
fn getbig(i: int) {
1820
if i != 0 {
1921
getbig(i - 1);
2022
}
2123
}
2224
getbig(100);
25+
}
2326
}
2427

2528
fn main() {

trunk/src/test/run-fail/morestack4.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
use std;
66

77
fn getbig_and_fail(&&i: int) {
8-
let r = and_then_get_big_again(@0);
8+
let r = and_then_get_big_again();
99
if i != 0 {
1010
getbig_and_fail(i - 1);
1111
} else {
1212
fail;
1313
}
1414
}
1515

16-
resource and_then_get_big_again(_i: @int) {
16+
class and_then_get_big_again {
17+
new() {}
18+
drop {}
1719
}
1820

1921
fn main() {
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// error-pattern:whatever
22

3-
fn main() {
4-
log(error, "whatever");
5-
task::spawn {||
6-
resource r(_i: ()) {
3+
class r {
74
// Setting the exit status after the runtime has already
85
// failed has no effect and the process exits with the
96
// runtime's exit code
10-
os::set_exit_status(50);
11-
}
12-
let i = r(());
7+
drop {
8+
os::set_exit_status(50);
9+
}
10+
new() {}
11+
}
12+
13+
fn main() {
14+
log(error, "whatever");
15+
task::spawn {||
16+
let i = r();
1317
};
1418
fail;
1519
}

trunk/src/test/run-fail/too-much-recursion-unwinding.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ fn recurse() {
99
recurse();
1010
}
1111

12-
resource r(recursed: *mut bool) unsafe {
12+
class r {
13+
let recursed: *mut bool;
14+
new(recursed: *mut bool) unsafe { self.recursed = recursed; }
15+
drop unsafe {
1316
if !*recursed {
1417
*recursed = true;
1518
recurse();
1619
}
20+
}
1721
}
1822

1923
fn main() {

trunk/src/test/run-fail/unwind-box-res.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ fn failfn() {
44
fail;
55
}
66

7-
resource r(v: *int) unsafe {
8-
let v2: ~int = unsafe::reinterpret_cast(v);
7+
class r {
8+
let v: *int;
9+
new(v: *int) { self.v = v; }
10+
drop unsafe {
11+
let _v2: ~int = unsafe::reinterpret_cast(self.v);
12+
}
913
}
1014

1115
fn main() unsafe {

trunk/src/test/run-fail/unwind-resource-fail.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// error-pattern:fail
22
// xfail-test
33

4-
resource r(i: int) {
5-
// What happens when destructors throw?
6-
fail;
4+
class r {
5+
new(i:int) {}
6+
drop { fail; }
77
}
88

99
fn main() {

trunk/src/test/run-fail/unwind-resource-fail2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// error-pattern:fail
22
// xfail-test
33

4-
resource r(i: int) {
5-
// Double-fail!!
6-
fail;
4+
class r {
5+
new(i:int) {}
6+
drop { fail; }
77
}
88

99
fn main() {

trunk/src/test/run-fail/unwind-resource-fail3.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// error-pattern:quux
22
// xfail-test
33

4-
resource faily_box(_i: @int) {
5-
// What happens to the box pointer owned by this resource?
6-
fail "quux";
4+
class faily_box {
5+
let i: @int;
6+
new(i: @int) { self.i = i; }
7+
// What happens to the box pointer owned by this class?
8+
drop { fail "quux"; }
79
}
810

911
fn main() {

0 commit comments

Comments
 (0)