rustc: put ty_closure behind some indirection.
This reduces the size of sty from 112 to 96; like with the ty_trait variant, this variant of sty occurs rarely (~1%) so the benefits are large and the costs small.
This commit is contained in:
parent
405b5fc1ee
commit
ddc796096b
12 changed files with 23 additions and 23 deletions
|
@ -315,7 +315,7 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
|
|||
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");
|
||||
|
|
|
@ -208,21 +208,21 @@ fn with_appropriate_checker(cx: &Context,
|
|||
|
||||
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,
|
||||
|
|
|
@ -173,7 +173,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
|
|||
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))
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
|
|||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
|
|||
// 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);
|
||||
}
|
||||
|
|
|
@ -746,7 +746,7 @@ pub enum sty {
|
|||
ty_ptr(mt),
|
||||
ty_rptr(Region, mt),
|
||||
ty_bare_fn(BareFnTy),
|
||||
ty_closure(ClosureTy),
|
||||
ty_closure(~ClosureTy),
|
||||
ty_trait(~TyTrait),
|
||||
ty_struct(DefId, substs),
|
||||
ty_tup(Vec<t>),
|
||||
|
@ -1407,7 +1407,7 @@ pub fn mk_mut_unboxed_vec(cx: &ctxt, ty: t) -> t {
|
|||
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 {
|
||||
|
@ -2149,7 +2149,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
|
|||
}
|
||||
|
||||
ty_closure(ref c) => {
|
||||
closure_contents(cx, c)
|
||||
closure_contents(cx, *c)
|
||||
}
|
||||
|
||||
ty_box(typ) => {
|
||||
|
@ -2870,7 +2870,7 @@ pub fn ty_region(tcx: &ctxt,
|
|||
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));
|
||||
|
@ -2888,7 +2888,7 @@ pub fn replace_closure_return_type(tcx: &ctxt, fn_type: t, ret_type: t) -> t {
|
|||
ty::ty_closure(ref fty) => {
|
||||
ty::mk_closure(tcx, ClosureTy {
|
||||
sig: FnSig {output: ret_type, ..fty.sig.clone()},
|
||||
..(*fty).clone()
|
||||
..(**fty).clone()
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
|
@ -3140,7 +3140,7 @@ pub fn adjust_ty(cx: &ctxt,
|
|||
ty::mk_closure(cx, ClosureTy {
|
||||
sigil: BorrowedSigil,
|
||||
region: r,
|
||||
..(*fty).clone()
|
||||
..(**fty).clone()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ pub fn super_fold_sty<T:TypeFolder>(this: &mut T,
|
|||
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),
|
||||
|
|
|
@ -1860,7 +1860,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
|
||||
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 \
|
||||
|
|
|
@ -610,7 +610,7 @@ fn check_expr_fn_block(rcx: &mut 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() {
|
||||
|
@ -635,7 +635,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ impl<'f> Coerce<'f> {
|
|||
});
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
|
@ -361,7 +361,7 @@ impl<'f> Coerce<'f> {
|
|||
ty::ClosureTy {
|
||||
sigil: ast::BorrowedSigil,
|
||||
region: r_borrow,
|
||||
..fn_ty
|
||||
.. *fn_ty
|
||||
});
|
||||
|
||||
if_ok!(self.subtype(a_borrowed, b));
|
||||
|
@ -397,7 +397,7 @@ impl<'f> Coerce<'f> {
|
|||
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))
|
||||
|
|
|
@ -570,7 +570,7 @@ pub fn super_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
|
|||
}
|
||||
|
||||
(&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))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -705,7 +705,7 @@ impl<'a> ConstraintContext<'a> {
|
|||
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);
|
||||
|
|
|
@ -453,7 +453,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
|||
~"(" + 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue