Skip to content

Commit

Permalink
Remove unused TyDesc parameter from the glue functions
Browse files Browse the repository at this point in the history
To remove the environment pointer, support for function pointers without
an environment argument is needed (i.e. a fixed version of #6661).
  • Loading branch information
Blei committed Jun 23, 2013
1 parent 1b76bac commit e2f1049
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 37 deletions.
16 changes: 14 additions & 2 deletions src/libextra/arena.rs
Expand Up @@ -115,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 @@ -134,8 +147,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
//debug!("freeing object: idx = %u, size = %u, align = %u, done = %b",
// start, size, align, is_done);
if is_done {
((*tydesc).drop_glue)(&tydesc as **TyDesc,
ptr::offset(buf, start) as *i8);
call_drop_glue(tydesc, ptr::offset(buf, start) as *i8);
}

// Find where the next tydesc lives
Expand Down
13 changes: 0 additions & 13 deletions src/librustc/back/abi.rs
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 @@ -69,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"; }
14 changes: 4 additions & 10 deletions src/librustc/middle/trans/glue.rs
Expand Up @@ -232,7 +232,7 @@ pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext,
field: uint,
ti: @mut tydesc_info) {
let _icx = push_ctxt("lazily_emit_tydesc_glue");
let llfnty = type_of_glue_fn(ccx);
let llfnty = Type::glue_fn();

if lazily_emit_simplified_tydesc_glue(ccx, field, ti) {
return;
Expand Down Expand Up @@ -338,9 +338,7 @@ pub fn call_tydesc_glue_full(bcx: block,
}
};

Call(bcx, llfn, [C_null(Type::nil().ptr_to()),
C_null(bcx.ccx().tydesc_type.ptr_to().ptr_to()),
llrawptr]);
Call(bcx, llfn, [C_null(Type::nil().ptr_to()), llrawptr]);
}

// See [Note-arg-mode]
Expand Down Expand Up @@ -680,7 +678,7 @@ pub fn make_generic_glue_inner(ccx: @mut CrateContext,

let bcx = top_scope_block(fcx, None);
let lltop = bcx.llbb;
let rawptr0_arg = fcx.arg_pos(1u);
let rawptr0_arg = fcx.arg_pos(0u);
let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, rawptr0_arg as c_uint) };
let llty = type_of(ccx, t);
let llrawptr0 = PointerCast(bcx, llrawptr0, llty.ptr_to());
Expand Down Expand Up @@ -715,7 +713,7 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
let _icx = push_ctxt("emit_tydescs");
// As of this point, allow no more tydescs to be created.
ccx.finished_tydescs = true;
let glue_fn_ty = Type::generic_glue_fn(ccx);
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
let tyds = &mut ccx.tydescs;
for tyds.each_value |&val| {
let ti = val;
Expand Down Expand Up @@ -782,7 +780,3 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
}
};
}

pub fn type_of_glue_fn(ccx: &CrateContext) -> Type {
Type::glue_fn(ccx.tydesc_type)
}
11 changes: 4 additions & 7 deletions src/librustc/middle/trans/type_.rs
Expand Up @@ -20,7 +20,6 @@ use middle::trans::base;

use syntax::ast;
use syntax::abi::{Architecture, X86, X86_64, Arm, Mips};
use back::abi;

use core::vec;
use core::cast;
Expand Down Expand Up @@ -189,22 +188,20 @@ impl Type {
None => ()
}

let ty = Type::glue_fn(cx.tydesc_type).ptr_to();
let ty = Type::glue_fn();
cx.tn.associate_type("glue_fn", &ty);

return ty;
}

pub fn glue_fn(tydesc: Type) -> Type {
let tydescpp = tydesc.ptr_to().ptr_to();
Type::func([ Type::nil().ptr_to(), tydescpp, Type::i8p() ],
pub fn glue_fn() -> Type {
Type::func([ Type::nil().ptr_to(), Type::i8p() ],
&Type::void())
}

pub fn tydesc(arch: Architecture) -> Type {
let mut tydesc = Type::named_struct("tydesc");
let pvoid = Type::i8p();
let glue_fn_ty = Type::glue_fn(tydesc).ptr_to();
let glue_fn_ty = Type::glue_fn().ptr_to();

let int_ty = Type::int(arch);

Expand Down
18 changes: 16 additions & 2 deletions src/libstd/cleanup.rs
Expand Up @@ -11,9 +11,10 @@
#[doc(hidden)];

use libc::{c_char, intptr_t, uintptr_t};
use ptr::{mut_null, to_unsafe_ptr};
use ptr::{mut_null};
use repr::BoxRepr;
use cast::transmute;
use unstable::intrinsics::TyDesc;
#[cfg(not(test))] use unstable::lang::clear_task_borrow_list;

/**
Expand Down Expand Up @@ -158,6 +159,19 @@ fn debug_mem() -> bool {
false
}

#[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);
}

/// Destroys all managed memory (i.e. @ boxes) held by the current task.
#[cfg(not(test))]
#[lang="annihilate"]
Expand Down Expand Up @@ -201,7 +215,7 @@ pub unsafe fn annihilate() {
if !uniq {
let tydesc = (*box).header.type_desc;
let data = transmute(&(*box).data);
((*tydesc).drop_glue)(to_unsafe_ptr(&tydesc), data);
call_drop_glue(tydesc, data);
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/libstd/gc.rs
Expand Up @@ -316,6 +316,19 @@ fn expect_sentinel() -> bool { true }
#[cfg(nogc)]
fn expect_sentinel() -> bool { false }

#[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);
}

// Entry point for GC-based cleanup. Walks stack looking for exchange
// heap and stack allocations requiring drop, and runs all
// destructors.
Expand Down Expand Up @@ -359,7 +372,7 @@ pub fn cleanup_stack_for_failure() {
// FIXME #4420: Destroy this box
// FIXME #4330: Destroy this box
} else {
((*tydesc).drop_glue)(&tydesc as **TyDesc, *root as *i8);
call_drop_glue(tydesc, *root as *i8);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/unstable/intrinsics.rs
Expand Up @@ -36,6 +36,10 @@ A quick refresher on memory ordering:
#[cfg(test)]
pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};

#[cfg(not(stage0))]
pub type GlueFn = extern "Rust" fn(*i8);

#[cfg(stage0)]
pub type GlueFn = extern "Rust" fn(**TyDesc, *i8);

// NB: this has to be kept in sync with the Rust ABI.
Expand Down
6 changes: 5 additions & 1 deletion src/rt/rust_task.cpp
Expand Up @@ -183,7 +183,11 @@ void task_start_wrapper(spawn_args *a)
if(env) {
// free the environment (which should be a unique closure).
const type_desc *td = env->td;
td->drop_glue(NULL, NULL, box_body(env));
td->drop_glue(NULL,
#ifdef _RUST_STAGE0
NULL,
#endif
box_body(env));
task->kernel->region()->free(env);
}

Expand Down
6 changes: 5 additions & 1 deletion src/rt/rust_type.h
Expand Up @@ -25,7 +25,11 @@ typedef void (*CDECL spawn_fn)(rust_opaque_box*, void *);

struct type_desc;

typedef void CDECL (glue_fn)(void *, const type_desc **, void *);
typedef void CDECL (glue_fn)(void *,
#ifdef _RUST_STAGE0
const type_desc **,
#endif
void *);

// Corresponds to the boxed data in the @ region. The body follows the
// header; you can obtain a ptr via box_body() below.
Expand Down

0 comments on commit e2f1049

Please sign in to comment.