]> git.lizzy.rs Git - rust.git/commitdiff
rustc: put ty_closure behind some indirection.
authorHuon Wilson <dbau.pp+github@gmail.com>
Wed, 19 Mar 2014 11:20:56 +0000 (22:20 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Wed, 19 Mar 2014 11:20:56 +0000 (22:20 +1100)
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.

12 files changed:
src/librustc/metadata/tyencode.rs
src/librustc/middle/kind.rs
src/librustc/middle/mem_categorization.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/ty.rs
src/librustc/middle/ty_fold.rs
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/regionck.rs
src/librustc/middle/typeck/infer/coercion.rs
src/librustc/middle/typeck/infer/combine.rs
src/librustc/middle/typeck/variance.rs
src/librustc/util/ppaux.rs

index 3d66645044fcd16f7d7cd7283f7463463c549717..0934b6407fb744ea51f95232a5a0a2f7a2f972d9 100644 (file)
@@ -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");
index b6433fe167d7c6b72600321f6424ee606dfd2fcf..0f7106c389813ad7c0b76e49ab976e10379e162b 100644 (file)
@@ -208,21 +208,21 @@ fn check_for_bare(cx: &Context, fv: @freevar_entry) {
 
     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,
index 3413a8fa3845ec2bf7d67bc506659ec3cdb33896..7c95815af54e50f9fb7051b1c5f5b9494ff5749b 100644 (file)
@@ -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)))
         }
index bcf0b5d5f64bdeed095b67c75454c194613ecdc6..7cdb4b07d03a823e825798d4acb1130fa98d5d06 100644 (file)
@@ -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);
                 }
index abf4d5a8c40975645ff95f693daec6a98700656b..61371cec49ea590321dd5dc92912b12cc95cbbb2 100644 (file)
@@ -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 @@ fn tc_ty(cx: &ctxt,
             }
 
             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 @@ fn borrow_fn(cx: &ctxt, span: Span, r: Region, ty: ty::t) -> ty::t {
                 ty::mk_closure(cx, ClosureTy {
                     sigil: BorrowedSigil,
                     region: r,
-                    ..(*fty).clone()
+                    ..(**fty).clone()
                 })
             }
 
index 126929683b33bbe05716caa32a50761eecec6654..f75d707b0f3b0f98a50c08df231ee014afc77fb4 100644 (file)
@@ -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),
index 205c1c106dd165d6adf7c997d7ad4923447a90d2..8ed28711194ff82808e6bf29caa34c3c95e14123 100644 (file)
@@ -1860,7 +1860,7 @@ fn check_call(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 \
index d7854ca4b73e1dfa23b240884e538d45774dd1b6..1533943a55c2190553429c9a10f01557e1171bc1 100644 (file)
@@ -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);
         }
index 53ab3d3419061eb92410f8d702e652d8cf51774a..5dc55ab4b5c07056084b91e5b0cbb60c73d48fa4 100644 (file)
@@ -119,7 +119,7 @@ pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult {
                 });
             }
 
-            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 @@ pub fn coerce_borrowed_fn(&self,
             ty::ClosureTy {
                 sigil: ast::BorrowedSigil,
                 region: r_borrow,
-                ..fn_ty
+                .. *fn_ty
             });
 
         if_ok!(self.subtype(a_borrowed, b));
@@ -397,7 +397,7 @@ fn coerce_from_bare_fn(&self, a: ty::t, fn_ty_a: &ty::BareFnTy, b: ty::t)
             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))
index b55d6be54fd26832207ccf32f589176981924d26..b05e168e9434c8feee4fb6e389e366c97b40c23d 100644 (file)
@@ -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))
         })
       }
index 8068ab1ae8ccb719c43f8aa14a94299b8155eff2..f9c336a499401b400cbdcf68e17a463951b9b7e1 100644 (file)
@@ -705,7 +705,7 @@ fn add_constraints_from_ty(&mut self,
                 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);
index 1fa204f526166c67ea9977fceda638c70bb4d192..7c03c1dc45dfb95a4bd625dd6c851bdfa197569e 100644 (file)
@@ -453,7 +453,7 @@ fn push_sig_to_str(cx: &ctxt,
         ~"(" + 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)