Skip to content

Commit 976c0b3

Browse files
committed
Remove rust_call_tydesc_glue
Towards #4812. Also includes some minor cleanups.
1 parent 273f905 commit 976c0b3

File tree

6 files changed

+17
-82
lines changed

6 files changed

+17
-82
lines changed

src/libextra/arena.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,20 @@ use list::{MutList, MutCons, MutNil};
4141
use core::at_vec;
4242
use core::cast::{transmute, transmute_mut_region};
4343
use core::cast;
44-
use core::libc::size_t;
4544
use core::ptr;
4645
use core::sys;
4746
use core::uint;
4847
use core::vec;
4948
use core::unstable::intrinsics;
49+
use core::unstable::intrinsics::{TyDesc};
5050

51-
#[cfg(stage0)]
52-
use intrinsic::{get_tydesc, TyDesc};
5351
#[cfg(not(stage0))]
54-
use core::unstable::intrinsics::{get_tydesc, TyDesc};
55-
56-
pub mod rustrt {
57-
use core::libc::size_t;
58-
#[cfg(stage0)]
59-
use intrinsic::{TyDesc};
60-
#[cfg(not(stage0))]
61-
use core::unstable::intrinsics::{TyDesc};
62-
63-
pub extern {
64-
#[rust_stack]
65-
unsafe fn rust_call_tydesc_glue(root: *u8,
66-
tydesc: *TyDesc,
67-
field: size_t);
68-
}
69-
}
52+
use core::unstable::intrinsics::{get_tydesc};
7053

71-
// This probably belongs somewhere else. Needs to be kept in sync with
72-
// changes to glue...
73-
static tydesc_drop_glue_index: size_t = 3 as size_t;
54+
#[cfg(stage0)]
55+
unsafe fn get_tydesc<T>() -> *TyDesc {
56+
intrinsics::get_tydesc::<T>() as *TyDesc
57+
}
7458

7559
// The way arena uses arrays is really deeply awful. The arrays are
7660
// allocated, and have capacities reserved, but the fill for the array
@@ -150,8 +134,8 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
150134
//debug!("freeing object: idx = %u, size = %u, align = %u, done = %b",
151135
// start, size, align, is_done);
152136
if is_done {
153-
rustrt::rust_call_tydesc_glue(
154-
ptr::offset(buf, start), tydesc, tydesc_drop_glue_index);
137+
((*tydesc).drop_glue)(&tydesc as **TyDesc,
138+
ptr::offset(buf, start) as *i8);
155139
}
156140

157141
// Find where the next tydesc lives

src/libstd/cleanup.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,6 @@ fn debug_mem() -> bool {
158158
false
159159
}
160160

