These variants occur rarely but inflate the whole enum for the other variants, leaving a lot of wasted space. In total this reduces `ty::sty` from 160 bytes to 96 (on a 64-bit platform).
After this, `ty_struct` and `ty_enum` are the largest variants, with the 80-byte `substs` being the major contributor.
enc_substs(w, cx, substs);
mywrite!(w, "]");
}
- ty::ty_trait(def, ref substs, store, mt, bounds) => {
- mywrite!(w, "x[{}|", (cx.ds)(def));
+ ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, mutability, bounds }) => {
+ mywrite!(w, "x[{}|", (cx.ds)(def_id));
enc_substs(w, cx, substs);
enc_trait_store(w, cx, store);
- enc_mutability(w, mt);
+ enc_mutability(w, mutability);
let bounds = ty::ParamBounds {builtin_bounds: bounds,
trait_bounds: Vec::new()};
enc_bounds(w, cx, &bounds);
ty::ty_unboxed_vec(mt) => { mywrite!(w, "U"); enc_mt(w, cx, mt); }
ty::ty_closure(ref f) => {
mywrite!(w, "f");
- enc_closure_ty(w, cx, f);
+ enc_closure_ty(w, cx, *f);
}
ty::ty_bare_fn(ref f) => {
mywrite!(w, "F");
let fty = ty::node_id_to_type(cx.tcx, id);
match ty::get(fty).sty {
- ty::ty_closure(ty::ClosureTy {
+ ty::ty_closure(~ty::ClosureTy {
sigil: OwnedSigil,
bounds: bounds,
..
}) => {
b(|cx, fv| check_for_uniq(cx, fv, bounds))
}
- ty::ty_closure(ty::ClosureTy {
+ ty::ty_closure(~ty::ClosureTy {
sigil: ManagedSigil,
..
}) => {
// can't happen
fail!("internal error: saw closure with managed sigil (@fn)");
}
- ty::ty_closure(ty::ClosureTy {
+ ty::ty_closure(~ty::ClosureTy {
sigil: BorrowedSigil,
bounds: bounds,
region: region,
fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span: Span) {
check_cast_for_escaping_regions(cx, source_ty, target_ty, span);
match ty::get(target_ty).sty {
- ty::ty_trait(_, _, _, _, bounds) => {
+ ty::ty_trait(~ty::TyTrait { bounds, .. }) => {
check_trait_cast_bounds(cx, span, source_ty, bounds);
}
_ => {}
}
ty::ty_uniq(_) | ty::ty_str(ty::vstore_uniq) |
ty::ty_vec(_, ty::vstore_uniq) |
- ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => {
+ ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) => {
n_uniq += 1;
}
ty::ty_closure(ref c) if c.sigil == ast::OwnedSigil => {
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
match ty::get(t).sty {
ty::ty_uniq(_) |
- ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
+ ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
ty::ty_vec(_, ty::vstore_uniq) |
ty::ty_str(ty::vstore_uniq) |
- ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
+ ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
Some(deref_ptr(OwnedPtr))
}
Some(deref_ptr(BorrowedPtr(kind, r)))
}
- ty::ty_trait(_, _, ty::RegionTraitStore(r), m, _) => {
+ ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(r), mutability: m, .. }) => {
let kind = ty::BorrowKind::from_mutbl(m);
Some(deref_ptr(BorrowedPtr(kind, r)))
}
ty::ty_str(ty::vstore_slice(r)) |
- ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
+ ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
region: r, ..}) => {
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
}
// noalias because the actual object pointer is nested.
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
- ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
+ ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
unsafe {
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
}
ty::ty_closure(ref closurety) => {
subroutine_type_metadata(cx, &closurety.sig, usage_site_span)
},
- ty::ty_trait(def_id, ref substs, trait_store, mutability, ref bounds) => {
+ ty::ty_trait(~ty::TyTrait { def_id, ref substs,
+ store: trait_store, mutability,
+ ref bounds }) => {
trait_metadata(cx, def_id, t, substs, trait_store, mutability, bounds)
},
ty::ty_struct(def_id, ref substs) => {
}
}
}
- 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| {
})
}
- ty::ty_trait(_, _, _, _, _) => {
+ ty::ty_trait(..) => {
let extra = [
self.c_slice(token::intern_and_get_ident(ty_to_str(tcx, t)))
];
ty_ptr(mt),
ty_rptr(Region, mt),
ty_bare_fn(BareFnTy),
- ty_closure(ClosureTy),
- ty_trait(DefId, substs, TraitStore, ast::Mutability, BuiltinBounds),
+ ty_closure(~ClosureTy),
+ ty_trait(~TyTrait),
ty_struct(DefId, substs),
ty_tup(Vec<t>),
ty_unboxed_vec(mt),
}
+#[deriving(Clone, Eq, Hash)]
+pub struct TyTrait {
+ def_id: DefId,
+ substs: substs,
+ store: TraitStore,
+ mutability: ast::Mutability,
+ bounds: BuiltinBounds
+}
+
#[deriving(Eq, Hash)]
pub struct TraitRef {
def_id: DefId,
&ty_infer(_) => flags |= needs_infer as uint,
&ty_self(_) => flags |= has_self as uint,
&ty_enum(_, ref substs) | &ty_struct(_, ref substs) |
- &ty_trait(_, ref substs, _, _, _) => {
+ &ty_trait(~ty::TyTrait { ref substs, .. }) => {
flags |= sflags(substs);
match st {
- ty_trait(_, _, RegionTraitStore(r), _, _) => {
+ ty_trait(~ty::TyTrait { store: RegionTraitStore(r), .. }) => {
flags |= rflags(r);
}
_ => {}
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
- mk_t(cx, ty_closure(fty))
+ mk_t(cx, ty_closure(~fty))
}
pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t {
bounds: BuiltinBounds)
-> t {
// take a copy of substs so that we own the vectors inside
- mk_t(cx, ty_trait(did, substs, store, mutability, bounds))
+ let inner = ~TyTrait {
+ def_id: did,
+ substs: substs,
+ store: store,
+ mutability: mutability,
+ bounds: bounds
+ };
+ mk_t(cx, ty_trait(inner))
}
pub fn mk_struct(cx: &ctxt, struct_id: ast::DefId, substs: substs) -> t {
maybe_walk_ty(tm.ty, f);
}
ty_enum(_, ref substs) | ty_struct(_, ref substs) |
- ty_trait(_, ref substs, _, _, _) => {
+ ty_trait(~TyTrait { ref substs, .. }) => {
for subty in (*substs).tps.iter() { maybe_walk_ty(*subty, |x| f(x)); }
}
ty_tup(ref ts) => { for tt in ts.iter() { maybe_walk_ty(*tt, |x| f(x)); } }
}
ty_closure(ref c) => {
- closure_contents(cx, c)
+ closure_contents(cx, *c)
}
ty_box(typ) => {
tc_ty(cx, typ, cache).owned_pointer()
}
- ty_trait(_, _, store, mutbl, bounds) => {
- object_contents(cx, store, mutbl, bounds)
+ ty_trait(~ty::TyTrait { store, mutability, bounds, .. }) => {
+ object_contents(cx, store, mutability, bounds)
}
ty_ptr(ref mt) => {
false // unsafe ptrs can always be NULL
}
- ty_trait(_, _, _, _, _) => {
+ ty_trait(..) => {
false
}
pub fn replace_fn_sig(cx: &ctxt, fsty: &sty, new_sig: FnSig) -> t {
match *fsty {
ty_bare_fn(ref f) => mk_bare_fn(cx, BareFnTy {sig: new_sig, ..*f}),
- ty_closure(ref f) => mk_closure(cx, ClosureTy {sig: new_sig, ..*f}),
+ ty_closure(ref f) => mk_closure(cx, ClosureTy {sig: new_sig, ..**f}),
ref s => {
cx.sess.bug(
format!("ty_fn_sig() called on non-fn type: {:?}", s));
ty::ty_closure(ref fty) => {
ty::mk_closure(tcx, ClosureTy {
sig: FnSig {output: ret_type, ..fty.sig.clone()},
- ..(*fty).clone()
+ ..(**fty).clone()
})
}
_ => {
ty::mk_closure(cx, ClosureTy {
sigil: BorrowedSigil,
region: r,
- ..(*fty).clone()
+ ..(**fty).clone()
})
}
fn borrow_obj(cx: &ctxt, span: Span, r: Region,
m: ast::Mutability, ty: ty::t) -> ty::t {
match get(ty).sty {
- ty_trait(trt_did, ref trt_substs, _, _, b) => {
- ty::mk_trait(cx, trt_did, trt_substs.clone(),
- RegionTraitStore(r), m, b)
+ ty_trait(~ty::TyTrait {def_id, ref substs, bounds, .. }) => {
+ ty::mk_trait(cx, def_id, substs.clone(),
+ RegionTraitStore(r), m, bounds)
}
ref s => {
cx.sess.span_bug(
ty_rptr(_, _) => ~"&-ptr",
ty_bare_fn(_) => ~"extern fn",
ty_closure(_) => ~"fn",
- ty_trait(id, _, _, _, _) => format!("trait {}", item_path_str(cx, id)),
+ ty_trait(ref inner) => format!("trait {}", item_path_str(cx, inner.def_id)),
ty_struct(id, _) => format!("struct {}", item_path_str(cx, id)),
ty_tup(_) => ~"tuple",
ty_infer(TyVar(_)) => ~"inferred type",
pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
match get(ty).sty {
- ty_trait(id, _, _, _, _) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
+ ty_trait(~TyTrait { def_id: id, .. }) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
_ => None
}
}
hash!(c.bounds);
region(&mut state, c.region);
}
- ty_trait(d, _, store, m, bounds) => {
+ ty_trait(~ty::TyTrait { def_id: d, store, mutability: m, bounds, .. }) => {
byte!(17);
did(&mut state, d);
match store {
ty::ty_enum(tid, ref substs) => {
ty::ty_enum(tid, this.fold_substs(substs))
}
- ty::ty_trait(did, ref substs, st, mutbl, bounds) => {
- ty::ty_trait(did,
- this.fold_substs(substs),
- this.fold_trait_store(st),
- mutbl,
- bounds)
+ ty::ty_trait(~ty::TyTrait { def_id, ref substs, store, mutability, bounds }) => {
+ ty::ty_trait(~ty::TyTrait{
+ def_id: def_id,
+ substs: this.fold_substs(substs),
+ store: this.fold_trait_store(store),
+ mutability: mutability,
+ bounds: bounds
+ })
}
ty::ty_tup(ref ts) => {
ty::ty_tup(fold_ty_vec(this, ts.as_slice()))
ty::ty_bare_fn(this.fold_bare_fn_ty(f))
}
ty::ty_closure(ref f) => {
- ty::ty_closure(this.fold_closure_ty(f))
+ ty::ty_closure(~this.fold_closure_ty(*f))
}
ty::ty_rptr(r, ref tm) => {
ty::ty_rptr(this.fold_region(r),
let span = self.self_expr.map_or(self.span, |e| e.span);
check::autoderef(self.fcx, span, self_ty, None, PreferMutLvalue, |self_ty, _| {
match get(self_ty).sty {
- ty_trait(did, ref substs, _, _, _) => {
- self.push_inherent_candidates_from_object(did, substs);
- self.push_inherent_impl_candidates_for_type(did);
+ ty_trait(~TyTrait { def_id, ref substs, .. }) => {
+ self.push_inherent_candidates_from_object(def_id, substs);
+ self.push_inherent_impl_candidates_for_type(def_id);
}
ty_enum(did, _) | ty_struct(did, _) => {
if self.check_traits == CheckTraitsAndInherentMethods {
autoderefs: autoderefs,
autoref: Some(ty::AutoBorrowVec(region, self_mt.mutbl))})
}
- ty::ty_trait(did, ref substs, ty::RegionTraitStore(_), mutbl, bounds) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id, ref substs, store: ty::RegionTraitStore(_), mutability: mutbl, bounds
+ }) => {
let region =
self.infcx().next_region_var(infer::Autoref(self.span));
- (ty::mk_trait(tcx, did, substs.clone(),
+ (ty::mk_trait(tcx, def_id, substs.clone(),
ty::RegionTraitStore(region),
mutbl, bounds),
ty::AutoDerefRef {
})
}
- ty_trait(trt_did, trt_substs, _, _, b) => {
+ ty_trait(~ty::TyTrait { def_id: trt_did, substs: trt_substs, bounds: b, .. }) => {
// Coerce ~/@/&Trait instances to &Trait.
self.search_for_some_kind_of_autorefd_method(
rcvr_matches_ty(self.fcx, mt.ty, candidate)
}
- ty::ty_trait(self_did, _, RegionTraitStore(_), self_m, _) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id: self_did, store: RegionTraitStore(_), mutability: self_m, ..
+ }) => {
mutability_matches(self_m, m) &&
rcvr_matches_object(self_did, candidate)
}
rcvr_matches_ty(self.fcx, typ, candidate)
}
- ty::ty_trait(self_did, _, UniqTraitStore, _, _) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id: self_did, store: UniqTraitStore, ..
+ }) => {
rcvr_matches_object(self_did, candidate)
}
let fn_sig = match *fn_sty {
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, ..}) |
- ty::ty_closure(ty::ClosureTy {sig: ref sig, ..}) => sig,
+ ty::ty_closure(~ty::ClosureTy {sig: ref sig, ..}) => sig,
_ => {
fcx.type_error_message(call_expr.span, |actual| {
format!("expected function but \
// explaining how it goes about doing that.
let target_ty = rcx.resolve_node_type(expr.id);
match ty::get(target_ty).sty {
- ty::ty_trait(_, _, ty::RegionTraitStore(trait_region), _, _) => {
+ ty::ty_trait(~ty::TyTrait { store: ty::RegionTraitStore(trait_region), .. }) => {
let source_ty = rcx.resolve_expr_type_adjusted(source);
constrain_regions_in_type(
rcx,
let tcx = rcx.fcx.tcx();
let function_type = rcx.resolve_node_type(expr.id);
match ty::get(function_type).sty {
- ty::ty_closure(ty::ClosureTy {
+ ty::ty_closure(~ty::ClosureTy {
sigil: ast::BorrowedSigil, region: region, ..}) => {
let freevars = freevars::get_freevars(tcx, expr.id);
if freevars.is_empty() {
rcx.set_repeating_scope(repeating_scope);
match ty::get(function_type).sty {
- ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
+ ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
let freevars = freevars::get_freevars(tcx, expr.id);
propagate_upupvar_borrow_kind(rcx, expr, freevars);
}
ty::EmptyBuiltinBounds());
fixup_ty(vcx, span, t, is_early).map(|t_f| {
match ty::get(t_f).sty {
- ty::ty_trait(_, ref substs_f, _, _, _) => (*substs_f).clone(),
+ ty::ty_trait(ref inner) => inner.substs.clone(),
_ => fail!("t_f should be a trait")
}
})
let resolve_object_cast = |src: &ast::Expr, target_ty: ty::t| {
match ty::get(target_ty).sty {
// Bounds of type's contents are not checked here, but in kind.rs.
- ty::ty_trait(target_def_id, ref target_substs, store,
- target_mutbl, _bounds) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id: target_def_id, substs: ref target_substs, store: store,
+ mutability: target_mutbl, bounds: _bounds
+ }) => {
fn mutability_allowed(a_mutbl: ast::Mutability,
b_mutbl: ast::Mutability) -> bool {
a_mutbl == b_mutbl ||
ty::walk_ty(original_type, |t| {
match get(t).sty {
ty_enum(def_id, _) |
- ty_trait(def_id, _, _, _, _) |
+ ty_trait(~ty::TyTrait { def_id, .. }) |
ty_struct(def_id, _) => {
if def_id.krate == ast::LOCAL_CRATE {
found_nominal = true;
match get(base_type).sty {
ty_enum(def_id, _) |
ty_struct(def_id, _) |
- ty_trait(def_id, _, _, _, _) => {
+ ty_trait(~ty::TyTrait { def_id, .. }) => {
return Some(def_id);
}
_ => {
});
}
- ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
+ ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
return self.unpack_actual_value(a, |sty_a| {
self.coerce_borrowed_fn(a, sty_a, b)
});
});
}
- ty::ty_trait(def_id, ref substs, ty::UniqTraitStore, m, bounds) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id, ref substs, store: ty::UniqTraitStore, mutability: m, bounds
+ }) => {
let result = self.unpack_actual_value(a, |sty_a| {
match *sty_a {
ty::ty_uniq(..) => {
}
}
- ty::ty_trait(def_id, ref substs, ty::RegionTraitStore(region), m, bounds) => {
+ ty::ty_trait(~ty::TyTrait {
+ def_id, ref substs, store: ty::RegionTraitStore(region), mutability: m, bounds
+ }) => {
let result = self.unpack_actual_value(a, |sty_a| {
match *sty_a {
ty::ty_rptr(..) => {
let r_a = self.get_ref().infcx.next_region_var(Coercion(self.get_ref().trace));
let a_borrowed = match *sty_a {
- ty::ty_trait(did, ref substs, _, _, b) => {
- ty::mk_trait(tcx, did, substs.clone(),
- ty::RegionTraitStore(r_a), b_mutbl, b)
+ ty::ty_trait(~ty::TyTrait { def_id, ref substs, bounds, .. }) => {
+ ty::mk_trait(tcx, def_id, substs.clone(),
+ ty::RegionTraitStore(r_a), b_mutbl, bounds)
}
_ => {
return self.subtype(a, b);
ty::ClosureTy {
sigil: ast::BorrowedSigil,
region: r_borrow,
- ..fn_ty
+ .. *fn_ty
});
if_ok!(self.subtype(a_borrowed, b));
let a_closure = ty::mk_closure(self.get_ref().infcx.tcx,
ty::ClosureTy {
sig: fn_ty_a.sig.clone(),
- ..fn_ty_b
+ .. *fn_ty_b
});
if_ok!(self.subtype(a_closure, b));
Ok(Some(adj))
Ok(ty::mk_enum(tcx, a_id, substs))
}
- (&ty::ty_trait(a_id, ref a_substs, a_store, a_mutbl, a_bounds),
- &ty::ty_trait(b_id, ref b_substs, b_store, b_mutbl, b_bounds))
- if a_id == b_id && a_mutbl == b_mutbl => {
+ (&ty::ty_trait(ref a_),
+ &ty::ty_trait(ref b_))
+ if a_.def_id == b_.def_id && a_.mutability == b_.mutability => {
debug!("Trying to match traits {:?} and {:?}", a, b);
- let substs = if_ok!(this.substs(a_id, a_substs, b_substs));
- let s = if_ok!(this.trait_stores(ty::terr_trait, a_store, b_store));
- let bounds = if_ok!(this.bounds(a_bounds, b_bounds));
+ let substs = if_ok!(this.substs(a_.def_id, &a_.substs, &b_.substs));
+ let s = if_ok!(this.trait_stores(ty::terr_trait, a_.store, b_.store));
+ let bounds = if_ok!(this.bounds(a_.bounds, b_.bounds));
Ok(ty::mk_trait(tcx,
- a_id,
+ a_.def_id,
substs.clone(),
s,
- a_mutbl,
+ a_.mutability,
bounds))
}
}
(&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
- this.closure_tys(a_fty, b_fty).and_then(|fty| {
+ this.closure_tys(*a_fty, *b_fty).and_then(|fty| {
Ok(ty::mk_closure(tcx, fty))
})
}
ty::EmptyBuiltinBounds());
let dummy1 = self.resolve_type_vars_if_possible(dummy0);
match ty::get(dummy1).sty {
- ty::ty_trait(ref def_id, ref substs, _, _, _) => {
+ ty::ty_trait(~ty::TyTrait { ref def_id, ref substs, .. }) => {
ty::TraitRef {
def_id: *def_id,
substs: (*substs).clone(),
}
}
}
-
substs, variance);
}
- ty::ty_trait(def_id, ref substs, _, _, _) => {
+ ty::ty_trait(~ty::TyTrait { def_id, ref substs, .. }) => {
let trait_def = ty::lookup_trait_def(self.tcx(), def_id);
self.add_constraints_from_substs(def_id, &trait_def.generics,
substs, variance);
self.add_constraints_from_sig(sig, variance);
}
- ty::ty_closure(ty::ClosureTy { sig: ref sig, region, .. }) => {
+ ty::ty_closure(~ty::ClosureTy { sig: ref sig, region, .. }) => {
let contra = self.contravariant(variance);
self.add_constraints_from_region(region, contra);
self.add_constraints_from_sig(sig, variance);
~"(" + strs.connect(",") + ")"
}
ty_closure(ref f) => {
- closure_to_str(cx, f)
+ closure_to_str(cx, *f)
}
ty_bare_fn(ref f) => {
bare_fn_to_str(cx, f.purity, f.abis, None, &f.sig)
did,
false)
}
- ty_trait(did, ref substs, s, mutbl, ref bounds) => {
+ ty_trait(~ty::TyTrait {
+ def_id: did, ref substs, store: s, mutability: mutbl, ref bounds
+ }) => {
let base = ty::item_path_str(cx, did);
let ty = parameterized(cx, base, &substs.regions,
substs.tps.as_slice(), did, true);