Skip to content

Commit 7d0adbc

Browse files
committed
---
yaml --- r: 95861 b: refs/heads/dist-snap c: c118b89 h: refs/heads/master i: 95859: f12a676 v: v3
1 parent 811397b commit 7d0adbc

File tree

4 files changed

+42
-60
lines changed

4 files changed

+42
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 702767db65c9b9d4e601ec5de836246fb9a9e462
9+
refs/heads/dist-snap: c118b89ad94ecabf3de85f8e8df81f0acf552caa
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/tutorial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ different type from `Bar(1, 2)`), and tuple structs' _fields_ do not have
759759
names.
760760

761761
For example:
762+
762763
~~~~
763764
struct MyTup(int, int, f64);
764765
let mytup: MyTup = MyTup(10, 20, 30.0);

branches/dist-snap/src/librustc/middle/trans/glue.rs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,39 @@ pub fn trans_struct_drop_flag(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did:
395395
let repr = adt::represent_type(bcx.ccx(), t);
396396
let drop_flag = adt::trans_drop_flag_ptr(bcx, repr, v0);
397397
do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| {
398-
trans_struct_drop(cx, t, v0, dtor_did, class_did, substs)
398+
let mut bcx = cx;
399+
400+
// Find and call the actual destructor
401+
let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did,
402+
class_did, substs.tps.clone());
403+
404+
// The second argument is the "self" argument for drop
405+
let params = unsafe {
406+
let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
407+
ty.element_type().func_params()
408+
};
409+
410+
// Class dtors have no explicit args, so the params should
411+
// just consist of the environment (self)
412+
assert_eq!(params.len(), 1);
413+
414+
let self_arg = PointerCast(bcx, v0, params[0]);
415+
let args = ~[self_arg];
416+
417+
Call(bcx, dtor_addr, args, []);
418+
419+
// Drop the fields
420+
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
421+
for (i, fld) in field_tys.iter().enumerate() {
422+
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
423+
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
424+
}
425+
426+
bcx
399427
}
400428
}
401429

402-
pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast::DefId,
430+
pub fn trans_struct_drop(mut bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast::DefId,
403431
class_did: ast::DefId, substs: &ty::substs) -> @mut Block {
404432
let repr = adt::represent_type(bcx.ccx(), t);
405433

@@ -417,24 +445,19 @@ pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast:
417445
// just consist of the environment (self)
418446
assert_eq!(params.len(), 1);
419447

420-
// Be sure to put all of the fields into a scope so we can use an invoke
421-
// instruction to call the user destructor but still call the field
422-
// destructors if the user destructor fails.
423-
do with_scope(bcx, None, "field drops") |bcx| {
424-
let self_arg = PointerCast(bcx, v0, params[0]);
425-
let args = ~[self_arg];
448+
let self_arg = PointerCast(bcx, v0, params[0]);
449+
let args = ~[self_arg];
426450

427-
// Add all the fields as a value which needs to be cleaned at the end of
428-
// this scope.
429-
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
430-
for (i, fld) in field_tys.iter().enumerate() {
431-
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
432-
add_clean(bcx, llfld_a, fld.mt.ty);
433-
}
451+
Call(bcx, dtor_addr, args, []);
434452

435-
let (_, bcx) = invoke(bcx, dtor_addr, args, []);
436-
bcx
453+
// Drop the fields
454+
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
455+
for (i, fld) in field_tys.iter().enumerate() {
456+
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
457+
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
437458
}
459+
460+
bcx
438461
}
439462

440463
pub fn make_drop_glue(bcx: @mut Block, v0: ValueRef, t: ty::t) -> @mut Block {

branches/dist-snap/src/test/run-pass/fail-in-dtor-drops-fields.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)