Skip to content

Commit a8e3d4c

Browse files
committed
auto merge of #7254 : Blei/rust/intrinsic-overhaul, r=cmr
This sets the `get_tydesc()` return type correctly and removes the intrinsic module. See #3730, #3475. Update: this now also removes the unused shape fields in tydescs.
2 parents c6515ee + f8ae3cd commit a8e3d4c

35 files changed

+566
-655
lines changed

src/libextra/arena.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,21 @@ use list::{MutList, MutCons, MutNil};
4141
use core::at_vec;
4242
use core::cast::{transmute, transmute_mut, transmute_mut_region};
4343
use core::cast;
44-
use core::libc::size_t;
4544
use core::ptr;
46-
use core::sys::TypeDesc;
4745
use core::sys;
4846
use core::uint;
4947
use core::vec;
5048
use core::unstable::intrinsics;
49+
use core::unstable::intrinsics::{TyDesc};
5150

52-
pub mod rustrt {
53-
use core::libc::size_t;
54-
use core::sys::TypeDesc;
51+
#[cfg(not(stage0))]
52+
use core::unstable::intrinsics::{get_tydesc};
5553

56-
pub extern {
57-
#[rust_stack]
58-
unsafe fn rust_call_tydesc_glue(root: *u8,
59-
tydesc: *TypeDesc,
60-
field: size_t);
61-
}
54+
#[cfg(stage0)]
55+
unsafe fn get_tydesc<T>() -> *TyDesc {
56+
intrinsics::get_tydesc::<T>() as *TyDesc
6257
}
6358

64-
// This probably belongs somewhere else. Needs to be kept in sync with
65-
// changes to glue...
66-
static tydesc_drop_glue_index: size_t = 3 as size_t;
67-
6859
// The way arena uses arrays is really deeply awful. The arrays are
6960
// allocated, and have capacities reserved, but the fill for the array
7061
// will always stay at 0.
@@ -125,6 +116,19 @@ fn round_up_to(base: uint, align: uint) -> uint {
125116
(base + (align - 1)) & !(align - 1)
126117
}
127118

119+
#[inline]
120+
#[cfg(not(stage0))]
121+
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
122+
// This function should be inlined when stage0 is gone
123+
((*tydesc).drop_glue)(data);
124+
}
125+
126+
#[inline]
127+
#[cfg(stage0)]
128+
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
129+
((*tydesc).drop_glue)(0 as **TyDesc, data);
130+
}
131+
128132
// Walk down a chunk, running the destructors for any objects stored
129133
// in it.
130134
unsafe fn destroy_chunk(chunk: &Chunk) {
@@ -137,19 +141,18 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
137141
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
138142
let (size, align) = ((*tydesc).size, (*tydesc).align);
139143

140-
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
144+
let after_tydesc = idx + sys::size_of::<*TyDesc>();
141145

142146
let start = round_up_to(after_tydesc, align);
143147

144148
//debug!("freeing object: idx = %u, size = %u, align = %u, done = %b",
145149
// start, size, align, is_done);
146150
if is_done {
147-
rustrt::rust_call_tydesc_glue(
148-
ptr::offset(buf, start), tydesc, tydesc_drop_glue_index);
151+
call_drop_glue(tydesc, ptr::offset(buf, start) as *i8);
149152
}
150153

151154
// Find where the next tydesc lives
152-
idx = round_up_to(start + size, sys::pref_align_of::<*TypeDesc>());
155+
idx = round_up_to(start + size, sys::pref_align_of::<*TyDesc>());
153156
}
154157
}
155158

@@ -158,12 +161,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
158161
// is necessary in order to properly do cleanup if a failure occurs
159162
// during an initializer.
160163
#[inline]
161-
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
164+
unsafe fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint {
162165
let p_bits: uint = transmute(p);
163166
p_bits | (is_done as uint)
164167
}
165168
#[inline]
166-
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
169+
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
167170
(transmute(p & !1), p & 1 == 1)
168171
}
169172

