Skip to content

Commit 3652736

Browse files
committed
auto merge of #7429 : Blei/rust/delete-shared, r=huonw
Mostly just low-haning fruit, i.e. function arguments that were @ even though & would work just as well. Reduces librustc.so size by 200k when compiling without -O, by 100k when compiling with -O.
2 parents c440743 + 7295a6d commit 3652736

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+388
-427
lines changed

src/librustc/driver/driver.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ pub fn compile_rest(sess: Session,
181181

182182
let time_passes = sess.time_passes();
183183

184-
let mut crate_opt = curr;
184+
let mut crate = curr.unwrap();
185185

186186
if phases.from == cu_parse || phases.from == cu_everything {
187187

188188
*sess.building_library = session::building_library(
189-
sess.opts.crate_type, crate_opt.unwrap(), sess.opts.test);
189+
sess.opts.crate_type, crate, sess.opts.test);
190190

191191
// strip before expansion to allow macros to depend on
192192
// configuration variables e.g/ in
@@ -195,27 +195,25 @@ pub fn compile_rest(sess: Session,
195195
// mod bar { macro_rules! baz!(() => {{}}) }
196196
//
197197
// baz! should not use this definition unless foo is enabled.
198-
crate_opt = Some(time(time_passes, ~"configuration 1", ||
199-
front::config::strip_unconfigured_items(crate_opt.unwrap())));
198+
crate = time(time_passes, ~"configuration 1", ||
199+
front::config::strip_unconfigured_items(crate));
200200

201-
crate_opt = Some(time(time_passes, ~"expansion", ||
201+
crate = time(time_passes, ~"expansion", ||
202202
syntax::ext::expand::expand_crate(sess.parse_sess, copy cfg,
203-
crate_opt.unwrap())));
203+
crate));
204204

205205
// strip again, in case expansion added anything with a #[cfg].
206-
crate_opt = Some(time(time_passes, ~"configuration 2", ||
207-
front::config::strip_unconfigured_items(crate_opt.unwrap())));
206+
crate = time(time_passes, ~"configuration 2", ||
207+
front::config::strip_unconfigured_items(crate));
208208

209-
crate_opt = Some(time(time_passes, ~"maybe building test harness", ||
210-
front::test::modify_for_testing(sess, crate_opt.unwrap())));
209+
crate = time(time_passes, ~"maybe building test harness", ||
210+
front::test::modify_for_testing(sess, crate));
211211
}
212212

213-
if phases.to == cu_expand { return (crate_opt, None); }
213+
if phases.to == cu_expand { return (Some(crate), None); }
214214

215215
assert!(phases.from != cu_no_trans);
216216

