Skip to content

Commit

Permalink
save-analysis: don't recompute crate name
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 20, 2015
1 parent 7aec917 commit 401c80d
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/librustc/middle/ty/mod.rs
Expand Up @@ -102,12 +102,12 @@ pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0;

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

Expand Down
13 changes: 8 additions & 5 deletions src/librustc_driver/driver.rs
Expand Up @@ -143,7 +143,7 @@ pub fn compile_input(sess: Session,
phase_3_run_analysis_passes(&sess,
ast_map,
&arenas,
id,
&id,
control.make_glob_map,
|tcx, analysis| {

Expand All @@ -155,7 +155,8 @@ pub fn compile_input(sess: Session,
tcx.map.krate(),
&analysis,
tcx,
&lcx);
&lcx,
&id);
(control.after_analysis.callback)(state);

tcx.sess.abort_if_errors();
Expand Down Expand Up @@ -279,7 +280,7 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
pub expanded_crate: Option<&'a ast::Crate>,
pub hir_crate: Option<&'a hir::Crate>,
pub ast_map: Option<&'a hir_map::Map<'ast>>,
pub analysis: Option<&'a ty::CrateAnalysis>,
pub analysis: Option<&'a ty::CrateAnalysis<'a>>,
pub tcx: Option<&'a ty::ctxt<'tcx>>,
pub lcx: Option<&'a LoweringContext<'a>>,
pub trans: Option<&'a trans::CrateTranslation>,
Expand Down Expand Up @@ -358,14 +359,16 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
hir_crate: &'a hir::Crate,
analysis: &'a ty::CrateAnalysis,
tcx: &'a ty::ctxt<'tcx>,
lcx: &'a LoweringContext<'a>)
lcx: &'a LoweringContext<'a>,
crate_name: &'a str)
-> CompileState<'a, 'ast, 'tcx> {
CompileState {
analysis: Some(analysis),
tcx: Some(tcx),
krate: Some(krate),
hir_crate: Some(hir_crate),
lcx: Some(lcx),
crate_name: Some(crate_name),
.. CompileState::empty(input, session, out_dir)
}
}
Expand Down Expand Up @@ -661,7 +664,7 @@ pub fn make_map<'ast>(sess: &Session,
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
ast_map: front::map::Map<'tcx>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
name: String,
name: &str,
make_glob_map: resolve::MakeGlobMap,
f: F)
-> R
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/lib.rs
Expand Up @@ -399,6 +399,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
state.lcx.unwrap(),
state.krate.unwrap(),
state.analysis.unwrap(),
state.crate_name.unwrap(),
state.out_dir));
};
control.make_glob_map = resolve::MakeGlobMap::Yes;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_driver/pretty.rs
Expand Up @@ -158,7 +158,7 @@ impl PpSourceMode {
sess: &'tcx Session,
ast_map: &hir_map::Map<'tcx>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
id: String,
id: &str,
payload: B,
f: F) -> A where
F: FnOnce(&HirPrinterSupport, B, &hir::Crate) -> A,
Expand Down Expand Up @@ -713,7 +713,7 @@ pub fn pretty_print_input(sess: Session,
(PpmHir(s), None) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(
&sess, &ast_map.unwrap(), &arenas, id, box out, |annotation, out, krate| {
&sess, &ast_map.unwrap(), &arenas, &id, box out, |annotation, out, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust_hir::print_crate(sess.codemap(),
Expand All @@ -732,7 +732,7 @@ pub fn pretty_print_input(sess: Session,
s.call_with_pp_support_hir(&sess,
&ast_map.unwrap(),
&arenas,
id,
&id,
(out,uii),
|annotation, (out,uii), _| {
debug!("pretty printing source code {:?}", s);
Expand Down Expand Up @@ -780,7 +780,7 @@ pub fn pretty_print_input(sess: Session,
driver::phase_3_run_analysis_passes(&sess,
ast_map,
&arenas,
id,
&id,
resolve::MakeGlobMap::No,
|tcx, _| {
print_flowgraph(variants, tcx, code, mode, out)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/back/link.rs
Expand Up @@ -184,9 +184,9 @@ pub fn find_crate_name(sess: Option<&Session>,
}

pub fn build_link_meta(sess: &Session, krate: &hir::Crate,
name: String) -> LinkMeta {
name: &str) -> LinkMeta {
let r = LinkMeta {
crate_name: name,
crate_name: name.to_owned(),
crate_hash: Svh::calculate(&sess.opts.cg.metadata, krate),
};
info!("{:?}", r);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -66,7 +66,7 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
save_ctxt: SaveContext<'l, 'tcx>,
sess: &'l Session,
tcx: &'l ty::ctxt<'tcx>,
analysis: &'l ty::CrateAnalysis,
analysis: &'l ty::CrateAnalysis<'l>,

span: SpanUtils<'l>,
fmt: FmtStrs<'l, 'tcx>,
Expand All @@ -77,7 +77,7 @@ pub struct DumpCsvVisitor<'l, 'tcx: 'l> {
impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
pub fn new(tcx: &'l ty::ctxt<'tcx>,
lcx: &'l LoweringContext<'l>,
analysis: &'l ty::CrateAnalysis,
analysis: &'l ty::CrateAnalysis<'l>,
output_file: Box<File>)
-> DumpCsvVisitor<'l, 'tcx> {
let span_utils = SpanUtils::new(&tcx.sess);
Expand Down
13 changes: 3 additions & 10 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -20,7 +20,6 @@ use rustc_front;
use rustc::front::map::NodeItem;
use rustc_front::{hir, lowering};

use syntax::attr;
use syntax::ast::{self, NodeId};
use syntax::ast_util;
use syntax::codemap::*;
Expand Down Expand Up @@ -714,19 +713,13 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>,
lcx: &'l lowering::LoweringContext<'l>,
krate: &ast::Crate,
analysis: &ty::CrateAnalysis,
cratename: &str,
odir: Option<&Path>) {
if generated_code(krate.span) {
return;
}

assert!(analysis.glob_map.is_some());
let cratename = match attr::find_crate_name(&krate.attrs) {
Some(name) => name.to_string(),
None => {
info!("Could not find crate name, using 'unknown_crate'");
String::from("unknown_crate")
}
};

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

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

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

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

visitor.dump_crate_info(&cratename, krate);
visitor.dump_crate_info(cratename, krate);
visit::walk_crate(&mut visitor, krate);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Expand Up @@ -143,7 +143,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
driver::phase_3_run_analysis_passes(&sess,
hir_map,
&arenas,
name,
&name,
resolve::MakeGlobMap::No,
|tcx, analysis| {
let ty::CrateAnalysis { exported_items, public_items, .. } = analysis;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/execution-engine/test.rs
Expand Up @@ -229,7 +229,7 @@ fn compile_program(input: &str, sysroot: PathBuf)
let ast_map = driver::make_map(&sess, &mut hir_forest);

driver::phase_3_run_analysis_passes(
&sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
&sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, analysis| {

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

Expand Down

0 comments on commit 401c80d

Please sign in to comment.