Skip to content

Commit 869d60d

Browse files
pcwaltonpnkfelix
authored andcommitted
eagerly-bind references to pass into by-value closures.
1 parent 084a47c commit 869d60d

Some content is hidden

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

51 files changed

+1531
-998
lines changed

src/librustc/back/link.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,12 @@ pub mod write {
411411
let mut llvm_c_strs = Vec::new();
412412
let mut llvm_args = Vec::new();
413413
{
414+
let llvm_args_ptr = &mut llvm_args;
415+
let llvm_c_strs_ptr = &mut llvm_c_strs;
414416
let add = |arg: &str| {
415417
let s = arg.to_c_str();
416-
llvm_args.push(s.with_ref(|p| p));
417-
llvm_c_strs.push(s);
418+
llvm_args_ptr.push(s.with_ref(|p| p));
419+
llvm_c_strs_ptr.push(s);
418420
};
419421
add("rustc"); // fake program name
420422
if vectorize_loop { add("-vectorize-loops"); }
@@ -649,7 +651,10 @@ pub fn sanitize(s: &str) -> String {
649651

650652
_ => {
651653
let mut tstr = String::new();
652-
char::escape_unicode(c, |c| tstr.push_char(c));
654+
{
655+
let tstr_ptr = &mut tstr;
656+
char::escape_unicode(c, |c| tstr_ptr.push_char(c));
657+
}
653658
result.push_char('$');
654659
result.push_str(tstr.as_slice().slice_from(1));
655660
}
@@ -976,8 +981,9 @@ fn link_rlib<'a>(sess: &'a Session,
976981
// into the archive.
977982
let bc = obj_filename.with_extension("bc");
978983
let bc_deflated = obj_filename.with_extension("bc.deflate");
984+
let bc_deflated_ptr = &bc_deflated;
979985
match fs::File::open(&bc).read_to_end().and_then(|data| {
980-
fs::File::create(&bc_deflated)
986+
fs::File::create(bc_deflated_ptr)
981987
.write(match flate::deflate_bytes(data.as_slice()) {
982988
Some(compressed) => compressed,
983989
None => sess.fatal("failed to compress bytecode")
@@ -991,8 +997,8 @@ fn link_rlib<'a>(sess: &'a Session,
991997
sess.abort_if_errors()
992998
}
993999
}
994-
a.add_file(&bc_deflated, false);
995-
remove(sess, &bc_deflated);
1000+
a.add_file(bc_deflated_ptr, false);
1001+
remove(sess, bc_deflated_ptr);
9961002
if !sess.opts.cg.save_temps &&
9971003
!sess.opts.output_types.contains(&OutputTypeBitcode) {
9981004
remove(sess, &bc);

src/librustc/driver/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,13 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
403403

404404
pub fn append_configuration(cfg: &mut ast::CrateConfig,
405405
name: InternedString) {
406-
if !cfg.iter().any(|mi| mi.name() == name) {
407-
cfg.push(attr::mk_word_item(name))
406+
{
407+
let name_ptr = &name;
408+
if cfg.iter().any(|mi| mi.name() == *name_ptr) {
409+
return
410+
}
408411
}
412+
cfg.push(attr::mk_word_item(name))
409413
}
410414

411415
pub fn build_configuration(sess: &Session) -> ast::CrateConfig {

src/librustc/driver/driver.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -553,14 +553,15 @@ fn write_out_deps(sess: &Session,
553553
_ => return,
554554
};
555555

556+
let deps_filename_ptr = &deps_filename;
556557
let result = (|| {
557558
// Build a list of files used to compile the output and
558559
// write Makefile-compatible dependency rules
559560
let files: Vec<String> = sess.codemap().files.borrow()
560561
.iter().filter(|fmap| fmap.is_real_file())
561562
.map(|fmap| fmap.name.to_string())
562563
.collect();
563-
let mut file = try!(io::File::create(&deps_filename));
564+
let mut file = try!(io::File::create(deps_filename_ptr));
564565
for path in out_filenames.iter() {
565566
try!(write!(&mut file as &mut Writer,
566567
"{}: {}\n\n", path.display(), files.connect(" ")));
@@ -572,7 +573,7 @@ fn write_out_deps(sess: &Session,
572573
Ok(()) => {}
573574
Err(e) => {
574575
sess.fatal(format!("error writing dependencies to `{}`: {}",
575-
deps_filename.display(), e).as_slice());
576+
deps_filename_ptr.display(), e).as_slice());
576577
}
577578
}
578579
}
@@ -713,21 +714,28 @@ pub fn pretty_print_input(sess: Session,
713714
}
714715
PpmFlowGraph(nodeid) => {
715716
let ast_map = ast_map.expect("--pretty flowgraph missing ast_map");
716-
let node = ast_map.find(nodeid).unwrap_or_else(|| {
717-
sess.fatal(format_strbuf!("--pretty flowgraph couldn't find id: {}",
718-
nodeid).as_slice())
719-
});
720-
let block = match node {
721-
syntax::ast_map::NodeBlock(block) => block,
722-
_ => {
723-
let message = format_strbuf!("--pretty=flowgraph needs block, got {:?}",
724-
node);
725-
726-
// point to what was found, if there's an
727-
// accessible span.
728-
match ast_map.opt_span(nodeid) {
729-
Some(sp) => sess.span_fatal(sp, message.as_slice()),
730-
None => sess.fatal(message.as_slice())
717+
let block = {
718+
let sess_ptr = &sess;
719+
let node = ast_map.find(nodeid).unwrap_or_else(|| {
720+
sess_ptr.fatal(format_strbuf!(
721+
"--pretty flowgraph couldn't find id: {}",
722+
nodeid).as_slice())
723+
});
724+
match node {
725+
syntax::ast_map::NodeBlock(block) => block,
726+
_ => {
727+
let message = format_strbuf!("--pretty=flowgraph \
728+
needs block, got {:?}",
729+
node);
730+
731+
// point to what was found, if there's an
732+
// accessible span.
733+
match ast_map.opt_span(nodeid) {
734+
Some(sp) => {
735+
sess_ptr.span_fatal(sp, message.as_slice())
736+
}
737+
None => sess_ptr.fatal(message.as_slice())
738+
}
731739
}
732740
}
733741
};

src/librustc/driver/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ fn run_compiler(args: &[String]) {
7272
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
7373
let ofile = matches.opt_str("o").map(|o| Path::new(o));
7474

75-
let pretty = matches.opt_default("pretty", "normal").map(|a| {
76-
parse_pretty(&sess, a.as_slice())
77-
});
75+
let pretty = {
76+
let sess_ptr = &sess;
77+
matches.opt_default("pretty", "normal").map(|a| {
78+
parse_pretty(sess_ptr, a.as_slice())
79+
})
80+
};
7881
match pretty {
7982
Some::<PpMode>(ppm) => {
8083
driver::pretty_print_input(sess, cfg, &input, ppm, ofile);

src/librustc/metadata/creader.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ fn dump_crates(cstore: &CStore) {
8282

8383
fn warn_if_multiple_versions(diag: &SpanHandler, cstore: &CStore) {
8484
let mut map = HashMap::new();
85-
cstore.iter_crate_data(|cnum, data| {
86-
let crateid = data.crate_id();
87-
let key = (crateid.name.clone(), crateid.path.clone());
88-
map.find_or_insert_with(key, |_| Vec::new()).push(cnum);
89-
});
85+
{
86+
let map_ptr = &mut map;
87+
cstore.iter_crate_data(|cnum, data| {
88+
let crateid = data.crate_id();
89+
let key = (crateid.name.clone(), crateid.path.clone());
90+
map_ptr.find_or_insert_with(key, |_| Vec::new()).push(cnum);
91+
});
92+
}
9093

9194
for ((name, _), dupes) in map.move_iter() {
9295
if dupes.len() == 1 { continue }
@@ -265,16 +268,19 @@ fn visit_item(e: &Env, i: &ast::Item) {
265268
fn existing_match(e: &Env, crate_id: &CrateId,
266269
hash: Option<&Svh>) -> Option<ast::CrateNum> {
267270
let mut ret = None;
268-
e.sess.cstore.iter_crate_data(|cnum, data| {
269-
let other_id = data.crate_id();
270-
if crate_id.matches(&other_id) {
271-
let other_hash = data.hash();
272-
match hash {
273-
Some(hash) if *hash != other_hash => {}
274-
Some(..) | None => { ret = Some(cnum); }
271+
{
272+
let ret_ptr = &mut ret;
273+
e.sess.cstore.iter_crate_data(|cnum, data| {
274+
let other_id = data.crate_id();
275+
if crate_id.matches(&other_id) {
276+
let other_hash = data.hash();
277+
match hash {
278+
Some(hash) if *hash != other_hash => {}
279+
Some(..) | None => *ret_ptr = Some(cnum),
280+
}
275281
}
276-
}
277-
});
282+
});
283+
}
278284
return ret;
279285
}
280286

@@ -441,9 +447,14 @@ impl<'a> CrateLoader for Loader<'a> {
441447
None => { load_ctxt.report_load_errs(); unreachable!() },
442448
};
443449
let macros = decoder::get_exported_macros(library.metadata.as_slice());
444-
let registrar = decoder::get_macro_registrar_fn(library.metadata.as_slice()).map(|id| {
445-
decoder::get_symbol(library.metadata.as_slice(), id).to_string()
446-
});
450+
let registrar = {
451+
let library_ptr = &library;
452+
decoder::get_macro_registrar_fn(library.metadata.as_slice())
453+
.map(|id| {
454+
decoder::get_symbol(library_ptr.metadata.as_slice(),
455+
id).to_string()
456+
})
457+
};
447458
let mc = MacroCrate {
448459
lib: library.dylib.clone(),
449460
macros: macros.move_iter().map(|x| x.to_string()).collect(),

0 commit comments

Comments
 (0)