217-
let mut crate = crate_opt.unwrap();
218-
219217
let (llcx, llmod, link_meta) = {
220218
crate = time(time_passes, ~"extra injection", ||
221219
front::std_inject::maybe_inject_libstd_ref(sess, crate));

src/librustc/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub fn expect<T:Copy>(sess: Session,
349349
}
350350

351351
pub fn building_library(req_crate_type: crate_type,
352-
crate: @ast::crate,
352+
crate: &ast::crate,
353353
testing: bool) -> bool {
354354
match req_crate_type {
355355
bin_crate => false,

src/librustc/front/config.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ struct Context {
2424
// any items that do not belong in the current configuration
2525
pub fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate {
2626
do strip_items(crate) |attrs| {
27-
in_cfg(/*bad*/copy crate.node.config, attrs)
27+
in_cfg(crate.node.config, attrs)
2828
}
2929
}
3030

31-
pub fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred)
31+
pub fn strip_items(crate: &ast::crate, in_cfg: in_cfg_pred)
3232
-> @ast::crate {
3333

3434
let ctxt = @Context { in_cfg: in_cfg };
@@ -44,8 +44,7 @@ pub fn strip_items(crate: @ast::crate, in_cfg: in_cfg_pred)
4444
.. *fold::default_ast_fold()};
4545

4646
let fold = fold::make_fold(precursor);
47-
let res = @fold.fold_crate(&*crate);
48-
return res;
47+
@fold.fold_crate(crate)
4948
}
5049

5150
fn filter_item(cx: @Context, item: @ast::item) ->
@@ -183,12 +182,12 @@ fn trait_method_in_cfg(cx: @Context, meth: &ast::trait_method) -> bool {
183182

184183
// Determine if an item should be translated in the current crate
185184
// configuration based on the item's attributes
186-
fn in_cfg(cfg: ast::crate_cfg, attrs: ~[ast::attribute]) -> bool {
185+
fn in_cfg(cfg: &[@ast::meta_item], attrs: &[ast::attribute]) -> bool {
187186
metas_in_cfg(cfg, attr::attr_metas(attrs))
188187
}
189188

190-
pub fn metas_in_cfg(cfg: ast::crate_cfg,
191-
metas: ~[@ast::meta_item]) -> bool {
189+
pub fn metas_in_cfg(cfg: &[@ast::meta_item],
190+
metas: &[@ast::meta_item]) -> bool {
192191
// The "cfg" attributes on the item
193192
let cfg_metas = attr::find_meta_items_by_name(metas, "cfg");
194193

src/librustc/front/std_inject.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::crate)
3030
}
3131
}
3232

33-
fn use_std(crate: @ast::crate) -> bool {
33+
fn use_std(crate: &ast::crate) -> bool {
3434
!attr::attrs_contains_name(crate.node.attrs, "no_std")
3535
}
3636

37-
fn inject_libstd_ref(sess: Session, crate: @ast::crate) -> @ast::crate {
37+
fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
3838
fn spanned<T:Copy>(x: T) -> codemap::spanned<T> {
3939
codemap::spanned { node: x, span: dummy_sp() }
4040
}

src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn generate_test_harness(sess: session::Session,
9292
return res;
9393
}
9494

95-
fn strip_test_functions(crate: @ast::crate) -> @ast::crate {
95+
fn strip_test_functions(crate: &ast::crate) -> @ast::crate {
9696
// When not compiling with --test we should not compile the
9797
// #[test] functions
9898
do config::strip_items(crate) |attrs| {

src/librustc/metadata/creader.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use metadata::filesearch::FileSearch;
1818
use metadata::loader;
1919

2020
use core::hashmap::HashMap;
21-
use core::vec;
2221
use syntax::attr;
2322
use syntax::codemap::{span, dummy_sp};
2423
use syntax::diagnostic::span_handler;
@@ -30,7 +29,7 @@ use syntax::ast;
3029
// Traverses an AST, reading all the information about use'd crates and extern
3130
// libraries necessary for later resolving, typechecking, linking, etc.
3231
pub fn read_crates(diag: @span_handler,
33-
crate: @ast::crate,
32+
crate: &ast::crate,
3433
cstore: @mut cstore::CStore,
3534
filesearch: @FileSearch,
3635
os: loader::os,
@@ -53,8 +52,8 @@ pub fn read_crates(diag: @span_handler,
5352
.. *visit::default_simple_visitor()});
5453
visit_crate(e, crate);
5554
visit::visit_crate(crate, ((), v));
56-
dump_crates(e.crate_cache);
57-
warn_if_multiple_versions(e, diag, e.crate_cache);
55+
dump_crates(*e.crate_cache);
56+
warn_if_multiple_versions(e, diag, *e.crate_cache);
5857
}
5958

6059
struct cache_entry {
@@ -64,7 +63,7 @@ struct cache_entry {
6463
metas: @~[@ast::meta_item]
6564
}
6665

67-
fn dump_crates(crate_cache: @mut ~[cache_entry]) {
66+
fn dump_crates(crate_cache: &[cache_entry]) {
6867
debug!("resolved crates:");
6968
for crate_cache.iter().advance |entry| {
7069
debug!("cnum: %?", entry.cnum);
@@ -75,11 +74,9 @@ fn dump_crates(crate_cache: @mut ~[cache_entry]) {
7574

7675
fn warn_if_multiple_versions(e: @mut Env,
7776
diag: @span_handler,
78-
crate_cache: @mut ~[cache_entry]) {
77+
crate_cache: &[cache_entry]) {
7978
use core::either::*;
8079

81-
let crate_cache = &mut *crate_cache;
82-
8380
if crate_cache.len() != 0u {
8481
let name = loader::crate_name_from_metas(
8582
*crate_cache[crate_cache.len() - 1].metas
@@ -111,7 +108,7 @@ fn warn_if_multiple_versions(e: @mut Env,
111108
}
112109
}
113110

114-
warn_if_multiple_versions(e, diag, @mut non_matches);
111+
warn_if_multiple_versions(e, diag, non_matches);
115112
}
116113
}
117114

@@ -126,7 +123,7 @@ struct Env {
126123
intr: @ident_interner
127124
}
128125

129-
fn visit_crate(e: @mut Env, c: &ast::crate) {
126+
fn visit_crate(e: &Env, c: &ast::crate) {
130127
let cstore = e.cstore;
131128
let link_args = attr::find_attrs_by_name(c.node.attrs, "link_args");
132129

@@ -152,7 +149,7 @@ fn visit_view_item(e: @mut Env, i: @ast::view_item) {
152149
}
153150
}
154151

155-
fn visit_item(e: @mut Env, i: @ast::item) {
152+
fn visit_item(e: &Env, i: @ast::item) {
156153
match i.node {
157154
ast::item_foreign_mod(ref fm) => {
158155
if fm.abis.is_rust() || fm.abis.is_intrinsic() {
@@ -204,26 +201,25 @@ fn visit_item(e: @mut Env, i: @ast::item) {
204201
}
205202
}
206203

207-
fn metas_with(ident: @str, key: @str, metas: ~[@ast::meta_item])
204+
fn metas_with(ident: @str, key: @str, mut metas: ~[@ast::meta_item])
208205
-> ~[@ast::meta_item] {
209206
let name_items = attr::find_meta_items_by_name(metas, key);
210207
if name_items.is_empty() {
211-
vec::append_one(metas, attr::mk_name_value_item_str(key, ident))
212-
} else {
213-
metas
208+
metas.push(attr::mk_name_value_item_str(key, ident));
214209
}
210+
metas
215211
}
216212

217213
fn metas_with_ident(ident: @str, metas: ~[@ast::meta_item])
218214
-> ~[@ast::meta_item] {
219215
metas_with(ident, @"name", metas)
220216
}
221217

222-
fn existing_match(e: @mut Env, metas: &[@ast::meta_item], hash: @str)
218+
fn existing_match(e: &Env, metas: &[@ast::meta_item], hash: &str)
223219
-> Option<int> {
224220
for e.crate_cache.iter().advance |c| {
225221
if loader::metadata_matches(*c.metas, metas)
226-
&& (hash.is_empty() || c.hash == hash) {
222+
&& (hash.is_empty() || c.hash.as_slice() == hash) {
227223
return Some(c.cnum);
228224
}
229225
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn check_crate(
5858
moves_map: moves::MovesMap,
5959
moved_variables_set: moves::MovedVariablesSet,
6060
capture_map: moves::CaptureMap,
61-
crate: @ast::crate) -> (root_map, write_guard_map)
61+
crate: &ast::crate) -> (root_map, write_guard_map)
6262
{
6363
let bccx = @BorrowckCtxt {
6464
tcx: tcx,
@@ -507,7 +507,7 @@ impl BorrowckCtxt {
507507
pub fn report_use_of_moved_value(&self,
508508
use_span: span,
509509
use_kind: MovedValueUseKind,
510-
lp: @LoanPath,
510+
lp: &LoanPath,
511511
move: &move_data::Move,
512512
moved_lp: @LoanPath) {
513513
let verb = match use_kind {
@@ -570,7 +570,7 @@ impl BorrowckCtxt {
570570

571571
pub fn report_reassigned_immutable_variable(&self,
572572
span: span,
573-
lp: @LoanPath,
573+
lp: &LoanPath,
574574
assign:
575575
&move_data::Assignment) {
576576
self.tcx.sess.span_err(

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax::codemap;
2121
use syntax::{visit, ast_util, ast_map};
2222

2323
pub fn check_crate(sess: Session,
24-
crate: @crate,
24+
crate: &crate,
2525
ast_map: ast_map::map,
2626
def_map: resolve::DefMap,
2727
method_map: typeck::method_map,

src/librustc/middle/check_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Context {
1919
can_ret: bool
2020
}
2121

22-
pub fn check_crate(tcx: ty::ctxt, crate: @crate) {
22+
pub fn check_crate(tcx: ty::ctxt, crate: &crate) {
2323
visit::visit_crate(crate,
2424
(Context { in_loop: false, can_ret: true },
2525
visit::mk_vt(@visit::Visitor {

0 commit comments

Comments
 (0)