use arena::TypedArena;
use std::c_str::ToCStr;
use std::cell::Cell;
-use std::libc::c_uint;
+use libc::c_uint;
use syntax::ast;
use syntax::parse::token;
let _icx = push_ctxt("trans_free");
callee::trans_lang_call(cx,
langcall(cx, None, "", FreeFnLangItem),
- [PointerCast(cx, v, Type::i8p())],
+ [PointerCast(cx, v, Type::i8p(cx.ccx()))],
Some(expr::Ignore)).bcx
}
let _icx = push_ctxt("trans_exchange_free");
callee::trans_lang_call(cx,
langcall(cx, None, "", ExchangeFreeFnLangItem),
- [PointerCast(cx, v, Type::i8p())],
+ [PointerCast(cx, v, Type::i8p(cx.ccx()))],
Some(expr::Ignore)).bcx
}
}
fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t {
- let tcx = ccx.tcx;
+ let tcx = ccx.tcx();
if !ty::type_needs_drop(tcx, t) {
return ty::mk_i8();
}
}
}
- ty::ty_vec(mt, ty::vstore_uniq) if !ty::type_needs_drop(tcx, mt.ty) =>
+ ty::ty_vec(ty, ty::VstoreUniq) if !ty::type_needs_drop(tcx, ty) =>
ty::mk_uniq(tcx, ty::mk_i8()),
_ => t
drop_ty(bcx, vp, t)
}
-pub fn get_drop_glue(ccx: @CrateContext, t: ty::t) -> ValueRef {
+pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
let t = get_drop_glue_type(ccx, t);
- {
- let drop_glues = ccx.drop_glues.borrow();
- match drop_glues.get().find(&t) {
- Some(&glue) => return glue,
- _ => { }
- }
+ match ccx.drop_glues.borrow().find(&t) {
+ Some(&glue) => return glue,
+ _ => { }
}
- let llfnty = Type::glue_fn(type_of(ccx, t).ptr_to());
+ let llfnty = Type::glue_fn(ccx, type_of(ccx, t).ptr_to());
let glue = declare_generic_glue(ccx, t, llfnty, "drop");
- {
- let mut drop_glues = ccx.drop_glues.borrow_mut();
- drop_glues.get().insert(t, glue);
- }
+ ccx.drop_glues.borrow_mut().insert(t, glue);
make_generic_glue(ccx, t, glue, make_drop_glue, "drop");
glue
}
-pub fn lazily_emit_visit_glue(ccx: @CrateContext, ti: @tydesc_info) {
+pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: @tydesc_info) {
let _icx = push_ctxt("lazily_emit_visit_glue");
- let llfnty = Type::glue_fn(type_of(ccx, ti.ty).ptr_to());
+ let llfnty = Type::glue_fn(ccx, type_of(ccx, ti.ty).ptr_to());
match ti.visit_glue.get() {
Some(_) => (),
None => {
- debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx, ti.ty));
+ debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
let glue_fn = declare_generic_glue(ccx, ti.ty, llfnty, "visit");
ti.visit_glue.set(Some(glue_fn));
make_generic_glue(ccx, ti.ty, glue_fn, make_visit_glue, "visit");
- debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx, ti.ty));
+ debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
}
}
}
let ccx = bcx.ccx();
// NB: Don't short-circuit even if this block is unreachable because
// GC-based cleanup needs to the see that the roots are live.
- if bcx.unreachable.get() && !ccx.sess.no_landing_pads() { return; }
+ if bcx.unreachable.get() && !ccx.sess().no_landing_pads() { return; }
let static_glue_fn = match static_ti {
None => None,
// When static type info is available, avoid casting to a generic pointer.
let llrawptr = if static_glue_fn.is_none() {
- PointerCast(bcx, v, Type::i8p())
+ PointerCast(bcx, v, Type::i8p(ccx))
} else {
v
};
fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'a> {
// NB: v0 is an *alias* of type t here, not a direct value.
let _icx = push_ctxt("make_drop_glue");
- let ccx = bcx.ccx();
match ty::get(t).sty {
ty::ty_box(body_ty) => {
decr_refcnt_maybe_free(bcx, v0, body_ty)
trans_exchange_free(bcx, llbox)
})
}
- ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) => {
- make_drop_glue(bcx, v0, tvec::expand_boxed_vec_ty(bcx.tcx(), t))
- }
- ty::ty_unboxed_vec(_) => {
- tvec::make_drop_glue_unboxed(bcx, v0, t)
+ ty::ty_vec(_, ty::VstoreUniq) | ty::ty_str(ty::VstoreUniq) => {
+ let llbox = Load(bcx, v0);
+ let not_null = IsNotNull(bcx, llbox);
+ with_cond(bcx, not_null, |bcx| {
+ let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
+ let bcx = tvec::make_drop_glue_unboxed(bcx, llbox, unit_ty);
+ trans_exchange_free(bcx, llbox)
+ })
}
ty::ty_struct(did, ref substs) => {
let tcx = bcx.tcx();
}
}
}
- ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => {
+ ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
// Only drop the value when it is non-null
with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| {
let dtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
let dtor = Load(bcx, dtor_ptr);
- Call(bcx, dtor, [PointerCast(bcx, lluniquevalue, Type::i8p())], []);
+ Call(bcx, dtor, [PointerCast(bcx, lluniquevalue, Type::i8p(bcx.ccx()))], []);
bcx
})
}
- ty::ty_closure(ref f) if f.sigil == ast::OwnedSigil => {
+ ty::ty_closure(ref f) if f.store == ty::UniqTraitStore => {
let box_cell_v = GEPi(bcx, v0, [0u, abi::fn_field_box]);
let env = Load(bcx, box_cell_v);
- let env_ptr_ty = Type::at_box(ccx, Type::i8()).ptr_to();
+ let env_ptr_ty = Type::at_box(bcx.ccx(), Type::i8(bcx.ccx())).ptr_to();
let env = PointerCast(bcx, env, env_ptr_ty);
with_cond(bcx, IsNotNull(bcx, env), |bcx| {
let dtor_ptr = GEPi(bcx, env, [0u, abi::box_field_tydesc]);
let dtor = Load(bcx, dtor_ptr);
let cdata = GEPi(bcx, env, [0u, abi::box_field_body]);
- Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p())], []);
+ Call(bcx, dtor, [PointerCast(bcx, cdata, Type::i8p(bcx.ccx()))], []);
// Free the environment itself
trans_exchange_free(bcx, env)
})
}
_ => {
- if ty::type_needs_drop(ccx.tcx, t) &&
+ if ty::type_needs_drop(bcx.tcx(), t) &&
ty::type_is_structural(t) {
iter_structural_ty(bcx, v0, t, drop_ty)
} else {
let llty = type_of(ccx, t);
- if ccx.sess.count_type_sizes() {
+ if ccx.sess().count_type_sizes() {
println!("{}\t{}", llsize_of_real(ccx, llty),
- ppaux::ty_to_str(ccx.tcx, t));
+ ppaux::ty_to_str(ccx.tcx(), t));
}
let llsize = llsize_of(ccx, llty);
let llalign = llalign_of(ccx, llty);
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc");
- debug!("+++ declare_tydesc {} {}", ppaux::ty_to_str(ccx.tcx, t), name);
+ debug!("+++ declare_tydesc {} {}", ppaux::ty_to_str(ccx.tcx(), t), name);
let gvar = name.with_c_str(|buf| {
unsafe {
- llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
+ llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type().to_ref(), buf)
}
});
note_unique_llvm_symbol(ccx, name);
- let ty_name = token::intern_and_get_ident(ppaux::ty_to_str(ccx.tcx, t));
+ let ty_name = token::intern_and_get_ident(ppaux::ty_to_str(ccx.tcx(), t));
let ty_name = C_str_slice(ccx, ty_name);
let inf = @tydesc_info {
name: ty_name,
visit_glue: Cell::new(None),
};
- debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx, t));
+ debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx(), t));
return inf;
}
fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
name: &str) -> ValueRef {
let _icx = push_ctxt("declare_generic_glue");
- let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, ~"glue_" + name);
- debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
+ let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "glue_".to_owned() + name);
+ debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty, ty::mk_nil());
note_unique_llvm_symbol(ccx, fn_nm);
return llfn;
}
-fn make_generic_glue(ccx: @CrateContext,
+fn make_generic_glue(ccx: &CrateContext,
t: ty::t,
llfn: ValueRef,
helper: <'a> |&'a Block<'a>, ValueRef, ty::t|
name: &str)
-> ValueRef {
let _icx = push_ctxt("make_generic_glue");
- let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx, t));
+ let glue_name = format!("glue {} {}", name, ty_to_short_str(ccx.tcx(), t));
let _s = StatRecorder::new(ccx, glue_name);
let arena = TypedArena::new();
// llfn is expected be declared to take a parameter of the appropriate
// type, so we don't need to explicitly cast the function parameter.
- let bcx = fcx.entry_bcx.get().unwrap();
+ let bcx = fcx.entry_bcx.borrow().clone().unwrap();
let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, fcx.arg_pos(0) as c_uint) };
let bcx = helper(bcx, llrawptr0, t);
finish_fn(&fcx, bcx);
llfn
}
-pub fn emit_tydescs(ccx: @CrateContext) {
+pub fn emit_tydescs(ccx: &CrateContext) {
let _icx = push_ctxt("emit_tydescs");
// As of this point, allow no more tydescs to be created.
ccx.finished_tydescs.set(true);
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
- let mut tyds = ccx.tydescs.borrow_mut();
- for (_, &val) in tyds.get().iter() {
+ for (_, &val) in ccx.tydescs.borrow().iter() {
let ti = val;
// Each of the glue functions needs to be cast to a generic type
}
};
- let tydesc = C_named_struct(ccx.tydesc_type,
+ let tydesc = C_named_struct(ccx.tydesc_type(),
[ti.size, // size
ti.align, // align
drop_glue, // drop_glue