Skip to content

Commit

Permalink
librustc: Stop generating visit glue and remove from TyDesc.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Oct 16, 2014
1 parent 7a4122a commit 7210a5a
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 97 deletions.
1 change: 1 addition & 0 deletions src/libcore/intrinsics.rs
Expand Up @@ -58,6 +58,7 @@ pub struct TyDesc {
pub drop_glue: GlueFn,

// Called by reflection visitor to visit a value of type `T`
#[cfg(stage0)]
pub visit_glue: GlueFn,

// Name corresponding to the type
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/trans/common.rs
Expand Up @@ -130,7 +130,6 @@ pub struct tydesc_info {
pub size: ValueRef,
pub align: ValueRef,
pub name: ValueRef,
pub visit_glue: Cell<Option<ValueRef>>,
}

/*
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/middle/trans/context.rs
Expand Up @@ -72,7 +72,6 @@ pub struct SharedCrateContext<'tcx> {

available_monomorphizations: RefCell<HashSet<String>>,
available_drop_glues: RefCell<HashMap<ty::t, String>>,
available_visit_glues: RefCell<HashMap<ty::t, String>>,
}

/// The local portion of a `CrateContext`. There is one `LocalCrateContext`
Expand Down Expand Up @@ -275,7 +274,6 @@ impl<'tcx> SharedCrateContext<'tcx> {
},
available_monomorphizations: RefCell::new(HashSet::new()),
available_drop_glues: RefCell::new(HashMap::new()),
available_visit_glues: RefCell::new(HashMap::new()),
};

for i in range(0, local_count) {
Expand Down Expand Up @@ -682,10 +680,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
&self.shared.available_drop_glues
}

pub fn available_visit_glues<'a>(&'a self) -> &'a RefCell<HashMap<ty::t, String>> {
&self.shared.available_visit_glues
}

pub fn int_type(&self) -> Type {
self.local.int_type
}
Expand Down
84 changes: 0 additions & 84 deletions src/librustc/middle/trans/glue.rs
Expand Up @@ -31,7 +31,6 @@ use middle::trans::datum;
use middle::trans::debuginfo;
use middle::trans::expr;
use middle::trans::machine::*;
use middle::trans::reflect;
use middle::trans::tvec;
use middle::trans::type_::Type;
use middle::trans::type_of::{type_of, sizing_type_of, align_of};
Expand All @@ -41,7 +40,6 @@ use util::ppaux;

use arena::TypedArena;
use std::c_str::ToCStr;
use std::cell::Cell;
use libc::c_uint;
use syntax::ast;
use syntax::parse::token;
Expand Down Expand Up @@ -186,71 +184,6 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
glue
}

pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: &tydesc_info) -> ValueRef {
let _icx = push_ctxt("lazily_emit_visit_glue");

let llfnty = Type::glue_fn(ccx, type_of(ccx, ti.ty).ptr_to());

match ti.visit_glue.get() {
Some(visit_glue) => visit_glue,
None => {
debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_string(ccx.tcx(), ti.ty));

let (glue_fn, new_sym) = match ccx.available_visit_glues().borrow().find(&ti.ty) {
Some(old_sym) => {
let glue_fn = decl_cdecl_fn(ccx, old_sym.as_slice(), llfnty, ty::mk_nil());
(glue_fn, None)
},
None => {
let (sym, glue_fn) = declare_generic_glue(ccx, ti.ty, llfnty, "visit");
(glue_fn, Some(sym))
},
};

ti.visit_glue.set(Some(glue_fn));

match new_sym {
Some(sym) => {
ccx.available_visit_glues().borrow_mut().insert(ti.ty, sym);
make_generic_glue(ccx, ti.ty, glue_fn, make_visit_glue, "visit");
},
None => {},
}

debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_string(ccx.tcx(), ti.ty));
glue_fn
}
}
}

// See [Note-arg-mode]
pub fn call_visit_glue(bcx: Block, v: ValueRef, tydesc: ValueRef) {
let _icx = push_ctxt("call_visit_glue");

// Select the glue function to call from the tydesc
let llfn = Load(bcx, GEPi(bcx, tydesc, [0u, abi::tydesc_field_visit_glue]));
let llrawptr = PointerCast(bcx, v, Type::i8p(bcx.ccx()));

Call(bcx, llfn, [llrawptr], None);
}

fn make_visit_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, t: ty::t)
-> Block<'blk, 'tcx> {
let _icx = push_ctxt("make_visit_glue");
let mut bcx = bcx;
let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(),
ty::ReStatic,
ty::ReStatic) {
Ok(pair) => pair,
Err(s) => {
bcx.tcx().sess.fatal(s.as_slice());
}
};
let v = PointerCast(bcx, v, type_of(bcx.ccx(), object_ty).ptr_to());
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, visitor_trait.def_id);
bcx
}

fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
t: ty::t,
v0: ValueRef,
Expand Down Expand Up @@ -577,7 +510,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info {
size: llsize,
align: llalign,
name: ty_name,
visit_glue: Cell::new(None),
}
}

Expand Down Expand Up @@ -643,27 +575,11 @@ pub fn emit_tydescs(ccx: &CrateContext) {
llvm::LLVMConstPointerCast(get_drop_glue(ccx, ti.ty), glue_fn_ty.to_ref())
};
ccx.stats().n_real_glues.set(ccx.stats().n_real_glues.get() + 1);
let visit_glue =
match ti.visit_glue.get() {
None => {
ccx.stats().n_null_glues.set(ccx.stats().n_null_glues.get() +
1u);
C_null(glue_fn_ty)
}
Some(v) => {
unsafe {
ccx.stats().n_real_glues.set(ccx.stats().n_real_glues.get() +
1);
llvm::LLVMConstPointerCast(v, glue_fn_ty.to_ref())
}
}
};

let tydesc = C_named_struct(ccx.tydesc_type(),
[ti.size, // size
ti.align, // align
drop_glue, // drop_glue
visit_glue, // visit_glue
ti.name]); // name

unsafe {
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/trans/intrinsic.rs
Expand Up @@ -269,7 +269,6 @@ pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::N
(_, "get_tydesc") => {
let tp_ty = *substs.types.get(FnSpace, 0);
let static_ti = get_tydesc(ccx, tp_ty);
glue::lazily_emit_visit_glue(ccx, &*static_ti);

// FIXME (#3730): ideally this shouldn't need a cast,
// but there's a circularity between translating rust types to llvm
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/trans/reflect.rs
Expand Up @@ -17,7 +17,6 @@ use middle::trans::callee::ArgVals;
use middle::trans::callee;
use middle::trans::common::*;
use middle::trans::datum::*;
use middle::trans::glue;
use middle::trans::machine;
use middle::trans::meth;
use middle::trans::type_::Type;
Expand Down Expand Up @@ -74,7 +73,6 @@ impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> {
pub fn c_tydesc(&mut self, t: ty::t) -> ValueRef {
let bcx = self.bcx;
let static_ti = get_tydesc(bcx.ccx(), t);
glue::lazily_emit_visit_glue(bcx.ccx(), &*static_ti);
PointerCast(bcx, static_ti.tydesc, self.tydesc_ty.ptr_to())
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/trans/type_.rs
Expand Up @@ -197,7 +197,6 @@ impl Type {
let elems = [int_ty, // size
int_ty, // align
glue_fn_ty, // drop
glue_fn_ty, // visit
str_slice_ty]; // name
tydesc.set_struct_body(elems, false);

Expand Down
2 changes: 0 additions & 2 deletions src/librustc_back/abi.rs
Expand Up @@ -14,8 +14,6 @@ pub const box_field_refcnt: uint = 0u;
pub const box_field_drop_glue: uint = 1u;
pub const box_field_body: uint = 4u;

pub const tydesc_field_visit_glue: uint = 3u;

// The two halves of a closure: code and environment.
pub const fn_field_code: uint = 0u;
pub const fn_field_box: uint = 1u;
Expand Down

0 comments on commit 7210a5a

Please sign in to comment.