auto merge of #9717 : blake2-ppc/rust/rustc-static-str, r=alexcrichton
rustc: Use static strings in a few literals Avoid allocating extra copies of strings by using "" instead of ~"" for the debug options list and for the `time` function. This is a small change, but it is in a path that's always executed.
This commit is contained in:
commit
c5295f9c47
6 changed files with 90 additions and 91 deletions
|
@ -1007,9 +1007,9 @@ pub fn link_args(sess: Session,
|
|||
continue;
|
||||
}
|
||||
let dir = cratepath.dirname();
|
||||
if dir != ~"" { args.push(~"-L" + dir); }
|
||||
if !dir.is_empty() { args.push("-L" + dir); }
|
||||
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned());
|
||||
args.push(~"-l" + libarg);
|
||||
args.push("-l" + libarg);
|
||||
}
|
||||
|
||||
let ula = cstore::get_used_link_args(cstore);
|
||||
|
@ -1032,12 +1032,12 @@ pub fn link_args(sess: Session,
|
|||
// forces to make sure that library can be found at runtime.
|
||||
|
||||
for path in sess.opts.addl_lib_search_paths.iter() {
|
||||
args.push(~"-L" + path.to_str());
|
||||
args.push("-L" + path.to_str());
|
||||
}
|
||||
|
||||
let rustpath = filesearch::rust_path();
|
||||
for path in rustpath.iter() {
|
||||
args.push(~"-L" + path.to_str());
|
||||
args.push("-L" + path.to_str());
|
||||
}
|
||||
|
||||
// The names of the extern libraries
|
||||
|
@ -1050,7 +1050,7 @@ pub fn link_args(sess: Session,
|
|||
// On mac we need to tell the linker to let this library
|
||||
// be rpathed
|
||||
if sess.targ_cfg.os == session::OsMacos {
|
||||
args.push(~"-Wl,-install_name,@rpath/"
|
||||
args.push("-Wl,-install_name,@rpath/"
|
||||
+ output.filename().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ pub enum input {
|
|||
|
||||
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input)
|
||||
-> ast::Crate {
|
||||
time(sess.time_passes(), ~"parsing", (), |_| {
|
||||
time(sess.time_passes(), "parsing", (), |_| {
|
||||
match *input {
|
||||
file_input(ref file) => {
|
||||
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
|
||||
|
@ -167,29 +167,29 @@ pub fn phase_2_configure_and_expand(sess: Session,
|
|||
// mod bar { macro_rules! baz!(() => {{}}) }
|
||||
//
|
||||
// baz! should not use this definition unless foo is enabled.
|
||||
crate = time(time_passes, ~"std macros injection", crate, |crate|
|
||||
crate = time(time_passes, "std macros injection", crate, |crate|
|
||||
syntax::ext::expand::inject_std_macros(sess.parse_sess,
|
||||
cfg.clone(),
|
||||
crate));
|
||||
|
||||
crate = time(time_passes, ~"configuration 1", crate, |crate|
|
||||
crate = time(time_passes, "configuration 1", crate, |crate|
|
||||
front::config::strip_unconfigured_items(crate));
|
||||
|
||||
crate = time(time_passes, ~"expansion", crate, |crate|
|
||||
crate = time(time_passes, "expansion", crate, |crate|
|
||||
syntax::ext::expand::expand_crate(sess.parse_sess, cfg.clone(),
|
||||
crate));
|
||||
|
||||
// strip again, in case expansion added anything with a #[cfg].
|
||||
crate = time(time_passes, ~"configuration 2", crate, |crate|
|
||||
crate = time(time_passes, "configuration 2", crate, |crate|
|
||||
front::config::strip_unconfigured_items(crate));
|
||||
|
||||
crate = time(time_passes, ~"maybe building test harness", crate, |crate|
|
||||
crate = time(time_passes, "maybe building test harness", crate, |crate|
|
||||
front::test::modify_for_testing(sess, crate));
|
||||
|
||||
crate = time(time_passes, ~"std injection", crate, |crate|
|
||||
crate = time(time_passes, "std injection", crate, |crate|
|
||||
front::std_inject::maybe_inject_libstd_ref(sess, crate));
|
||||
|
||||
crate = time(time_passes, ~"assigning node ids", crate, |crate|
|
||||
crate = time(time_passes, "assigning node ids", crate, |crate|
|
||||
front::assign_node_ids::assign_node_ids(sess, crate));
|
||||
|
||||
return crate;
|
||||
|
@ -211,17 +211,17 @@ pub fn phase_3_run_analysis_passes(sess: Session,
|
|||
|
||||
let time_passes = sess.time_passes();
|
||||
|
||||
let ast_map = time(time_passes, ~"ast indexing", (), |_|
|
||||
let ast_map = time(time_passes, "ast indexing", (), |_|
|
||||
syntax::ast_map::map_crate(sess.diagnostic(), crate));
|
||||
|
||||
time(time_passes, ~"external crate/lib resolution", (), |_|
|
||||
time(time_passes, "external crate/lib resolution", (), |_|
|
||||
creader::read_crates(sess.diagnostic(), crate, sess.cstore,
|
||||
sess.filesearch,
|
||||
session::sess_os_to_meta_os(sess.targ_cfg.os),
|
||||
sess.opts.is_static,
|
||||
token::get_ident_interner()));
|
||||
|
||||
let lang_items = time(time_passes, ~"language item collection", (), |_|
|
||||
let lang_items = time(time_passes, "language item collection", (), |_|
|
||||
middle::lang_items::collect_language_items(crate, sess));
|
||||
|
||||
let middle::resolve::CrateMap {
|
||||
|
@ -229,19 +229,19 @@ pub fn phase_3_run_analysis_passes(sess: Session,
|
|||
exp_map2: exp_map2,
|
||||
trait_map: trait_map
|
||||
} =
|
||||
time(time_passes, ~"resolution", (), |_|
|
||||
time(time_passes, "resolution", (), |_|
|
||||
middle::resolve::resolve_crate(sess, lang_items, crate));
|
||||
|
||||
time(time_passes, ~"looking for entry point", (),
|
||||
time(time_passes, "looking for entry point", (),
|
||||
|_| middle::entry::find_entry_point(sess, crate, ast_map));
|
||||
|
||||
let freevars = time(time_passes, ~"freevar finding", (), |_|
|
||||
let freevars = time(time_passes, "freevar finding", (), |_|
|
||||
freevars::annotate_freevars(def_map, crate));
|
||||
|
||||
let region_map = time(time_passes, ~"region resolution", (), |_|
|
||||
let region_map = time(time_passes, "region resolution", (), |_|
|
||||
middle::region::resolve_crate(sess, def_map, crate));
|
||||
|
||||
let rp_set = time(time_passes, ~"region parameterization inference", (), |_|
|
||||
let rp_set = time(time_passes, "region parameterization inference", (), |_|
|
||||
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
|
||||
|
||||
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
|
||||
|
@ -252,53 +252,53 @@ pub fn phase_3_run_analysis_passes(sess: Session,
|
|||
ty_cx, trait_map, crate);
|
||||
|
||||
// These next two const passes can probably be merged
|
||||
time(time_passes, ~"const marking", (), |_|
|
||||
time(time_passes, "const marking", (), |_|
|
||||
middle::const_eval::process_crate(crate, ty_cx));
|
||||
|
||||
time(time_passes, ~"const checking", (), |_|
|
||||
time(time_passes, "const checking", (), |_|
|
||||
middle::check_const::check_crate(sess, crate, ast_map, def_map,
|
||||
method_map, ty_cx));
|
||||
|
||||
let exported_items =
|
||||
time(time_passes, ~"privacy checking", (), |_|
|
||||
time(time_passes, "privacy checking", (), |_|
|
||||
middle::privacy::check_crate(ty_cx, &method_map, &exp_map2, crate));
|
||||
|
||||
time(time_passes, ~"effect checking", (), |_|
|
||||
time(time_passes, "effect checking", (), |_|
|
||||
middle::effect::check_crate(ty_cx, method_map, crate));
|
||||
|
||||
time(time_passes, ~"loop checking", (), |_|
|
||||
time(time_passes, "loop checking", (), |_|
|
||||
middle::check_loop::check_crate(ty_cx, crate));
|
||||
|
||||
time(time_passes, ~"stack checking", (), |_|
|
||||
time(time_passes, "stack checking", (), |_|
|
||||
middle::stack_check::stack_check_crate(ty_cx, crate));
|
||||
|
||||
let middle::moves::MoveMaps {moves_map, moved_variables_set,
|
||||
capture_map} =
|
||||
time(time_passes, ~"compute moves", (), |_|
|
||||
time(time_passes, "compute moves", (), |_|
|
||||
middle::moves::compute_moves(ty_cx, method_map, crate));
|
||||
|
||||
time(time_passes, ~"match checking", (), |_|
|
||||
time(time_passes, "match checking", (), |_|
|
||||
middle::check_match::check_crate(ty_cx, method_map,
|
||||
moves_map, crate));
|
||||
|
||||
time(time_passes, ~"liveness checking", (), |_|
|
||||
time(time_passes, "liveness checking", (), |_|
|
||||
middle::liveness::check_crate(ty_cx, method_map,
|
||||
capture_map, crate));
|
||||
|
||||
let (root_map, write_guard_map) =
|
||||
time(time_passes, ~"borrow checking", (), |_|
|
||||
time(time_passes, "borrow checking", (), |_|
|
||||
middle::borrowck::check_crate(ty_cx, method_map,
|
||||
moves_map, moved_variables_set,
|
||||
capture_map, crate));
|
||||
|
||||
time(time_passes, ~"kind checking", (), |_|
|
||||
time(time_passes, "kind checking", (), |_|
|
||||
kind::check_crate(ty_cx, method_map, crate));
|
||||
|
||||
let reachable_map =
|
||||
time(time_passes, ~"reachability checking", (), |_|
|
||||
time(time_passes, "reachability checking", (), |_|
|
||||
reachable::find_reachable(ty_cx, method_map, crate));
|
||||
|
||||
time(time_passes, ~"lint checking", (), |_|
|
||||
time(time_passes, "lint checking", (), |_|
|
||||
lint::check_crate(ty_cx, crate));
|
||||
|
||||
CrateAnalysis {
|
||||
|
@ -328,7 +328,7 @@ pub fn phase_4_translate_to_llvm(sess: Session,
|
|||
crate: ast::Crate,
|
||||
analysis: &CrateAnalysis,
|
||||
outputs: &OutputFilenames) -> CrateTranslation {
|
||||
time(sess.time_passes(), ~"translation", crate, |crate|
|
||||
time(sess.time_passes(), "translation", crate, |crate|
|
||||
trans::base::trans_crate(sess, crate, analysis,
|
||||
&outputs.obj_filename))
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
|
|||
let output_type = link::output_type_assembly;
|
||||
let asm_filename = outputs.obj_filename.with_filetype("s");
|
||||
|
||||
time(sess.time_passes(), ~"LLVM passes", (), |_|
|
||||
time(sess.time_passes(), "LLVM passes", (), |_|
|
||||
link::write::run_passes(sess,
|
||||
trans.context,
|
||||
trans.module,
|
||||
|
@ -363,7 +363,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
|
|||
os::remove_file(&asm_filename);
|
||||
}
|
||||
} else {
|
||||
time(sess.time_passes(), ~"LLVM passes", (), |_|
|
||||
time(sess.time_passes(), "LLVM passes", (), |_|
|
||||
link::write::run_passes(sess,
|
||||
trans.context,
|
||||
trans.module,
|
||||
|
@ -377,7 +377,7 @@ pub fn phase_5_run_llvm_passes(sess: Session,
|
|||
pub fn phase_6_link_output(sess: Session,
|
||||
trans: &CrateTranslation,
|
||||
outputs: &OutputFilenames) {
|
||||
time(sess.time_passes(), ~"linking", (), |_|
|
||||
time(sess.time_passes(), "linking", (), |_|
|
||||
link::link_binary(sess,
|
||||
&outputs.obj_filename,
|
||||
&outputs.out_filename,
|
||||
|
@ -596,12 +596,12 @@ pub fn build_target_config(sopts: @session::options,
|
|||
-> @session::config {
|
||||
let os = match get_os(sopts.target_triple) {
|
||||
Some(os) => os,
|
||||
None => early_error(demitter, ~"unknown operating system")
|
||||
None => early_error(demitter, "unknown operating system")
|
||||
};
|
||||
let arch = match get_arch(sopts.target_triple) {
|
||||
Some(arch) => arch,
|
||||
None => early_error(demitter,
|
||||
~"unknown architecture: " + sopts.target_triple)
|
||||
"unknown architecture: " + sopts.target_triple)
|
||||
};
|
||||
let (int_type, uint_type) = match arch {
|
||||
abi::X86 => (ast::ty_i32, ast::ty_u32),
|
||||
|
@ -686,7 +686,7 @@ pub fn build_session_options(binary: @str,
|
|||
let mut this_bit = 0u;
|
||||
for tuple in debug_map.iter() {
|
||||
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
|
||||
if name == debug_flag { this_bit = bit; break; }
|
||||
if *name == *debug_flag { this_bit = bit; break; }
|
||||
}
|
||||
if this_bit == 0u {
|
||||
early_error(demitter, format!("unknown debug flag: {}", *debug_flag))
|
||||
|
@ -726,7 +726,7 @@ pub fn build_session_options(binary: @str,
|
|||
No
|
||||
} else if matches.opt_present("O") {
|
||||
if matches.opt_present("opt-level") {
|
||||
early_error(demitter, ~"-O and --opt-level both provided");
|
||||
early_error(demitter, "-O and --opt-level both provided");
|
||||
}
|
||||
Default
|
||||
} else if matches.opt_present("opt-level") {
|
||||
|
@ -736,7 +736,7 @@ pub fn build_session_options(binary: @str,
|
|||
~"2" => Default,
|
||||
~"3" => Aggressive,
|
||||
_ => {
|
||||
early_error(demitter, ~"optimization level needs to be between 0-3")
|
||||
early_error(demitter, "optimization level needs to be between 0-3")
|
||||
}
|
||||
}
|
||||
} else { No }
|
||||
|
@ -1030,7 +1030,7 @@ pub fn build_output_filenames(input: &input,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn early_error(emitter: @diagnostic::Emitter, msg: ~str) -> ! {
|
||||
pub fn early_error(emitter: @diagnostic::Emitter, msg: &str) -> ! {
|
||||
emitter.emit(None, msg, diagnostic::fatal);
|
||||
fail2!();
|
||||
}
|
||||
|
|
|
@ -81,61 +81,60 @@ pub static no_vectorize_slp: uint = 1 << 28;
|
|||
pub static no_prepopulate_passes: uint = 1 << 29;
|
||||
pub static use_softfp: uint = 1 << 30;
|
||||
|
||||
pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
|
||||
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
|
||||
(~"time-passes", ~"measure time of each rustc pass", time_passes),
|
||||
(~"count-llvm-insns", ~"count where LLVM \
|
||||
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
|
||||
~[("verbose", "in general, enable more debug printouts", verbose),
|
||||
("time-passes", "measure time of each rustc pass", time_passes),
|
||||
("count-llvm-insns", "count where LLVM \
|
||||
instrs originate", count_llvm_insns),
|
||||
(~"time-llvm-passes", ~"measure time of each LLVM pass",
|
||||
("time-llvm-passes", "measure time of each LLVM pass",
|
||||
time_llvm_passes),
|
||||
(~"trans-stats", ~"gather trans statistics", trans_stats),
|
||||
(~"asm-comments", ~"generate comments into the assembly (may change behavior)", asm_comments),
|
||||
(~"no-verify", ~"skip LLVM verification", no_verify),
|
||||
(~"trace", ~"emit trace logs", trace),
|
||||
(~"coherence", ~"perform coherence checking", coherence),
|
||||
(~"borrowck-stats", ~"gather borrowck statistics", borrowck_stats),
|
||||
(~"borrowck-note-pure", ~"note where purity is req'd",
|
||||
("trans-stats", "gather trans statistics", trans_stats),
|
||||
("asm-comments", "generate comments into the assembly (may change behavior)", asm_comments),
|
||||
("no-verify", "skip LLVM verification", no_verify),
|
||||
("trace", "emit trace logs", trace),
|
||||
("coherence", "perform coherence checking", coherence),
|
||||
("borrowck-stats", "gather borrowck statistics", borrowck_stats),
|
||||
("borrowck-note-pure", "note where purity is req'd",
|
||||
borrowck_note_pure),
|
||||
(~"borrowck-note-loan", ~"note where loans are req'd",
|
||||
("borrowck-note-loan", "note where loans are req'd",
|
||||
borrowck_note_loan),
|
||||
(~"no-landing-pads", ~"omit landing pads for unwinding",
|
||||
("no-landing-pads", "omit landing pads for unwinding",
|
||||
no_landing_pads),
|
||||
(~"debug-llvm", ~"enable debug output from LLVM", debug_llvm),
|
||||
(~"count-type-sizes", ~"count the sizes of aggregate types",
|
||||
("debug-llvm", "enable debug output from LLVM", debug_llvm),
|
||||
("count-type-sizes", "count the sizes of aggregate types",
|
||||
count_type_sizes),
|
||||
(~"meta-stats", ~"gather metadata statistics", meta_stats),
|
||||
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
|
||||
(~"print-link-args", ~"Print the arguments passed to the linker", print_link_args),
|
||||
(~"gc", ~"Garbage collect shared data (experimental)", gc),
|
||||
(~"jit", ~"Execute using JIT (experimental)", jit),
|
||||
(~"extra-debug-info", ~"Extra debugging info (experimental)",
|
||||
("meta-stats", "gather metadata statistics", meta_stats),
|
||||
("no-opt", "do not optimize, even if -O is passed", no_opt),
|
||||
("print-link-args", "Print the arguments passed to the linker", print_link_args),
|
||||
("gc", "Garbage collect shared data (experimental)", gc),
|
||||
("jit", "Execute using JIT (experimental)", jit),
|
||||
("extra-debug-info", "Extra debugging info (experimental)",
|
||||
extra_debug_info),
|
||||
(~"debug-info", ~"Produce debug info (experimental)", debug_info),
|
||||
(~"static", ~"Use or produce static libraries or binaries " +
|
||||
"(experimental)", statik),
|
||||
(~"no-debug-borrows",
|
||||
~"do not show where borrow checks fail",
|
||||
("debug-info", "Produce debug info (experimental)", debug_info),
|
||||
("static", "Use or produce static libraries or binaries (experimental)", statik),
|
||||
("no-debug-borrows",
|
||||
"do not show where borrow checks fail",
|
||||
no_debug_borrows),
|
||||
(~"lint-llvm",
|
||||
~"Run the LLVM lint pass on the pre-optimization IR",
|
||||
("lint-llvm",
|
||||
"Run the LLVM lint pass on the pre-optimization IR",
|
||||
lint_llvm),
|
||||
(~"once-fns",
|
||||
~"Allow 'once fn' closures to deinitialize captured variables",
|
||||
("once-fns",
|
||||
"Allow 'once fn' closures to deinitialize captured variables",
|
||||
once_fns),
|
||||
(~"print-llvm-passes",
|
||||
~"Prints the llvm optimization passes being run",
|
||||
("print-llvm-passes",
|
||||
"Prints the llvm optimization passes being run",
|
||||
print_llvm_passes),
|
||||
(~"no-prepopulate-passes",
|
||||
~"Don't pre-populate the pass managers with a list of passes, only use \
|
||||
("no-prepopulate-passes",
|
||||
"Don't pre-populate the pass managers with a list of passes, only use \
|
||||
the passes from --passes",
|
||||
no_prepopulate_passes),
|
||||
(~"no-vectorize-loops",
|
||||
~"Don't run the loop vectorization optimization passes",
|
||||
("no-vectorize-loops",
|
||||
"Don't run the loop vectorization optimization passes",
|
||||
no_vectorize_loops),
|
||||
(~"no-vectorize-slp",
|
||||
~"Don't run LLVM's SLP vectorization passes",
|
||||
("no-vectorize-slp",
|
||||
"Don't run LLVM's SLP vectorization passes",
|
||||
no_vectorize_slp),
|
||||
(~"soft-float", ~"Generate software floating point library calls", use_softfp),
|
||||
("soft-float", "Generate software floating point library calls", use_softfp),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -447,17 +447,17 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
tcx: tcx
|
||||
};
|
||||
|
||||
time(time_passes, ~"type collecting", (), |_|
|
||||
time(time_passes, "type collecting", (), |_|
|
||||
collect::collect_item_types(ccx, crate));
|
||||
|
||||
// this ensures that later parts of type checking can assume that items
|
||||
// have valid types and not error
|
||||
tcx.sess.abort_if_errors();
|
||||
|
||||
time(time_passes, ~"coherence checking", (), |_|
|
||||
time(time_passes, "coherence checking", (), |_|
|
||||
coherence::check_coherence(ccx, crate));
|
||||
|
||||
time(time_passes, ~"type checking", (), |_|
|
||||
time(time_passes, "type checking", (), |_|
|
||||
check::check_item_types(ccx, crate));
|
||||
|
||||
check_for_entry_fn(ccx);
|
||||
|
|
|
@ -243,7 +243,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
|||
return;
|
||||
}
|
||||
let input = match matches.free.len() {
|
||||
0u => early_error(demitter, ~"no input filename given"),
|
||||
0u => early_error(demitter, "no input filename given"),
|
||||
1u => {
|
||||
let ifile = matches.free[0].as_slice();
|
||||
if "-" == ifile {
|
||||
|
@ -253,7 +253,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
|||
file_input(Path(ifile))
|
||||
}
|
||||
}
|
||||
_ => early_error(demitter, ~"multiple input filenames provided")
|
||||
_ => early_error(demitter, "multiple input filenames provided")
|
||||
};
|
||||
|
||||
let sopts = build_session_options(binary, matches, demitter);
|
||||
|
@ -278,7 +278,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
|||
list_metadata(sess, &(*ifile), io::stdout());
|
||||
}
|
||||
str_input(_) => {
|
||||
early_error(demitter, ~"can not list metadata for stdin");
|
||||
early_error(demitter, "can not list metadata for stdin");
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -17,7 +17,7 @@ use syntax::visit::Visitor;
|
|||
use std::hashmap::HashSet;
|
||||
use extra;
|
||||
|
||||
pub fn time<T, U>(do_it: bool, what: ~str, u: U, f: &fn(U) -> T) -> T {
|
||||
pub fn time<T, U>(do_it: bool, what: &str, u: U, f: &fn(U) -> T) -> T {
|
||||
if !do_it { return f(u); }
|
||||
let start = extra::time::precise_time_s();
|
||||
let rv = f(u);
|
||||
|
|
Loading…
Add table
Reference in a new issue