Skip to content

Commit 336f812

Browse files
author
Ariel Ben-Yehuda
committed
Remove type_needs_unwind_cleanup
After the last @dinosaur went extinct, the check became redundant with type_needs_drop, except for its bugginess. Fixes #26655.
1 parent bf164bc commit 336f812

File tree

3 files changed

+37
-51
lines changed

3 files changed

+37
-51
lines changed

src/librustc_trans/trans/cleanup.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
389389
if !self.type_needs_drop(ty) { return; }
390390
let drop = box DropValue {
391391
is_immediate: false,
392-
must_unwind: common::type_needs_unwind_cleanup(self.ccx, ty),
393392
val: val,
394393
ty: ty,
395394
fill_on_drop: false,
@@ -415,7 +414,6 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
415414

416415
let drop = box DropValue {
417416
is_immediate: false,
418-
must_unwind: common::type_needs_unwind_cleanup(self.ccx, ty),
419417
val: val,
420418
ty: ty,
421419
fill_on_drop: true,
@@ -447,7 +445,6 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
447445

448446
let drop = box DropValue {
449447
is_immediate: false,
450-
must_unwind: common::type_needs_unwind_cleanup(self.ccx, ty),
451448
val: val,
452449
ty: ty,
453450
fill_on_drop: false,
@@ -473,7 +470,6 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
473470
if !self.type_needs_drop(ty) { return; }
474471
let drop = box DropValue {
475472
is_immediate: true,
476-
must_unwind: common::type_needs_unwind_cleanup(self.ccx, ty),
477473
val: val,
478474
ty: ty,
479475
fill_on_drop: false,
@@ -1031,7 +1027,6 @@ impl EarlyExitLabel {
10311027
#[derive(Copy, Clone)]
10321028
pub struct DropValue<'tcx> {
10331029
is_immediate: bool,
1034-
must_unwind: bool,
10351030
val: ValueRef,
10361031
ty: Ty<'tcx>,
10371032
fill_on_drop: bool,
@@ -1040,11 +1035,11 @@ pub struct DropValue<'tcx> {
10401035

10411036
impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> {
10421037
fn must_unwind(&self) -> bool {
1043-
self.must_unwind
1038+
true
10441039
}
10451040

10461041
fn clean_on_unwind(&self) -> bool {
1047-
self.must_unwind
1042+
true
10481043
}
10491044

10501045
fn is_lifetime_end(&self) -> bool {

src/librustc_trans/trans/common.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use middle::lang_items::LangItem;
2525
use middle::mem_categorization as mc;
2626
use middle::mem_categorization::Typer;
2727
use middle::region;
28-
use middle::subst::{self, Subst, Substs};
28+
use middle::subst::{self, Substs};
2929
use trans::base;
3030
use trans::build;
3131
use trans::cleanup;
@@ -54,8 +54,6 @@ use syntax::ast;
5454
use syntax::codemap::{DUMMY_SP, Span};
5555
use syntax::parse::token::InternedString;
5656
use syntax::parse::token;
57-
use util::common::memoized;
58-
use util::nodemap::FnvHashSet;
5957

6058
pub use trans::context::CrateContext;
6159

@@ -136,47 +134,6 @@ pub fn type_is_fat_ptr<'tcx>(cx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool {
136134
}
137135
}
138136

139-
// Some things don't need cleanups during unwinding because the
140-
// thread can free them all at once later. Currently only things
141-
// that only contain scalars and shared boxes can avoid unwind
142-
// cleanups.
143-
pub fn type_needs_unwind_cleanup<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
144-
return memoized(ccx.needs_unwind_cleanup_cache(), ty, |ty| {
145-
type_needs_unwind_cleanup_(ccx.tcx(), ty, &mut FnvHashSet())
146-
});
147-
148-
fn type_needs_unwind_cleanup_<'tcx>(tcx: &ty::ctxt<'tcx>,
149-
ty: Ty<'tcx>,
150-
tycache: &mut FnvHashSet<Ty<'tcx>>)
151-
-> bool
152-
{
153-
// Prevent infinite recursion
154-
if !tycache.insert(ty) {
155-
return false;
156-
}
157-
158-
let mut needs_unwind_cleanup = false;
159-
ty.maybe_walk(|ty| {
160-
needs_unwind_cleanup |= match ty.sty {
161-
ty::TyBool | ty::TyInt(_) | ty::TyUint(_) |
162-
ty::TyFloat(_) | ty::TyTuple(_) | ty::TyRawPtr(_) => false,
163-
164-
ty::TyEnum(did, substs) =>
165-
tcx.enum_variants(did).iter().any(|v|
166-
v.args.iter().any(|&aty| {
167-
let t = aty.subst(tcx, substs);
168-
type_needs_unwind_cleanup_(tcx, t, tycache)
169-
})
170-
),
171-
172-
_ => true
173-
};
174-
!needs_unwind_cleanup
175-
});
176-
needs_unwind_cleanup
177-
}
178-
}
179-
180137
/// If `type_needs_drop` returns true, then `ty` is definitely
181138
/// non-copy and *might* have a destructor attached; if it returns
182139
/// false, then `ty` definitely has no destructor (i.e. no drop glue).

src/test/run-pass/issue-26655.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_fn)]
12+
13+
// Check that the destructors of simple enums are run on unwinding
14+
15+
use std::sync::atomic::{Ordering, AtomicUsize};
16+
use std::thread;
17+
18+
static LOG: AtomicUsize = AtomicUsize::new(0);
19+
20+
enum WithDtor { Val }
21+
impl Drop for WithDtor {
22+
fn drop(&mut self) {
23+
LOG.store(LOG.load(Ordering::SeqCst)+1,Ordering::SeqCst);
24+
}
25+
}
26+
27+
pub fn main() {
28+
thread::spawn(move|| {
29+
let _e: WithDtor = WithDtor::Val;
30+
panic!("fail");
31+
}).join().unwrap_err();
32+
33+
assert_eq!(LOG.load(Ordering::SeqCst), 1);
34+
}

0 commit comments

Comments
 (0)