about summary refs log tree commit diff
path: root/src/libarena
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-03-15 04:01:57 +0200
committerEduard Burtescu <edy.burt@gmail.com>2015-03-17 21:00:23 +0200
commite256b7f049b44fa697b9f9c5e75b4433a7d9ffdf (patch)
tree05ed074d9080f696cb047c6df587ceef976f6897 /src/libarena
parent3e98ab560a56492d70932066bb4d46f3a6a1bd4c (diff)
downloadrust-e256b7f049b44fa697b9f9c5e75b4433a7d9ffdf.tar.gz
rust-e256b7f049b44fa697b9f9c5e75b4433a7d9ffdf.zip
Replace TyDesc and its uses with trait vtables and a type_name intrinsic.
Diffstat (limited to 'src/libarena')
-rw-r--r--src/libarena/lib.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs
index 029d9d03835..fb858344b85 100644
--- a/src/libarena/lib.rs
+++ b/src/libarena/lib.rs
@@ -42,8 +42,9 @@ extern crate alloc;
 
 use std::cell::{Cell, RefCell};
 use std::cmp;
-use std::intrinsics::{TyDesc, get_tydesc};
 use std::intrinsics;
+#[cfg(stage0)] // SNAP 270a677
+use std::intrinsics::{get_tydesc, TyDesc};
 use std::marker;
 use std::mem;
 #[cfg(stage0)]
@@ -186,6 +187,27 @@ fn un_bitpack_tydesc_ptr(p: usize) -> (*const TyDesc, bool) {
     ((p & !1) as *const TyDesc, p & 1 == 1)
 }
 
+// HACK(eddyb) TyDesc replacement using a trait object vtable.
+// This could be replaced in the future with a custom DST layout,
+// or `&'static (drop_glue, size, align)` created by a `const fn`.
+#[cfg(not(stage0))] // SNAP 270a677
+struct TyDesc {
+    drop_glue: fn(*const i8),
+    size: usize,
+    align: usize
+}
+
+#[cfg(not(stage0))] // SNAP 270a677
+unsafe fn get_tydesc<T>() -> *const TyDesc {
+    use std::raw::TraitObject;
+
+    let ptr = &*(1 as *const T);
+
+    // Can use any trait that is implemented for all types.
+    let obj = mem::transmute::<&marker::MarkerTrait, TraitObject>(ptr);
+    obj.vtable as *const TyDesc
+}
+
 impl<'longer_than_self> Arena<'longer_than_self> {
     fn chunk_size(&self) -> usize {
         self.copy_head.borrow().capacity()