Skip to content

Commit 401c80d

Browse files
committed
save-analysis: don't recompute crate name
1 parent 7aec917 commit 401c80d

File tree

9 files changed

+24
-27
lines changed

9 files changed

+24
-27
lines changed

src/librustc/middle/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0;
102102

103103
/// The complete set of all analyses described in this module. This is
104104
/// produced by the driver and fed to trans and later passes.
105-
pub struct CrateAnalysis {
105+
pub struct CrateAnalysis<'a> {
106106
pub export_map: ExportMap,
107107
pub exported_items: middle::privacy::ExportedItems,
108108
pub public_items: middle::privacy::PublicItems,
109109
pub reachable: NodeSet,
110-
pub name: String,
110+
pub name: &'a str,
111111
pub glob_map: Option<GlobMap>,
112112
}
113113

src/librustc_driver/driver.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn compile_input(sess: Session,
143143
phase_3_run_analysis_passes(&sess,
144144
ast_map,
145145
&arenas,
146-
id,
146+
&id,
147147
control.make_glob_map,
148148
|tcx, analysis| {
149149

@@ -155,7 +155,8 @@ pub fn compile_input(sess: Session,
155155
tcx.map.krate(),
156156
&analysis,
157157
tcx,
158-
&lcx);
158+
&lcx,
159+
&id);
159160
(control.after_analysis.callback)(state);
160161

161162
tcx.sess.abort_if_errors();
@@ -279,7 +280,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
279280
pub expanded_crate: Option<&'a ast::Crate>,
280281
pub hir_crate: Option<&'a hir::Crate>,
281282
pub ast_map: Option<&'a hir_map::Map<'ast>>,
282-
pub analysis: Option<&'a ty::CrateAnalysis>,
283+
pub analysis: Option<&'a ty::CrateAnalysis<'a>>,
283284
pub tcx: Option<&'a ty::ctxt<'tcx>>,
284285
pub lcx: Option<&'a LoweringContext<'a>>,
285286
pub trans: Option<&'a trans::CrateTranslation>,
@@ -358,14 +359,16 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
358359
hir_crate: &'a hir::Crate,
359360
analysis: &'a ty::CrateAnalysis,
360361
tcx: &'a ty::ctxt<'tcx>,
361-
lcx: &'a LoweringContext<'a>)
362+
lcx: &'a LoweringContext<'a>,
363+
crate_name: &'a str)
362364
-> CompileState<'a, 'ast, 'tcx> {
363365
CompileState {
364366
analysis: Some(analysis),
365367
tcx: Some(tcx),
366368
krate: Some(krate),
367369
hir_crate: Some(hir_crate),
368370
lcx: Some(lcx),
371+
crate_name: Some(crate_name),
369372
.. CompileState::empty(input, session, out_dir)
370373
}
371374
}
@@ -661,7 +664,7 @@ pub fn make_map<'ast>(sess: &Session,
661664
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
662665
ast_map: front::map::Map<'tcx>,
663666
arenas: &'tcx ty::CtxtArenas<'tcx>,
664-
name: String,
667+
name: &str,
665668
make_glob_map: resolve::MakeGlobMap,
666669
f: F)
667670
-> R

src/librustc_driver/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
399399
state.lcx.unwrap(),
400400
state.krate.unwrap(),
401401
state.analysis.unwrap(),
402+
state.crate_name.unwrap(),
402403
state.out_dir));
403404
};
404405
control.make_glob_map = resolve::MakeGlobMap::Yes;

