From 5e5cc6749eb16f2820fe291582ded0b035667612 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 5 Dec 2014 01:10:22 -0800 Subject: Slash the ast::Stmt type from 104 to 24 bytes. (on platforms with 64-bit pointers.) The StmtMac variant is rather large and also fairly rare, so let's optimise the common case. --- src/libsyntax/ast.rs | 2 +- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/visit.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0c8c17b080b..d4932fbb5f1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -607,7 +607,7 @@ pub enum Stmt_ { /// Expr with trailing semi-colon (may have any type): StmtSemi(P, NodeId), - StmtMac(Mac, MacStmtStyle), + StmtMac(P, MacStmtStyle), } #[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index f2b6f6bfe16..d2d624fa05e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -672,7 +672,7 @@ fn expand_stmt(s: Stmt, fld: &mut MacroExpander) -> SmallVector> { StmtMac(mac, style) => (mac, style), _ => return expand_non_macro_stmt(s, fld) }; - let expanded_stmt = match expand_mac_invoc(mac, s.span, + let expanded_stmt = match expand_mac_invoc(mac.and_then(|m| m), s.span, |r| r.make_stmt(), mark_stmt, fld) { Some(stmt) => stmt, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0803de1bb53..c58901701f5 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1461,7 +1461,7 @@ pub fn noop_fold_stmt(Spanned {node, span}: Stmt, folder: &mut T) })) } StmtMac(mac, semi) => SmallVector::one(P(Spanned { - node: StmtMac(folder.fold_mac(mac), semi), + node: StmtMac(mac.map(|m| folder.fold_mac(m)), semi), span: span })) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 94b61ba56d2..15b92b2edbf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3940,7 +3940,7 @@ impl<'a> Parser<'a> { expr = Some( self.mk_mac_expr(span.lo, span.hi, - m.node)); + m.and_then(|x| x.node))); } _ => { stmts.push(P(Spanned { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3d53bd8aadf..623f20bccd2 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1337,7 +1337,7 @@ impl<'a> State<'a> { ast::MacStmtWithBraces => token::Brace, _ => token::Paren }; - try!(self.print_mac(mac, delim)); + try!(self.print_mac(&**mac, delim)); match style { ast::MacStmtWithBraces => {} _ => try!(word(&mut self.s, ";")), diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 4cc93467a7c..714339d0f0a 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -730,7 +730,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => { visitor.visit_expr(&**expression) } - StmtMac(ref macro, _) => visitor.visit_mac(macro), + StmtMac(ref macro, _) => visitor.visit_mac(&**macro), } } -- cgit 1.4.1-3-g733a5 From d442f7756161eb36531772ed905680385f87f1a4 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 11 Dec 2014 21:01:28 -0700 Subject: Rebase fixes. I've totally mangled the history with these rebases; sorry, future programmer! --- src/librustc/lint/builtin.rs | 4 ++-- src/librustc/middle/ty.rs | 13 ++++++------- src/librustc/util/ppaux.rs | 2 +- src/librustc_driver/driver.rs | 4 ++-- src/librustc_trans/trans/expr.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- src/libsyntax/parse/parser.rs | 6 +++--- 7 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 0fd69ea25bc..9ce344586fd 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1598,7 +1598,7 @@ impl LintPass for MissingCopyImplementations { } ty::mk_struct(cx.tcx, ast_util::local_def(item.id), - Substs::empty()) + cx.tcx.mk_substs(Substs::empty())) } ast::ItemEnum(_, ref ast_generics) => { if ast_generics.is_parameterized() { @@ -1606,7 +1606,7 @@ impl LintPass for MissingCopyImplementations { } ty::mk_enum(cx.tcx, ast_util::local_def(item.id), - Substs::empty()) + cx.tcx.mk_substs(Substs::empty())) } _ => return, }; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 24e85efde7f..ce02f443318 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -803,14 +803,13 @@ bitflags! { } } -impl Copy for TypeFlags {} - macro_rules! sty_debug_print { ($ctxt: expr, $($variant: ident),*) => {{ // curious inner module to allow variant names to be used as // variable names. mod inner { use middle::ty; + #[deriving(Copy)] struct DebugStat { total: uint, region_infer: uint, @@ -5704,7 +5703,7 @@ pub fn object_region_bounds<'tcx>(tcx: &ctxt<'tcx>, let opt_trait_ref = opt_principal.map_or(Vec::new(), |principal| { let substs = principal.substs().with_self_ty(open_ty); - vec!(Rc::new(ty::Binder(ty::TraitRef::new(principal.def_id(), substs)))) + vec!(Rc::new(ty::Binder(ty::TraitRef::new(principal.def_id(), tcx.mk_substs(substs))))) }); let param_bounds = ty::ParamBounds { @@ -6063,7 +6062,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) - } ty_rptr(r, m) => { byte!(13); - region(state, r); + region(state, *r); mt(state, m); } ty_bare_fn(opt_def_id, ref b) => { @@ -6123,7 +6122,7 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) - ty_unboxed_closure(d, r, _) => { byte!(24); did(state, d); - region(state, r); + region(state, *r); } } true @@ -6695,7 +6694,7 @@ pub fn can_type_implement_copy<'tcx>(tcx: &ctxt<'tcx>, param_env: &ParameterEnvironment<'tcx>) -> Result<(),CopyImplementationError> { match self_type.sty { - ty::ty_struct(struct_did, ref substs) => { + ty::ty_struct(struct_did, substs) => { let fields = ty::struct_fields(tcx, struct_did, substs); for field in fields.iter() { if type_moves_by_default(tcx, field.mt.ty, param_env) { @@ -6703,7 +6702,7 @@ pub fn can_type_implement_copy<'tcx>(tcx: &ctxt<'tcx>, } } } - ty::ty_enum(enum_did, ref substs) => { + ty::ty_enum(enum_did, substs) => { let enum_variants = ty::enum_variants(tcx, enum_did); for variant in enum_variants.iter() { for variant_arg_type in variant.args.iter() { diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 7887c4e2dce..62092a67cbe 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -759,7 +759,7 @@ impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> { let trait_def = ty::lookup_trait_def(tcx, self.def_id); format!("TraitRef({}, {})", self.substs.self_ty().repr(tcx), - parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics, self.def_id)) + parameterized(tcx, base.as_slice(), self.substs, &trait_def.generics, self.def_id)) } } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 6b61bd4f72b..0ac8d6ba734 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -83,7 +83,7 @@ pub fn compile_input(sess: Session, phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir); if log_enabled!(::log::INFO) { - println!("Pre-trans") + println!("Pre-trans"); analysis.ty_cx.print_debug_stats(); } @@ -91,7 +91,7 @@ pub fn compile_input(sess: Session, let (tcx, trans) = phase_4_translate_to_llvm(analysis); if log_enabled!(::log::INFO) { - println!("Post-trans") + println!("Post-trans"); tcx.print_debug_stats(); } diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index ca34b10e394..e3e0fffcd86 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -350,7 +350,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr.id, datum_ty, |t| ty::mk_rptr(tcx, - ty::ReStatic, + tcx.mk_region(ty::ReStatic), ty::mt{ ty: t, mutbl: ast::MutImmutable diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9252e5a8203..793c5f5b4a0 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1419,7 +1419,7 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, index += 1; Some(ty::mk_param(ccx.tcx, subst::AssocSpace, - index as u32 - 1, + index - 1, local_def(trait_item.ty_param.id))).into_iter() } ast::RequiredMethod(_) | ast::ProvidedMethod(_) => { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 15b92b2edbf..a2e2abab03e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3746,9 +3746,9 @@ impl<'a> Parser<'a> { if id.name == token::special_idents::invalid.name { P(spanned(lo, hi, - StmtMac(spanned(lo, + StmtMac(P(spanned(lo, hi, - MacInvocTT(pth, tts, EMPTY_CTXT)), + MacInvocTT(pth, tts, EMPTY_CTXT))), style))) } else { // if it has a special ident, it's definitely an item @@ -3911,7 +3911,7 @@ impl<'a> Parser<'a> { _ => { let e = self.mk_mac_expr(span.lo, span.hi, - macro.node); + macro.and_then(|m| m.node)); let e = self.parse_dot_or_call_expr_with(e); self.handle_expression_like_statement( -- cgit 1.4.1-3-g733a5