Skip to content

Commit e6d6c37

Browse files
committed
Reimplement pretty printing
1 parent e5a0dd7 commit e6d6c37

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

src/librustc/hir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,7 @@ pub type FreevarMap = NodeMap<Vec<Freevar>>;
16391639

16401640
pub type CaptureModeMap = NodeMap<CaptureClause>;
16411641

1642+
#[derive(Clone)]
16421643
pub struct TraitCandidate {
16431644
pub def_id: DefId,
16441645
pub import_id: Option<NodeId>,

src/librustc/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub type Disr = ConstInt;
108108

109109
/// The complete set of all analyses described in this module. This is
110110
/// produced by the driver and fed to trans and later passes.
111+
#[derive(Clone)]
111112
pub struct CrateAnalysis<'a> {
112113
pub export_map: ExportMap,
113114
pub access_levels: middle::privacy::AccessLevels,

src/librustc_driver/driver.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use syntax::visit;
6161
use syntax;
6262
use syntax_ext;
6363

64+
#[derive(Clone)]
6465
pub struct Resolutions {
6566
pub def_map: RefCell<DefMap>,
6667
pub freevars: FreevarMap,
@@ -209,6 +210,8 @@ pub fn compile_input(sess: &Session,
209210
&arenas,
210211
&cstore,
211212
&hir_map,
213+
&analysis,
214+
&resolutions,
212215
&expanded_crate,
213216
&hir_map.krate(),
214217
&id),
@@ -384,6 +387,7 @@ pub struct CompileState<'a, 'b, 'ast: 'a, 'tcx: 'b> where 'ast: 'tcx {
384387
pub expanded_crate: Option<&'a ast::Crate>,
385388
pub hir_crate: Option<&'a hir::Crate>,
386389
pub ast_map: Option<&'a hir_map::Map<'ast>>,
390+
pub resolutions: Option<&'a Resolutions>,
387391
pub mir_map: Option<&'b MirMap<'tcx>>,
388392
pub analysis: Option<&'a ty::CrateAnalysis<'a>>,
389393
pub tcx: Option<&'b TyCtxt<'tcx>>,
@@ -408,6 +412,7 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
408412
expanded_crate: None,
409413
hir_crate: None,
410414
ast_map: None,
415+
resolutions: None,
411416
analysis: None,
412417
mir_map: None,
413418
tcx: None,
@@ -454,6 +459,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
454459
arenas: &'ast ty::CtxtArenas<'ast>,
455460
cstore: &'a CStore,
456461
hir_map: &'a hir_map::Map<'ast>,
462+
analysis: &'a ty::CrateAnalysis,
463+
resolutions: &'a Resolutions,
457464
krate: &'a ast::Crate,
458465
hir_crate: &'a hir::Crate,
459466
crate_name: &'a str)
@@ -463,6 +470,8 @@ impl<'a, 'b, 'ast, 'tcx> CompileState<'a, 'b, 'ast, 'tcx> {
463470
arenas: Some(arenas),
464471
cstore: Some(cstore),
465472
ast_map: Some(hir_map),
473+
analysis: Some(analysis),
474+
resolutions: Some(resolutions),
466475
expanded_crate: Some(krate),
467476
hir_crate: Some(hir_crate),
468477
out_file: out_file.as_ref().map(|s| &**s),

src/librustc_driver/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
469469
control.after_write_deps.callback = box move |state| {
470470
pretty::print_after_write_deps(state.session,
471471
state.ast_map.unwrap(),
472+
state.analysis.unwrap(),
473+
state.resolutions.unwrap(),
472474
state.input,
473475
&state.expanded_crate.take().unwrap(),
474476
state.crate_name.unwrap(),

src/librustc_driver/pretty.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub use self::PpSourceMode::*;
1515
pub use self::PpMode::*;
1616
use self::NodesMatchingUII::*;
1717

18-
use {driver, abort_on_err};
18+
use abort_on_err;
19+
use driver::{self, Resolutions};
1920

2021
use rustc::dep_graph::DepGraph;
2122
use rustc::ty::{self, TyCtxt};
@@ -25,7 +26,6 @@ use rustc::session::Session;
2526
use rustc::session::config::Input;
2627
use rustc_borrowck as borrowck;
2728
use rustc_borrowck::graphviz as borrowck_dot;
28-
use rustc_resolve as resolve;
2929

3030
use rustc_mir::pretty::write_mir_pretty;
3131
use rustc_mir::graphviz::write_mir_graphviz;
@@ -202,6 +202,8 @@ impl PpSourceMode {
202202
fn call_with_pp_support_hir<'tcx, A, B, F>(&self,
203203
sess: &'tcx Session,
204204
ast_map: &hir_map::Map<'tcx>,
205+
analysis: &ty::CrateAnalysis,
206+
resolutions: &Resolutions,
205207
arenas: &'tcx ty::CtxtArenas<'tcx>,
206208
id: &str,
207209
payload: B,
@@ -226,12 +228,12 @@ impl PpSourceMode {
226228
f(&annotation, payload, ast_map.forest.krate())
227229
}
228230
PpmTyped => {
229-
/*
230231
abort_on_err(driver::phase_3_run_analysis_passes(sess,
231232
ast_map.clone(),
233+
analysis.clone(),
234+
resolutions.clone(),
232235
arenas,
233236
id,
234-
resolve::MakeGlobMap::No,
235237
|tcx, _, _, _| {
236238
let annotation = TypedAnnotation {
237239
tcx: tcx,
@@ -241,8 +243,6 @@ impl PpSourceMode {
241243
payload,
242244
ast_map.forest.krate())
243245
}), sess)
244-
*/
245-
unimplemented!()
246246
}
247247
_ => panic!("Should use call_with_pp_support"),
248248
}
@@ -814,6 +814,8 @@ pub fn print_after_parsing(sess: &Session,
814814

815815
pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
816816
ast_map: &hir_map::Map<'tcx>,
817+
analysis: &ty::CrateAnalysis,
818+
resolutions: &Resolutions,
817819
input: &Input,
818820
krate: &ast::Crate,
819821
crate_name: &str,
@@ -825,7 +827,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
825827
let _ignore = dep_graph.in_ignore();
826828

827829
if ppm.needs_analysis() {
828-
print_with_analysis(sess, ast_map, crate_name, arenas, ppm, opt_uii, ofile);
830+
print_with_analysis(sess, ast_map, analysis, resolutions,
831+
crate_name, arenas, ppm, opt_uii, ofile);
829832
return;
830833
}
831834

@@ -856,6 +859,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
856859
let out: &mut Write = &mut out;
857860
s.call_with_pp_support_hir(sess,
858861
ast_map,
862+
analysis,
863+
resolutions,
859864
arenas,
860865
crate_name,
861866
box out,
@@ -877,6 +882,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
877882
let out: &mut Write = &mut out;
878883
s.call_with_pp_support_hir(sess,
879884
ast_map,
885+
analysis,
886+
resolutions,
880887
arenas,
881888
crate_name,
882889
(out,uii),
@@ -917,6 +924,8 @@ pub fn print_after_write_deps<'tcx, 'a: 'tcx>(sess: &'a Session,
917924
// Instead, we call that function ourselves.
918925
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
919926
ast_map: &hir_map::Map<'tcx>,
927+
analysis: &ty::CrateAnalysis,
928+
resolutions: &Resolutions,
920929
crate_name: &str,
921930
arenas: &'tcx ty::CtxtArenas<'tcx>,
922931
ppm: PpMode,
@@ -930,14 +939,14 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
930939
None
931940
};
932941

933-
/*
934942
let mut out = Vec::new();
935943

936944
abort_on_err(driver::phase_3_run_analysis_passes(sess,
937945
ast_map.clone(),
946+
analysis.clone(),
947+
resolutions.clone(),
938948
arenas,
939949
crate_name,
940-
resolve::MakeGlobMap::No,
941950
|tcx, mir_map, _, _| {
942951
match ppm {
943952
PpmMir | PpmMirCFG => {
@@ -1002,6 +1011,4 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
10021011
}), sess).unwrap();
10031012

10041013
write_output(out, ofile);
1005-
*/
1006-
unimplemented!()
10071014
}

0 commit comments

Comments
 (0)