161-
#[cfg(stage0)]
162-
unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) {
163-
use sys::TypeDesc;
164-
165-
let tydesc: *TypeDesc = transmute(tydesc);
166-
let drop_glue: extern "Rust" fn(**TypeDesc, *i8) = transmute((*tydesc).drop_glue);
167-
drop_glue(to_unsafe_ptr(&tydesc), data);
168-
}
169-
170-
#[cfg(not(stage0))]
171-
unsafe fn call_drop_glue(tydesc: *::std::unstable::intrinsics::TyDesc, data: *i8) {
172-
((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data);
173-
}
174-
175161
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
176162
#[cfg(not(test))]
177163
#[lang="annihilate"]
@@ -213,7 +199,9 @@ pub unsafe fn annihilate() {
213199
// callback, as the original value may have been freed.
214200
for each_live_alloc(false) |box, uniq| {
215201
if !uniq {
216-
call_drop_glue((*box).header.type_desc, transmute(&(*box).data));
202+
let tydesc = (*box).header.type_desc;
203+
let data = transmute(&(*box).data);
204+
((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data);
217205
}
218206
}
219207

src/libstd/gc.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ with destructors.
4040
use cast;
4141
use container::{Map, Set};
4242
use io;
43-
use libc::{size_t, uintptr_t};
43+
use libc::{uintptr_t};
4444
use option::{None, Option, Some};
4545
use ptr;
4646
use hashmap::HashSet;
4747
use stackwalk::walk_stack;
4848
use sys;
49+
use unstable::intrinsics::{TyDesc};
4950

5051
pub use stackwalk::Word;
5152

@@ -58,17 +59,11 @@ pub struct StackSegment {
5859
}
5960

6061
pub mod rustrt {
61-
use libc::size_t;
6262
use stackwalk::Word;
6363
use super::StackSegment;
6464

6565
#[link_name = "rustrt"]
6666
pub extern {
67-
#[rust_stack]
68-
pub unsafe fn rust_call_tydesc_glue(root: *Word,
69-
tydesc: *Word,
70-
field: size_t);
71-
7267
#[rust_stack]
7368
pub unsafe fn rust_gc_metadata() -> *Word;
7469

@@ -125,7 +120,7 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
125120
return None;
126121
}
127122

128-
type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
123+
type Visitor<'self> = &'self fn(root: **Word, tydesc: *TyDesc) -> bool;
129124

130125
// Walks the list of roots for the given safe point, and calls visitor
131126
// on each root.
@@ -139,7 +134,7 @@ unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
139134
let stack_roots: *u32 = bump(sp_meta, 2);
140135
let reg_roots: *u8 = bump(stack_roots, num_stack_roots);
141136
let addrspaces: *Word = align_to_pointer(bump(reg_roots, num_reg_roots));
142-
let tydescs: ***Word = bump(addrspaces, num_stack_roots);
137+
let tydescs: ***TyDesc = bump(addrspaces, num_stack_roots);
143138

144139
// Stack roots
145140
let mut sri = 0;
@@ -364,7 +359,7 @@ pub fn cleanup_stack_for_failure() {
364359
// FIXME #4420: Destroy this box
365360
// FIXME #4330: Destroy this box
366361
} else {
367-
rustrt::rust_call_tydesc_glue(*root, tydesc, 3 as size_t);
362+
((*tydesc).drop_glue)(&tydesc as **TyDesc, *root as *i8);
368363
}
369364
}
370365
}

src/libstd/sys.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ use repr;
2222
use str;
2323
use unstable::intrinsics;
2424

25-
// Corresponds to runtime type_desc type
26-
#[cfg(stage0)]
27-
pub struct TypeDesc {
28-
size: uint,
29-
align: uint,
30-
take_glue: uint,
31-
drop_glue: uint,
32-
free_glue: uint
33-
// Remaining fields not listed
34-
}
35-
3625
/// The representation of a Rust closure
3726
pub struct Closure {
3827
code: *(),
@@ -50,18 +39,6 @@ pub mod rustrt {
5039
}
5140
}
5241

53-
/**
54-
* Returns a pointer to a type descriptor.
55-
*
56-
* Useful for calling certain function in the Rust runtime or otherwise
57-
* performing dark magick.
58-
*/
59-
#[inline]
60-
#[cfg(stage0)]
61-
pub fn get_type_desc<T>() -> *TypeDesc {
62-
unsafe { intrinsics::get_tydesc::<T>() as *TypeDesc }
63-
}
64-
6542
/// Returns the size of a type
6643
#[inline]
6744
pub fn size_of<T>() -> uint {

src/rt/rust_builtin.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,14 +729,6 @@ rust_task_deref(rust_task *task) {
729729
task->deref();
730730
}
731731

732-
// Must call on rust stack.
733-
extern "C" CDECL void
734-
rust_call_tydesc_glue(void *root, size_t *tydesc, size_t glue_index) {
735-
glue_fn *fn = (glue_fn*) tydesc[glue_index];
736-
if (fn)
737-
fn(0, 0, root);
738-
}
739-
740732
// Don't run on the Rust stack!
741733
extern "C" void
742734
rust_log_str(uint32_t level, const char *str, size_t size) {

src/rt/rustrt.def.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ rust_set_task_local_data
174174
rust_task_local_data_atexit
175175
rust_task_ref
176176
rust_task_deref
177-
rust_call_tydesc_glue
178177
tdefl_compress_mem_to_heap
179178
tinfl_decompress_mem_to_heap
180179
rust_gc_metadata
@@ -239,4 +238,4 @@ rust_valgrind_stack_deregister
239238
rust_take_env_lock
240239
rust_drop_env_lock
241240
rust_update_log_settings
242-
rust_running_on_valgrind
241+
rust_running_on_valgrind

0 commit comments

Comments
 (0)