src/librustc_driver/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl PpSourceMode {
158158
sess: &'tcx Session,
159159
ast_map: &hir_map::Map<'tcx>,
160160
arenas: &'tcx ty::CtxtArenas<'tcx>,
161-
id: String,
161+
id: &str,
162162
payload: B,
163163
f: F) -> A where
164164
F: FnOnce(&HirPrinterSupport, B, &hir::Crate) -> A,
@@ -713,7 +713,7 @@ pub fn pretty_print_input(sess: Session,
713713
(PpmHir(s), None) => {
714714
let out: &mut Write = &mut out;
715715
s.call_with_pp_support_hir(
716-
&sess, &ast_map.unwrap(), &arenas, id, box out, |annotation, out, krate| {
716+
&sess, &ast_map.unwrap(), &arenas, &id, box out, |annotation, out, krate| {
717717
debug!("pretty printing source code {:?}", s);
718718
let sess = annotation.sess();
719719
pprust_hir::print_crate(sess.codemap(),
@@ -732,7 +732,7 @@ pub fn pretty_print_input(sess: Session,
732732
s.call_with_pp_support_hir(&sess,
733733
&ast_map.unwrap(),
734734
&arenas,
735-
id,
735+
&id,
736736
(out,uii),
737737
|annotation, (out,uii), _| {
738738
debug!("pretty printing source code {:?}", s);
@@ -780,7 +780,7 @@ pub fn pretty_print_input(sess: Session,
780780
driver::phase_3_run_analysis_passes(&sess,
781781
ast_map,
782782
&arenas,
783-
id,
783+
&id,
784784
resolve::MakeGlobMap::No,
785785
|tcx, _| {
786786
print_flowgraph(variants, tcx, code, mode, out)

src/librustc_trans/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ pub fn find_crate_name(sess: Option<&Session>,
184184
}
185185

186186
pub fn build_link_meta(sess: &Session, krate: &hir::Crate,
187-
name: String) -> LinkMeta {
187+
name: &str) -> LinkMeta {
188188
let r = LinkMeta {
189-
crate_name: name,
189+
crate_name: name.to_owned(),
190190
crate_hash: Svh::calculate(&sess.opts.cg.metadata, krate),
191191
};
192192
info!("{:?}", r);

src/librustc_trans/save/dump_csv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
6666
save_ctxt: SaveContext<'l, 'tcx>,
6767
sess: &'l Session,
6868
tcx: &'l ty::ctxt<'tcx>,
69-
analysis: &'l ty::CrateAnalysis,
69+
analysis: &'l ty::CrateAnalysis<'l>,
7070

7171
span: SpanUtils<'l>,
7272
fmt: FmtStrs<'l, 'tcx>,
@@ -77,7 +77,7 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
7777
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
7878
pub fn new(tcx: &'l ty::ctxt<'tcx>,
7979
lcx: &'l LoweringContext<'l>,
80-
analysis: &'l ty::CrateAnalysis,
80+
analysis: &'l ty::CrateAnalysis<'l>,
8181
output_file: Box<File>)
8282
-> DumpCsvVisitor<'l, 'tcx> {
8383
let span_utils = SpanUtils::new(&tcx.sess);

src/librustc_trans/save/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_front;
2020
use rustc::front::map::NodeItem;
2121
use rustc_front::{hir, lowering};
2222

23-
use syntax::attr;
2423
use syntax::ast::{self, NodeId};
2524
use syntax::ast_util;
2625
use syntax::codemap::*;
@@ -714,19 +713,13 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>,
714713
lcx: &'l lowering::LoweringContext<'l>,
715714
krate: &ast::Crate,
716715
analysis: &ty::CrateAnalysis,
716+
cratename: &str,
717717
odir: Option<&Path>) {
718718
if generated_code(krate.span) {
719719
return;
720720
}
721721

722722
assert!(analysis.glob_map.is_some());
723-
let cratename = match attr::find_crate_name(&krate.attrs) {
724-
Some(name) => name.to_string(),
725-
None => {
726-
info!("Could not find crate name, using 'unknown_crate'");
727-
String::from("unknown_crate")
728-
}
729-
};
730723

731724
info!("Dumping crate {}", cratename);
732725

@@ -751,7 +744,7 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>,
751744
}
752745

753746
// Create output file.
754-
let mut out_name = cratename.clone();
747+
let mut out_name = cratename.to_owned();
755748
out_name.push_str(".csv");
756749
root_path.push(&out_name);
757750
let output_file = match File::create(&root_path) {
@@ -765,7 +758,7 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>,
765758

766759
let mut visitor = dump_csv::DumpCsvVisitor::new(tcx, lcx, analysis, output_file);
767760

768-
visitor.dump_crate_info(&cratename, krate);
761+
visitor.dump_crate_info(cratename, krate);
769762
visit::walk_crate(&mut visitor, krate);
770763
}
771764

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
143143
driver::phase_3_run_analysis_passes(&sess,
144144
hir_map,
145145
&arenas,
146-
name,
146+
&name,
147147
resolve::MakeGlobMap::No,
148148
|tcx, analysis| {
149149
let ty::CrateAnalysis { exported_items, public_items, .. } = analysis;

src/test/run-make/execution-engine/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn compile_program(input: &str, sysroot: PathBuf)
229229
let ast_map = driver::make_map(&sess, &mut hir_forest);
230230

231231
driver::phase_3_run_analysis_passes(
232-
&sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
232+
&sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, analysis| {
233233

234234
let trans = driver::phase_4_translate_to_llvm(tcx, analysis);
235235

0 commit comments

Comments
 (0)