@@ -203,7 +206,7 @@ impl Arena {
203206
#[inline]
204207
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
205208
unsafe {
206-
let tydesc = sys::get_type_desc::<T>();
209+
let tydesc = get_tydesc::<T>();
207210
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
208211
let ptr: *mut T = transmute(ptr);
209212
intrinsics::move_val_init(&mut (*ptr), op());
@@ -231,13 +234,13 @@ impl Arena {
231234
let head = transmute_mut_region(&mut self.head);
232235

233236
let tydesc_start = head.fill;
234-
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
237+
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
235238
let start = round_up_to(after_tydesc, align);
236239
let end = start + n_bytes;
237240
if end > at_vec::capacity(head.data) {
238241
return self.alloc_nonpod_grow(n_bytes, align);
239242
}
240-
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
243+
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());
241244

242245
//debug!("idx = %u, size = %u, align = %u, fill = %u",
243246
// start, n_bytes, align, head.fill);
@@ -250,7 +253,7 @@ impl Arena {
250253
#[inline]
251254
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
252255
unsafe {
253-
let tydesc = sys::get_type_desc::<T>();
256+
let tydesc = get_tydesc::<T>();
254257
let (ty_ptr, ptr) =
255258
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
256259
let ty_ptr: *mut uint = transmute(ty_ptr);

src/libextra/dbg.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,62 @@
1313
#[allow(missing_doc)];
1414

1515
use core::cast::transmute;
16-
use core::sys;
16+
#[cfg(stage0)]
17+
use intrinsic::{get_tydesc};
18+
#[cfg(not(stage0))]
19+
use core::unstable::intrinsics::{get_tydesc};
1720

1821
pub mod rustrt {
19-
use core::sys;
22+
#[cfg(stage0)]
23+
use intrinsic::{TyDesc};
24+
#[cfg(not(stage0))]
25+
use core::unstable::intrinsics::{TyDesc};
2026

2127
#[abi = "cdecl"]
2228
pub extern {
23-
pub unsafe fn debug_tydesc(td: *sys::TypeDesc);
24-
pub unsafe fn debug_opaque(td: *sys::TypeDesc, x: *());
25-
pub unsafe fn debug_box(td: *sys::TypeDesc, x: *());
26-
pub unsafe fn debug_tag(td: *sys::TypeDesc, x: *());
27-
pub unsafe fn debug_fn(td: *sys::TypeDesc, x: *());
28-
pub unsafe fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
29+
pub unsafe fn debug_tydesc(td: *TyDesc);
30+
pub unsafe fn debug_opaque(td: *TyDesc, x: *());
31+
pub unsafe fn debug_box(td: *TyDesc, x: *());
32+
pub unsafe fn debug_tag(td: *TyDesc, x: *());
33+
pub unsafe fn debug_fn(td: *TyDesc, x: *());
34+
pub unsafe fn debug_ptrcast(td: *TyDesc, x: *()) -> *();
2935
pub unsafe fn rust_dbg_breakpoint();
3036
}
3137
}
3238

3339
pub fn debug_tydesc<T>() {
3440
unsafe {
35-
rustrt::debug_tydesc(sys::get_type_desc::<T>());
41+
rustrt::debug_tydesc(get_tydesc::<T>());
3642
}
3743
}
3844

3945
pub fn debug_opaque<T>(x: T) {
4046
unsafe {
41-
rustrt::debug_opaque(sys::get_type_desc::<T>(), transmute(&x));
47+
rustrt::debug_opaque(get_tydesc::<T>(), transmute(&x));
4248
}
4349
}
4450

4551
pub fn debug_box<T>(x: @T) {
4652
unsafe {
47-
rustrt::debug_box(sys::get_type_desc::<T>(), transmute(&x));
53+
rustrt::debug_box(get_tydesc::<T>(), transmute(&x));
4854
}
4955
}
5056

5157
pub fn debug_tag<T>(x: T) {
5258
unsafe {
53-
rustrt::debug_tag(sys::get_type_desc::<T>(), transmute(&x));
59+
rustrt::debug_tag(get_tydesc::<T>(), transmute(&x));
5460
}
5561
}
5662

5763
pub fn debug_fn<T>(x: T) {
5864
unsafe {
59-
rustrt::debug_fn(sys::get_type_desc::<T>(), transmute(&x));
65+
rustrt::debug_fn(get_tydesc::<T>(), transmute(&x));
6066
}
6167
}
6268

6369
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
6470
transmute(
65-
rustrt::debug_ptrcast(sys::get_type_desc::<T>(), transmute(x)))
71+
rustrt::debug_ptrcast(get_tydesc::<T>(), transmute(x)))
6672
}
6773

6874
/// Triggers a debugger breakpoint

src/librustc/back/abi.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
12-
13-
1411
pub static rc_base_field_refcnt: uint = 0u;
1512

1613
pub static task_field_refcnt: uint = 0u;
@@ -49,9 +46,7 @@ pub static tydesc_field_take_glue: uint = 2u;
4946
pub static tydesc_field_drop_glue: uint = 3u;
5047
pub static tydesc_field_free_glue: uint = 4u;
5148
pub static tydesc_field_visit_glue: uint = 5u;
52-
pub static tydesc_field_shape: uint = 6u;
53-
pub static tydesc_field_shape_tables: uint = 7u;
54-
pub static n_tydesc_fields: uint = 8u;
49+
pub static n_tydesc_fields: uint = 6u;
5550

5651
// The two halves of a closure: code and environment.
5752
pub static fn_field_code: uint = 0u;
@@ -71,14 +66,4 @@ pub static vec_elt_elems: uint = 2u;
7166
pub static slice_elt_base: uint = 0u;
7267
pub static slice_elt_len: uint = 1u;
7368

74-
pub static worst_case_glue_call_args: uint = 7u;
75-
7669
pub static abi_version: uint = 1u;
77-
78-
pub fn memcpy_glue_name() -> ~str { return ~"rust_memcpy_glue"; }
79-
80-
pub fn bzero_glue_name() -> ~str { return ~"rust_bzero_glue"; }
81-
82-
pub fn yield_glue_name() -> ~str { return ~"rust_yield_glue"; }
83-
84-
pub fn no_op_type_glue_name() -> ~str { return ~"rust_no_op_type_glue"; }

src/librustc/driver/driver.rs

-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ pub fn compile_rest(sess: Session,
206206
let mut crate = crate_opt.unwrap();
207207

208208
let (llcx, llmod, link_meta) = {
209-
crate = time(time_passes, ~"intrinsic injection", ||
210-
front::intrinsic_inject::inject_intrinsic(sess, crate));
211-
212209
crate = time(time_passes, ~"extra injection", ||
213210
front::std_inject::maybe_inject_libstd_ref(sess, crate));
214211

src/librustc/front/intrinsic.rs

-140
This file was deleted.

0 commit comments

Comments
 (0)