Skip to content

Commit ddc7960

Browse files
committed
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.
1 parent 405b5fc commit ddc7960

File tree

12 files changed

+23
-23
lines changed

12 files changed

+23
-23
lines changed

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
315315
ty::ty_unboxed_vec(mt) => { mywrite!(w, "U"); enc_mt(w, cx, mt); }
316316
ty::ty_closure(ref f) => {
317317
mywrite!(w, "f");
318-
enc_closure_ty(w, cx, f);
318+
enc_closure_ty(w, cx, *f);
319319
}
320320
ty::ty_bare_fn(ref f) => {
321321
mywrite!(w, "F");

src/librustc/middle/kind.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,21 @@ fn with_appropriate_checker(cx: &Context,
208208

209209
let fty = ty::node_id_to_type(cx.tcx, id);
210210
match ty::get(fty).sty {
211-
ty::ty_closure(ty::ClosureTy {
211+
ty::ty_closure(~ty::ClosureTy {
212212
sigil: OwnedSigil,
213213
bounds: bounds,
214214
..
215215
}) => {
216216
b(|cx, fv| check_for_uniq(cx, fv, bounds))
217217
}
218-
ty::ty_closure(ty::ClosureTy {
218+
ty::ty_closure(~ty::ClosureTy {
219219
sigil: ManagedSigil,
220220
..
221221
}) => {
222222
// can't happen
223223
fail!("internal error: saw closure with managed sigil (@fn)");
224224
}
225-
ty::ty_closure(ty::ClosureTy {
225+
ty::ty_closure(~ty::ClosureTy {
226226
sigil: BorrowedSigil,
227227
bounds: bounds,
228228
region: region,

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
173173
ty::ty_trait(~ty::TyTrait { store: ty::UniqTraitStore, .. }) |
174174
ty::ty_vec(_, ty::vstore_uniq) |
175175
ty::ty_str(ty::vstore_uniq) |
176-
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
176+
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
177177
Some(deref_ptr(OwnedPtr))
178178
}
179179

@@ -189,7 +189,7 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
189189
}
190190

191191
ty::ty_str(ty::vstore_slice(r)) |
192-
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil,
192+
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil,
193193
region: r, ..}) => {
194194
Some(deref_ptr(BorrowedPtr(ty::ImmBorrow, r)))
195195
}

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
269269
// noalias because the actual object pointer is nested.
270270
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
271271
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
272-
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
272+
ty::ty_closure(~ty::ClosureTy {sigil: ast::OwnedSigil, ..}) => {
273273
unsafe {
274274
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
275275
}

src/librustc/middle/ty.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ pub enum sty {
746746
ty_ptr(mt),
747747
ty_rptr(Region, mt),
748748
ty_bare_fn(BareFnTy),
749-
ty_closure(ClosureTy),
749+
ty_closure(~ClosureTy),
750750
ty_trait(~TyTrait),
751751
ty_struct(DefId, substs),
752752
ty_tup(Vec<t>),
@@ -1407,7 +1407,7 @@ pub fn mk_mut_unboxed_vec(cx: &ctxt, ty: t) -> t {
14071407
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
14081408

14091409
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
1410-
mk_t(cx, ty_closure(fty))
1410+
mk_t(cx, ty_closure(~fty))
14111411
}
14121412

14131413
pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t {
@@ -2149,7 +2149,7 @@ pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
21492149
}
21502150

21512151
ty_closure(ref c) => {
2152-
closure_contents(cx, c)
2152+
closure_contents(cx, *c)
21532153
}
21542154

21552155
ty_box(typ) => {
@@ -2870,7 +2870,7 @@ pub fn ty_region(tcx: &ctxt,
28702870
pub fn replace_fn_sig(cx: &ctxt, fsty: &sty, new_sig: FnSig) -> t {
28712871
match *fsty {
28722872
ty_bare_fn(ref f) => mk_bare_fn(cx, BareFnTy {sig: new_sig, ..*f}),
2873-
ty_closure(ref f) => mk_closure(cx, ClosureTy {sig: new_sig, ..*f}),
2873+
ty_closure(ref f) => mk_closure(cx, ClosureTy {sig: new_sig, ..**f}),
28742874
ref s => {
28752875
cx.sess.bug(
28762876
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 {
28882888
ty::ty_closure(ref fty) => {
28892889
ty::mk_closure(tcx, ClosureTy {
28902890
sig: FnSig {output: ret_type, ..fty.sig.clone()},
2891-
..(*fty).clone()
2891+
..(**fty).clone()
28922892
})
28932893
}
28942894
_ => {
@@ -3140,7 +3140,7 @@ pub fn adjust_ty(cx: &ctxt,
31403140
ty::mk_closure(cx, ClosureTy {
31413141
sigil: BorrowedSigil,
31423142
region: r,
3143-
..(*fty).clone()
3143+
..(**fty).clone()
31443144
})
31453145
}
31463146

src/librustc/middle/ty_fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn super_fold_sty<T:TypeFolder>(this: &mut T,
175175
ty::ty_bare_fn(this.fold_bare_fn_ty(f))
176176
}
177177
ty::ty_closure(ref f) => {
178-
ty::ty_closure(this.fold_closure_ty(f))
178+
ty::ty_closure(~this.fold_closure_ty(*f))
179179
}
180180
ty::ty_rptr(r, ref tm) => {
181181
ty::ty_rptr(this.fold_region(r),

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
18601860

18611861
let fn_sig = match *fn_sty {
18621862
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, ..}) |
1863-
ty::ty_closure(ty::ClosureTy {sig: ref sig, ..}) => sig,
1863+
ty::ty_closure(~ty::ClosureTy {sig: ref sig, ..}) => sig,
18641864
_ => {
18651865
fcx.type_error_message(call_expr.span, |actual| {
18661866
format!("expected function but \

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
610610
let tcx = rcx.fcx.tcx();
611611
let function_type = rcx.resolve_node_type(expr.id);
612612
match ty::get(function_type).sty {
613-
ty::ty_closure(ty::ClosureTy {
613+
ty::ty_closure(~ty::ClosureTy {
614614
sigil: ast::BorrowedSigil, region: region, ..}) => {
615615
let freevars = freevars::get_freevars(tcx, expr.id);
616616
if freevars.is_empty() {
@@ -635,7 +635,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
635635
rcx.set_repeating_scope(repeating_scope);
636636

637637
match ty::get(function_type).sty {
638-
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
638+
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
639639
let freevars = freevars::get_freevars(tcx, expr.id);
640640
propagate_upupvar_borrow_kind(rcx, expr, freevars);
641641
}

src/librustc/middle/typeck/infer/coercion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'f> Coerce<'f> {
119119
});
120120
}
121121

122-
ty::ty_closure(ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
122+
ty::ty_closure(~ty::ClosureTy {sigil: ast::BorrowedSigil, ..}) => {
123123
return self.unpack_actual_value(a, |sty_a| {
124124
self.coerce_borrowed_fn(a, sty_a, b)
125125
});
@@ -361,7 +361,7 @@ impl<'f> Coerce<'f> {
361361
ty::ClosureTy {
362362
sigil: ast::BorrowedSigil,
363363
region: r_borrow,
364-
..fn_ty
364+
.. *fn_ty
365365
});
366366

367367
if_ok!(self.subtype(a_borrowed, b));
@@ -397,7 +397,7 @@ impl<'f> Coerce<'f> {
397397
let a_closure = ty::mk_closure(self.get_ref().infcx.tcx,
398398
ty::ClosureTy {
399399
sig: fn_ty_a.sig.clone(),
400-
..fn_ty_b
400+
.. *fn_ty_b
401401
});
402402
if_ok!(self.subtype(a_closure, b));
403403
Ok(Some(adj))

src/librustc/middle/typeck/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ pub fn super_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
570570
}
571571

572572
(&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
573-
this.closure_tys(a_fty, b_fty).and_then(|fty| {
573+
this.closure_tys(*a_fty, *b_fty).and_then(|fty| {
574574
Ok(ty::mk_closure(tcx, fty))
575575
})
576576
}

src/librustc/middle/typeck/variance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'a> ConstraintContext<'a> {
705705
self.add_constraints_from_sig(sig, variance);
706706
}
707707

708-
ty::ty_closure(ty::ClosureTy { sig: ref sig, region, .. }) => {
708+
ty::ty_closure(~ty::ClosureTy { sig: ref sig, region, .. }) => {
709709
let contra = self.contravariant(variance);
710710
self.add_constraints_from_region(region, contra);
711711
self.add_constraints_from_sig(sig, variance);

src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
453453
~"(" + strs.connect(",") + ")"
454454
}
455455
ty_closure(ref f) => {
456-
closure_to_str(cx, f)
456+
closure_to_str(cx, *f)
457457
}
458458
ty_bare_fn(ref f) => {
459459
bare_fn_to_str(cx, f.purity, f.abis, None, &f.sig)

0 commit comments

Comments
 (0)