Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intrinsic overhaul #7254

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,21 @@ use list::{MutList, MutCons, MutNil};
use core::at_vec;
use core::cast::{transmute, transmute_mut_region};
use core::cast;
use core::libc::size_t;
use core::ptr;
use core::sys::TypeDesc;
use core::sys;
use core::uint;
use core::vec;
use core::unstable::intrinsics;
use core::unstable::intrinsics::{TyDesc};

pub mod rustrt {
use core::libc::size_t;
use core::sys::TypeDesc;
#[cfg(not(stage0))]
use core::unstable::intrinsics::{get_tydesc};

pub extern {
#[rust_stack]
unsafe fn rust_call_tydesc_glue(root: *u8,
tydesc: *TypeDesc,
field: size_t);
}
#[cfg(stage0)]
unsafe fn get_tydesc<T>() -> *TyDesc {
intrinsics::get_tydesc::<T>() as *TyDesc
}

// This probably belongs somewhere else. Needs to be kept in sync with
// changes to glue...
static tydesc_drop_glue_index: size_t = 3 as size_t;

// The way arena uses arrays is really deeply awful. The arrays are
// allocated, and have capacities reserved, but the fill for the array
// will always stay at 0.
Expand Down Expand Up @@ -124,6 +115,19 @@ fn round_up_to(base: uint, align: uint) -> uint {
(base + (align - 1)) & !(align - 1)
}

#[inline]
#[cfg(not(stage0))]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
// This function should be inlined when stage0 is gone
((*tydesc).drop_glue)(data);
}

#[inline]
#[cfg(stage0)]
unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
((*tydesc).drop_glue)(0 as **TyDesc, data);
}

// Walk down a chunk, running the destructors for any objects stored
// in it.
unsafe fn destroy_chunk(chunk: &Chunk) {
Expand All @@ -136,19 +140,18 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
let (size, align) = ((*tydesc).size, (*tydesc).align);

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

let start = round_up_to(after_tydesc, align);

//debug!("freeing object: idx = %u, size = %u, align = %u, done = %b",
// start, size, align, is_done);
if is_done {
rustrt::rust_call_tydesc_glue(
ptr::offset(buf, start), tydesc, tydesc_drop_glue_index);
call_drop_glue(tydesc, ptr::offset(buf, start) as *i8);
}

// Find where the next tydesc lives
idx = round_up_to(start + size, sys::pref_align_of::<*TypeDesc>());
idx = round_up_to(start + size, sys::pref_align_of::<*TyDesc>());
}
}

Expand All @@ -157,12 +160,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
// is necessary in order to properly do cleanup if a failure occurs
// during an initializer.
#[inline]
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
unsafe fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint {
let p_bits: uint = transmute(p);
p_bits | (is_done as uint)
}
#[inline]
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
(transmute(p & !1), p & 1 == 1)
}

Expand Down Expand Up @@ -202,7 +205,7 @@ impl Arena {
#[inline]
fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let tydesc = get_tydesc::<T>();
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
let ptr: *mut T = transmute(ptr);
intrinsics::move_val_init(&mut (*ptr), op());
Expand Down Expand Up @@ -230,13 +233,13 @@ impl Arena {
let head = transmute_mut_region(&mut self.head);

let tydesc_start = head.fill;
let after_tydesc = head.fill + sys::size_of::<*TypeDesc>();
let after_tydesc = head.fill + sys::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align);
let end = start + n_bytes;
if end > at_vec::capacity(head.data) {
return self.alloc_nonpod_grow(n_bytes, align);
}
head.fill = round_up_to(end, sys::pref_align_of::<*TypeDesc>());
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>());

