Update type visitor to use &Visitor and not @Visitor

This commit is contained in:
Niko Matsakis 2013-08-11 13:58:01 -04:00
parent 66b8ad5867
commit df016dc4bf
6 changed files with 37 additions and 12 deletions

View File

@ -348,7 +348,8 @@ pub fn make_visit_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
let _icx = push_ctxt("make_visit_glue");
do with_scope(bcx, None, "visitor cleanup") |bcx| {
let mut bcx = bcx;
let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx()){
let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(),
ty::re_static) {
Ok(pair) => pair,
Err(s) => {
bcx.tcx().sess.fatal(s);

View File

@ -100,17 +100,13 @@ pub fn visit(&mut self, ty_name: &str, args: &[ValueRef]) {
debug!("arg %u: %s", i, bcx.val_to_str(*a));
}
let bool_ty = ty::mk_bool();
// XXX: Should not be BoxTraitStore!
let result = unpack_result!(bcx, callee::trans_call_inner(
self.bcx, None, mth_ty, bool_ty,
|bcx| meth::trans_trait_callee_from_llval(bcx,
mth_ty,
mth_idx,
v,
ty::BoxTraitStore,
ast::sty_region(
None,
ast::m_imm)),
None),
ArgVals(args), None, DontAutorefArg));
let result = bool_to_i1(bcx, result);
let next_bcx = sub_block(bcx, "next");

View File

@ -4487,7 +4487,8 @@ pub fn get_opaque_ty(tcx: ctxt) -> Result<t, ~str> {
}
}
pub fn visitor_object_ty(tcx: ctxt) -> Result<(@TraitRef, t), ~str> {
pub fn visitor_object_ty(tcx: ctxt,
region: ty::Region) -> Result<(@TraitRef, t), ~str> {
let trait_lang_item = match tcx.lang_items.require(TyVisitorTraitLangItem) {
Ok(id) => id,
Err(s) => { return Err(s); }
@ -4498,13 +4499,11 @@ pub fn visitor_object_ty(tcx: ctxt) -> Result<(@TraitRef, t), ~str> {
tps: ~[]
};
let trait_ref = @TraitRef { def_id: trait_lang_item, substs: substs };
let mut static_trait_bound = EmptyBuiltinBounds();
static_trait_bound.add(BoundStatic);
Ok((trait_ref,
mk_trait(tcx,
trait_ref.def_id,
trait_ref.substs.clone(),
BoxTraitStore,
RegionTraitStore(region),
ast::m_imm,
static_trait_bound)))
EmptyBuiltinBounds())))
}

View File

@ -3437,7 +3437,8 @@ fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t {
Ok(t) => t,
Err(s) => { tcx.sess.span_fatal(it.span, s); }
};
let visitor_object_ty = match ty::visitor_object_ty(tcx) {
let region = ty::re_bound(ty::br_anon(0));
let visitor_object_ty = match ty::visitor_object_ty(tcx, region) {
Ok((_, vot)) => vot,
Err(s) => { tcx.sess.span_fatal(it.span, s); }
};

View File

@ -158,6 +158,7 @@ pub fn visit_inner(&self, inner: *TyDesc) -> bool {
}
#[inline]
#[cfg(stage0)]
pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
unsafe {
let u = ReprVisitor(ptr, self.writer);
@ -167,6 +168,17 @@ pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
}
}
#[inline]
#[cfg(not(stage0))]
pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
unsafe {
let u = ReprVisitor(ptr, self.writer);
let v = reflect::MovePtrAdaptor(u);
visit_tydesc(inner, &v as &TyVisitor);
true
}
}
#[inline]
pub fn write<T:Repr>(&self) -> bool {
do self.get |v:&T| {
@ -556,6 +568,7 @@ fn visit_opaque_box(&self) -> bool {
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
}
#[cfg(stage0)]
pub fn write_repr<T>(writer: @Writer, object: &T) {
unsafe {
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
@ -566,6 +579,17 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
}
}
#[cfg(not(stage0))]
pub fn write_repr<T>(writer: @Writer, object: &T) {
unsafe {
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
let tydesc = get_tydesc::<T>();
let u = ReprVisitor(ptr, writer);
let v = reflect::MovePtrAdaptor(u);
visit_tydesc(tydesc, &v as &TyVisitor)
}
}
#[cfg(test)]
struct P {a: int, b: float}

View File

@ -328,8 +328,12 @@ fn visit_leave_fn(&self, purity: uint, proto: uint,
/// Returns `true` if a type is managed (will be allocated on the local heap)
pub fn contains_managed<T>() -> bool;
#[cfg(stage0)]
pub fn visit_tydesc(td: *TyDesc, tv: @TyVisitor);
#[cfg(not(stage0))]
pub fn visit_tydesc(td: *TyDesc, tv: &TyVisitor);
pub fn frame_address(f: &once fn(*u8));
/// Get the address of the `__morestack` stack growth function.