Skip to content

Commit 0f61039

Browse files
authored
Rollup merge of rust-lang#41349 - eddyb:ty-contents, r=nikomatsakis
rustc: replace TypeContents with two independent properties (is_freeze / needs_drop). `InteriorUnsafe` / `interior_unsafe` was replaced with a private lang-item `Freeze` auto trait in libcore. `OwnsDtor` / `needs_drop` was replaced with a specialized traversal that *doesn't* avoid caching results in case of a cycle, as the only cycles left can only occur in erroneous "types with infinite sizes", references and raw pointers not having destructors. Also, `Copy` is now checked at every step of the recursion. r? @nikomatsakis
2 parents 71f1482 + 6528f11 commit 0f61039

File tree

19 files changed

+222
-317
lines changed

19 files changed

+222
-317
lines changed

src/libcore/marker.rs

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
#![stable(feature = "rust1", since = "1.0.0")]
1818

19+
use cell::UnsafeCell;
1920
use cmp;
2021
use hash::Hash;
2122
use hash::Hasher;
@@ -553,3 +554,19 @@ mod impls {
553554
#[stable(feature = "rust1", since = "1.0.0")]
554555
unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
555556
}
557+
558+
/// Compiler-internal trait used to determine whether a type contains
559+
/// any `UnsafeCell` internally, but not through an indirection.
560+
/// This affects, for example, whether a `static` of that type is
561+
/// placed in read-only static memory or writable static memory.
562+
#[cfg_attr(not(stage0), lang = "freeze")]
563+
unsafe trait Freeze {}
564+
565+
unsafe impl Freeze for .. {}
566+
567+
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
568+
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
569+
unsafe impl<T: ?Sized> Freeze for *const T {}
570+
unsafe impl<T: ?Sized> Freeze for *mut T {}
571+
unsafe impl<'a, T: ?Sized> Freeze for &'a T {}
572+
unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}

src/librustc/middle/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ language_item_table! {
274274
UnsizeTraitLangItem, "unsize", unsize_trait;
275275
CopyTraitLangItem, "copy", copy_trait;
276276
SyncTraitLangItem, "sync", sync_trait;
277+
FreezeTraitLangItem, "freeze", freeze_trait;
277278

278279
DropTraitLangItem, "drop", drop_trait;
279280

src/librustc/ty/contents.rs

-255
This file was deleted.

src/librustc/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,6 @@ pub struct GlobalCtxt<'tcx> {
436436
// Internal cache for metadata decoding. No need to track deps on this.
437437
pub rcache: RefCell<FxHashMap<ty::CReaderCacheKey, Ty<'tcx>>>,
438438

439-
// Cache for the type-contents routine. FIXME -- track deps?
440-
pub tc_cache: RefCell<FxHashMap<Ty<'tcx>, ty::contents::TypeContents>>,
441-
442439
// FIXME dep tracking -- should be harmless enough
443440
pub normalized_cache: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,
444441

@@ -708,7 +705,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
708705
freevars: RefCell::new(resolutions.freevars),
709706
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
710707
rcache: RefCell::new(FxHashMap()),
711-
tc_cache: RefCell::new(FxHashMap()),
712708
normalized_cache: RefCell::new(FxHashMap()),
713709
inhabitedness_cache: RefCell::new(FxHashMap()),
714710
lang_items: lang_items,

0 commit comments

Comments
 (0)