From 446a0c65f57c717d69a091a0050dfb46c236a556 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 26 Jan 2014 01:09:32 +1100 Subject: [PATCH] rustc: allow "omitting" visit glue. This adds `-Z noop-reflection` which causes all visit glues to be empty. As an example of its effects, an optimised libsyntax.so is 300 KB (5%) smaller and requires 14MB less memory to compile. This is likely most useful for #[no_std] crates using closures or trait objects (which require a tydesc to be created for their contained types) to avoid the code bloat of the otherwise unused visit glue. --- src/librustc/driver/session.rs | 8 +++++++- src/librustc/middle/trans/glue.rs | 7 +++++-- src/test/run-pass/noop-reflection.rs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/noop-reflection.rs diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 38fa85fe8089a..a1652b3321300 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -76,7 +76,8 @@ debugging_opts!( GEN_CRATE_MAP, PREFER_DYNAMIC, NO_INTEGRATED_AS, - LTO + LTO, + NOOP_REFLECTION ] 0 ) @@ -124,6 +125,8 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, u64)] { ("no-integrated-as", "Use external assembler rather than LLVM's integrated one", NO_INTEGRATED_AS), ("lto", "Perform LLVM link-time optimizations", LTO), + ("noop-reflection", "Avoid generating the visit glue (stops {:?} working)", + NOOP_REFLECTION) ] } @@ -348,6 +351,9 @@ impl Session_ { pub fn no_landing_pads(&self) -> bool { self.debugging_opt(NO_LANDING_PADS) } + pub fn noop_reflection(&self) -> bool { + self.debugging_opt(NOOP_REFLECTION) + } // pointless function, now... pub fn str_of(&self, id: ast::Ident) -> @str { diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index ae03d48dbf0dc..e7af045460b53 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -267,10 +267,13 @@ fn call_tydesc_glue<'a>(cx: &'a Block<'a>, v: ValueRef, t: ty::t, field: uint) cx } -fn make_visit_glue<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) +fn make_visit_glue<'a>(mut bcx: &'a Block<'a>, v: ValueRef, t: ty::t) -> &'a Block<'a> { let _icx = push_ctxt("make_visit_glue"); - let mut bcx = bcx; + if bcx.tcx().sess.noop_reflection() { + return bcx; + } + let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(), ty::ReStatic) { Ok(pair) => pair, diff --git a/src/test/run-pass/noop-reflection.rs b/src/test/run-pass/noop-reflection.rs new file mode 100644 index 0000000000000..65eca9ae67e09 --- /dev/null +++ b/src/test/run-pass/noop-reflection.rs @@ -0,0 +1,16 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-fast compile flags doesn't work +// compile-flags: -Z noop-reflection + +pub fn main() { + assert_eq!(format!("{:?}", 1), ~""); +}