//debug!("idx = %u, size = %u, align = %u, fill = %u",
// start, n_bytes, align, head.fill);
Expand All @@ -249,7 +252,7 @@ impl Arena {
#[inline]
fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
unsafe {
let tydesc = sys::get_type_desc::<T>();
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
let ty_ptr: *mut uint = transmute(ty_ptr);
Expand Down
34 changes: 20 additions & 14 deletions src/libextra/dbg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,62 @@
#[allow(missing_doc)];

use core::cast::transmute;
use core::sys;
#[cfg(stage0)]
use intrinsic::{get_tydesc};
#[cfg(not(stage0))]
use core::unstable::intrinsics::{get_tydesc};

pub mod rustrt {
use core::sys;
#[cfg(stage0)]
use intrinsic::{TyDesc};
#[cfg(not(stage0))]
use core::unstable::intrinsics::{TyDesc};

#[abi = "cdecl"]
pub extern {
pub unsafe fn debug_tydesc(td: *sys::TypeDesc);
pub unsafe fn debug_opaque(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_box(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_tag(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_fn(td: *sys::TypeDesc, x: *());
pub unsafe fn debug_ptrcast(td: *sys::TypeDesc, x: *()) -> *();
pub unsafe fn debug_tydesc(td: *TyDesc);
pub unsafe fn debug_opaque(td: *TyDesc, x: *());
pub unsafe fn debug_box(td: *TyDesc, x: *());
pub unsafe fn debug_tag(td: *TyDesc, x: *());
pub unsafe fn debug_fn(td: *TyDesc, x: *());
pub unsafe fn debug_ptrcast(td: *TyDesc, x: *()) -> *();
pub unsafe fn rust_dbg_breakpoint();
}
}

pub fn debug_tydesc<T>() {
unsafe {
rustrt::debug_tydesc(sys::get_type_desc::<T>());
rustrt::debug_tydesc(get_tydesc::<T>());
}
}

pub fn debug_opaque<T>(x: T) {
unsafe {
rustrt::debug_opaque(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_opaque(get_tydesc::<T>(), transmute(&x));
}
}

pub fn debug_box<T>(x: @T) {
unsafe {
rustrt::debug_box(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_box(get_tydesc::<T>(), transmute(&x));
}
}

pub fn debug_tag<T>(x: T) {
unsafe {
rustrt::debug_tag(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_tag(get_tydesc::<T>(), transmute(&x));
}
}

pub fn debug_fn<T>(x: T) {
unsafe {
rustrt::debug_fn(sys::get_type_desc::<T>(), transmute(&x));
rustrt::debug_fn(get_tydesc::<T>(), transmute(&x));
}
}

pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
transmute(
rustrt::debug_ptrcast(sys::get_type_desc::<T>(), transmute(x)))
rustrt::debug_ptrcast(get_tydesc::<T>(), transmute(x)))
}

/// Triggers a debugger breakpoint
Expand Down
17 changes: 1 addition & 16 deletions src/librustc/back/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.




pub static rc_base_field_refcnt: uint = 0u;

pub static task_field_refcnt: uint = 0u;
Expand Down Expand Up @@ -49,9 +46,7 @@ pub static tydesc_field_take_glue: uint = 2u;
pub static tydesc_field_drop_glue: uint = 3u;
pub static tydesc_field_free_glue: uint = 4u;
pub static tydesc_field_visit_glue: uint = 5u;
pub static tydesc_field_shape: uint = 6u;
pub static tydesc_field_shape_tables: uint = 7u;
pub static n_tydesc_fields: uint = 8u;
pub static n_tydesc_fields: uint = 6u;

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

pub static worst_case_glue_call_args: uint = 7u;

pub static abi_version: uint = 1u;

pub fn memcpy_glue_name() -> ~str { return ~"rust_memcpy_glue"; }

pub fn bzero_glue_name() -> ~str { return ~"rust_bzero_glue"; }

pub fn yield_glue_name() -> ~str { return ~"rust_yield_glue"; }

pub fn no_op_type_glue_name() -> ~str { return ~"rust_no_op_type_glue"; }
3 changes: 0 additions & 3 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ pub fn compile_rest(sess: Session,
let mut crate = crate_opt.unwrap();

let (llcx, llmod, link_meta) = {
crate = time(time_passes, ~"intrinsic injection", ||
front::intrinsic_inject::inject_intrinsic(sess, crate));

crate = time(time_passes, ~"extra injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));

Expand Down
140 changes: 0 additions & 140 deletions src/librustc/front/intrinsic.rs

This file was deleted.

Loading