From e6d6c379685243a877d52f05afd5e04129674194 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Thu, 5 May 2016 08:54:18 +0000 Subject: [PATCH] Reimplement pretty printing --- src/librustc/hir/mod.rs | 1 + src/librustc/ty/mod.rs | 1 + src/librustc_driver/driver.rs | 9 +++++++++ src/librustc_driver/lib.rs | 2 ++ src/librustc_driver/pretty.rs | 29 ++++++++++++++++++----------- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 68e3e742d031..97c438838190 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1639,6 +1639,7 @@ pub type FreevarMap = NodeMap>; pub type CaptureModeMap = NodeMap; +#[derive(Clone)] pub struct TraitCandidate { pub def_id: DefId, pub import_id: Option, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 174f626498b1..700ed62f216d 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -108,6 +108,7 @@ pub type Disr = ConstInt; /// The complete set of all analyses described in this module. This is /// produced by the driver and fed to trans and later passes. +#[derive(Clone)] pub struct CrateAnalysis<'a> { pub export_map: ExportMap, pub access_levels: middle::privacy::AccessLevels, diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index ebb6cf709ce7..1c20f0f2f394 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -61,6 +61,7 @@ use syntax::visit; use syntax; use syntax_ext; +#[derive(Clone)] pub struct Resolutions { pub def_map: RefCell, pub freevars: FreevarMap, @@ -209,6 +210,8 @@ pub fn compile_input(sess: &Session, &arenas, &cstore, &hir_map, + &analysis, + &resolutions, &expanded_crate, &hir_map.krate(), &id), @@ -384,6 +387,7 @@ pub struct CompileState<'a, 'b, 'ast: 'a, 'tcx: 'b> where 'ast: 'tcx { pub expanded_crate: Option<&'a ast::Crate>, pub hir_crate: Option<&'a hir::Crate>, pub ast_map: Option<&'a hir_map::Map<'ast>>, + pub resolutions: Option<&'a Resolutions>, pub mir_map: Option<&'b MirMap<'tcx>>, pub analysis: Option<&'a ty::CrateAnalysis<'a>>, pub tcx: Option<&'b TyCtxt<'tcx>>, @@ -408,6 +412,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { expanded_crate: None, hir_crate: None, ast_map: None, + resolutions: None, analysis: None, mir_map: None, tcx: None, @@ -454,6 +459,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { arenas: &'ast ty::CtxtArenas<'ast>, cstore: &'a CStore, hir_map: &'a hir_map::Map<'ast>, + analysis: &'a ty::CrateAnalysis, + resolutions: &'a Resolutions, krate: &'a ast::Crate, hir_crate: &'a hir::Crate, crate_name: &'a str) @@ -463,6 +470,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> { arenas: Some(arenas), cstore: Some(cstore), ast_map: Some(hir_map), + analysis: Some(analysis), + resolutions: Some(resolutions), expanded_crate: Some(krate), hir_crate: Some(hir_crate), out_file: out_file.as_ref().map(|s| &**s), diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 299a20c1a0de..4da36be94e00 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -469,6 +469,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { control.after_write_deps.callback = box move |state| { pretty::print_after_write_deps(state.session, state.ast_map.unwrap(), + state.analysis.unwrap(), + state.resolutions.unwrap(), state.input, &state.expanded_crate.take().unwrap(), state.crate_name.unwrap(), diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index f4a8a766c8e3..8d8984000c7e 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -15,7 +15,8 @@ pub use self::PpSourceMode::*; pub use self::PpMode::*; use self::NodesMatchingUII::*; -use {driver, abort_on_err}; +use abort_on_err; +use driver::{self, Resolutions}; use rustc::dep_graph::DepGraph; use rustc::ty::{self, TyCtxt}; @@ -25,7 +26,6 @@ use rustc::session::Session; use rustc::session::config::Input; use rustc_borrowck as borrowck; use rustc_borrowck::graphviz as borrowck_dot; -use rustc_resolve as resolve; use rustc_mir::pretty::write_mir_pretty; use rustc_mir::graphviz::write_mir_graphviz; @@ -202,6 +202,8 @@ impl PpSourceMode { fn call_with_pp_support_hir<'tcx, A, B, F>(&self, sess: &'tcx Session, ast_map: &hir_map::Map<'tcx>, + analysis: &ty::CrateAnalysis, + resolutions: &Resolutions, arenas: &'tcx ty::CtxtArenas<'tcx>, id: &str, payload: B, @@ -226,12 +228,12 @@ impl PpSourceMode { f(&annotation, payload, ast_map.forest.krate()) } PpmTyped => { - /* abort_on_err(driver::phase_3_run_analysis_passes(sess, ast_map.clone(), + analysis.clone(), + resolutions.clone(), arenas, id, - resolve::MakeGlobMap::No, |tcx, _, _, _| { let annotation = TypedAnnotation { tcx: tcx, @@ -241,8 +243,6 @@ impl PpSourceMode { payload, ast_map.forest.krate()) }), sess) - */ - unimplemented!() } _ => panic!("Should use call_with_pp_support"), } @@ -814,6 +814,8 @@ pub fn print_after_parsing(sess: &Session, pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, ast_map: &hir_map::Map<'tcx>, + analysis: &ty::CrateAnalysis, + resolutions: &Resolutions, input: &Input, krate: &ast::Crate, crate_name: &str, @@ -825,7 +827,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, let _ignore = dep_graph.in_ignore(); if ppm.needs_analysis() { - print_with_analysis(sess, ast_map, crate_name, arenas, ppm, opt_uii, ofile); + print_with_analysis(sess, ast_map, analysis, resolutions, + crate_name, arenas, ppm, opt_uii, ofile); return; } @@ -856,6 +859,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, let out: &mut Write = &mut out; s.call_with_pp_support_hir(sess, ast_map, + analysis, + resolutions, arenas, crate_name, box out, @@ -877,6 +882,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, let out: &mut Write = &mut out; s.call_with_pp_support_hir(sess, ast_map, + analysis, + resolutions, arenas, crate_name, (out,uii), @@ -917,6 +924,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session, // Instead, we call that function ourselves. fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, ast_map: &hir_map::Map<'tcx>, + analysis: &ty::CrateAnalysis, + resolutions: &Resolutions, crate_name: &str, arenas: &'tcx ty::CtxtArenas<'tcx>, ppm: PpMode, @@ -930,14 +939,14 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, None }; - /* let mut out = Vec::new(); abort_on_err(driver::phase_3_run_analysis_passes(sess, ast_map.clone(), + analysis.clone(), + resolutions.clone(), arenas, crate_name, - resolve::MakeGlobMap::No, |tcx, mir_map, _, _| { match ppm { PpmMir | PpmMirCFG => { @@ -1002,6 +1011,4 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, }), sess).unwrap(); write_output(out, ofile); - */ - unimplemented!() }