@@ -259,7 +259,6 @@ struct ctxt_ {
259
259
rcache : creader_cache ,
260
260
ccache : constness_cache ,
261
261
short_names_cache : HashMap < t , @~str > ,
262
- needs_drop_cache : HashMap < t , bool > ,
263
262
needs_unwind_cleanup_cache : HashMap < t , bool > ,
264
263
tc_cache : @mut LinearMap < uint , TypeContents > ,
265
264
ast_ty_to_ty_cache : HashMap < node_id , ast_ty_to_ty_cache_entry > ,
@@ -822,7 +821,6 @@ pub fn mk_ctxt(s: session::Session,
822
821
rcache : mk_rcache ( ) ,
823
822
ccache : HashMap ( ) ,
824
823
short_names_cache : new_ty_hash ( ) ,
825
- needs_drop_cache : new_ty_hash ( ) ,
826
824
needs_unwind_cleanup_cache : new_ty_hash ( ) ,
827
825
tc_cache : @mut LinearMap :: new ( ) ,
828
826
ast_ty_to_ty_cache : HashMap ( ) ,
@@ -1600,79 +1598,7 @@ pub fn type_is_immediate(ty: t) -> bool {
1600
1598
}
1601
1599
1602
1600
pub fn type_needs_drop(cx: ctxt, ty: t) -> bool {
1603
- match cx.needs_drop_cache.find(&ty) {
1604
- Some(result) => return result,
1605
- None => {/* fall through */ }
1606
- }
1607
-
1608
- let mut accum = false;
1609
- let result = match /*bad*/copy get(ty).sty {
1610
- // scalar types
1611
- ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
1612
- ty_type | ty_ptr(_) | ty_rptr(_, _) |
1613
- ty_estr(vstore_fixed(_)) |
1614
- ty_estr(vstore_slice(_)) |
1615
- ty_evec(_, vstore_slice(_)) |
1616
- ty_self => false,
1617
-
1618
- ty_box(_) | ty_uniq(_) |
1619
- ty_opaque_box | ty_opaque_closure_ptr(*) |
1620
- ty_estr(vstore_uniq) |
1621
- ty_estr(vstore_box) |
1622
- ty_evec(_, vstore_uniq) |
1623
- ty_evec(_, vstore_box) => true,
1624
-
1625
- ty_trait(_, _, vstore_box) |
1626
- ty_trait(_, _, vstore_uniq) => true,
1627
- ty_trait(_, _, vstore_fixed(_)) |
1628
- ty_trait(_, _, vstore_slice(_)) => false,
1629
-
1630
- ty_param(*) | ty_infer(*) | ty_err => true,
1631
-
1632
- ty_evec(mt, vstore_fixed(_)) => type_needs_drop(cx, mt.ty),
1633
- ty_unboxed_vec(mt) => type_needs_drop(cx, mt.ty),
1634
- ty_rec(flds) => {
1635
- for flds.each |f| {
1636
- if type_needs_drop(cx, f.mt.ty) { accum = true; }
1637
- }
1638
- accum
1639
- }
1640
- ty_struct(did, ref substs) => {
1641
- // Any struct with a dtor needs a drop
1642
- ty_dtor(cx, did).is_present() || {
1643
- for vec::each(ty::struct_fields(cx, did, substs)) |f| {
1644
- if type_needs_drop(cx, f.mt.ty) { accum = true; }
1645
- }
1646
- accum
1647
- }
1648
- }
1649
- ty_tup(elts) => {
1650
- for elts.each |m| { if type_needs_drop(cx, *m) { accum = true; } }
1651
- accum
1652
- }
1653
- ty_enum(did, ref substs) => {
1654
- let variants = enum_variants(cx, did);
1655
- for vec::each(*variants) |variant| {
1656
- for variant.args.each |aty| {
1657
- // Perform any type parameter substitutions.
1658
- let arg_ty = subst(cx, substs, *aty);
1659
- if type_needs_drop(cx, arg_ty) { accum = true; }
1660
- }
1661
- if accum { break; }
1662
- }
1663
- accum
1664
- }
1665
- ty_bare_fn(*) => false,
1666
- ty_closure(ref fty) => {
1667
- match fty.sigil {
1668
- ast::BorrowedSigil => false,
1669
- ast::ManagedSigil | ast::OwnedSigil => true,
1670
- }
1671
- }
1672
- };
1673
-
1674
- cx.needs_drop_cache.insert(ty, result);
1675
- return result;
1601
+ type_contents(cx, ty).needs_drop(cx)
1676
1602
}
1677
1603
1678
1604
// Some things don't need cleanups during unwinding because the
@@ -1819,7 +1745,7 @@ pub impl TypeContents {
1819
1745
1820
1746
static fn nonimplicitly_copyable(cx: ctxt) -> TypeContents {
1821
1747
let base = TypeContents::noncopyable(cx) + TC_OWNED_POINTER;
1822
- if cx.vecs_implicitly_copyable {base} else {base + TC_OWNED_SLICE }
1748
+ if cx.vecs_implicitly_copyable {base} else {base + TC_OWNED_VEC }
1823
1749
}
1824
1750
1825
1751
fn is_safe_for_default_mode(&self, cx: ctxt) -> bool {
@@ -1828,7 +1754,17 @@ pub impl TypeContents {
1828
1754
1829
1755
static fn nondefault_mode(cx: ctxt) -> TypeContents {
1830
1756
let tc = TypeContents::nonimplicitly_copyable(cx);
1831
- tc + TC_BIG + TC_OWNED_SLICE // disregard cx.vecs_implicitly_copyable
1757
+ tc + TC_BIG + TC_OWNED_VEC // disregard cx.vecs_implicitly_copyable
1758
+ }
1759
+
1760
+ fn needs_drop(&self, cx: ctxt) -> bool {
1761
+ let tc = TC_MANAGED + TC_DTOR + TypeContents::owned(cx);
1762
+ self.intersects(tc)
1763
+ }
1764
+
1765
+ static fn owned(&self, _cx: ctxt) -> TypeContents {
1766
+ //! Any kind of owned contents.
1767
+ TC_OWNED_CLOSURE + TC_OWNED_POINTER + TC_OWNED_VEC
1832
1768
}
1833
1769
}
1834
1770
@@ -1859,8 +1795,8 @@ const TC_BORROWED_POINTER: TypeContents = TypeContents{bits:0b0000_00000001};
1859
1795
/// Contains an owned pointer (~T) but not slice of some kind
1860
1796
const TC_OWNED_POINTER: TypeContents = TypeContents{bits:0b000000000010};
1861
1797
1862
- /// Contains an owned slice
1863
- const TC_OWNED_SLICE : TypeContents = TypeContents{bits:0b000000000100};
1798
+ /// Contains an owned vector ~[] or owned string ~str
1799
+ const TC_OWNED_VEC : TypeContents = TypeContents{bits:0b000000000100};
1864
1800
1865
1801
/// Contains a ~fn() or a ~Trait, which is non-copyable.
1866
1802
const TC_OWNED_CLOSURE: TypeContents = TypeContents{bits:0b000000001000};
@@ -1963,7 +1899,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
1963
1899
}
1964
1900
1965
1901
ty_estr(vstore_uniq) => {
1966
- TC_OWNED_SLICE
1902
+ TC_OWNED_VEC
1967
1903
}
1968
1904
1969
1905
ty_closure(ref c) => {
@@ -1996,7 +1932,7 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
1996
1932
}
1997
1933
1998
1934
ty_evec(mt, vstore_uniq) => {
1999
- TC_OWNED_SLICE + tc_mt(cx, mt, cache)
1935
+ TC_OWNED_VEC + tc_mt(cx, mt, cache)
2000
1936
}
2001
1937
2002
1938
ty_evec(mt, vstore_box) => {
0 commit comments