2
2
3
3
use rustc:: hir;
4
4
use rustc:: hir:: map as hir_map;
5
- use rustc:: hir:: map:: blocks;
6
5
use rustc:: hir:: print as pprust_hir;
7
6
use rustc:: hir:: def_id:: LOCAL_CRATE ;
8
7
use rustc:: session:: Session ;
9
8
use rustc:: session:: config:: Input ;
10
9
use rustc:: ty:: { self , TyCtxt } ;
11
10
use rustc:: util:: common:: ErrorReported ;
12
11
use rustc_interface:: util:: ReplaceBodyWithLoop ;
13
- use rustc_ast_borrowck as borrowck;
14
- use rustc_ast_borrowck:: graphviz as borrowck_dot;
15
- use rustc_ast_borrowck:: cfg:: { self , graphviz:: LabelledCFG } ;
16
12
use rustc_mir:: util:: { write_mir_pretty, write_mir_graphviz} ;
17
13
18
14
use syntax:: ast;
19
15
use syntax:: mut_visit:: MutVisitor ;
20
16
use syntax:: print:: { pprust} ;
21
17
use syntax_pos:: FileName ;
22
18
23
- use graphviz as dot;
24
-
25
19
use std:: cell:: Cell ;
26
20
use std:: fs:: File ;
27
- use std:: io:: { self , Write } ;
21
+ use std:: io:: Write ;
28
22
use std:: option;
29
23
use std:: path:: Path ;
30
24
use std:: str:: FromStr ;
@@ -48,21 +42,11 @@ pub enum PpSourceMode {
48
42
PpmTyped ,
49
43
}
50
44
51
- #[ derive( Copy , Clone , PartialEq , Debug ) ]
52
- pub enum PpFlowGraphMode {
53
- Default ,
54
- /// Drops the labels from the edges in the flowgraph output. This
55
- /// is mostly for use in the -Z unpretty flowgraph run-make tests,
56
- /// since the labels are largely uninteresting in those cases and
57
- /// have become a pain to maintain.
58
- UnlabelledEdges ,
59
- }
60
45
#[ derive( Copy , Clone , PartialEq , Debug ) ]
61
46
pub enum PpMode {
62
47
PpmSource ( PpSourceMode ) ,
63
48
PpmHir ( PpSourceMode ) ,
64
49
PpmHirTree ( PpSourceMode ) ,
65
- PpmFlowGraph ( PpFlowGraphMode ) ,
66
50
PpmMir ,
67
51
PpmMirCFG ,
68
52
}
@@ -80,15 +64,14 @@ impl PpMode {
80
64
PpmHir ( _) |
81
65
PpmHirTree ( _) |
82
66
PpmMir |
83
- PpmMirCFG |
84
- PpmFlowGraph ( _) => true ,
67
+ PpmMirCFG => true ,
85
68
PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
86
69
}
87
70
}
88
71
89
72
pub fn needs_analysis ( & self ) -> bool {
90
73
match * self {
91
- PpmMir | PpmMirCFG | PpmFlowGraph ( _ ) => true ,
74
+ PpmMir | PpmMirCFG => true ,
92
75
_ => false ,
93
76
}
94
77
}
@@ -114,15 +97,13 @@ pub fn parse_pretty(sess: &Session,
114
97
( "hir-tree" , true ) => PpmHirTree ( PpmNormal ) ,
115
98
( "mir" , true ) => PpmMir ,
116
99
( "mir-cfg" , true ) => PpmMirCFG ,
117
- ( "flowgraph" , true ) => PpmFlowGraph ( PpFlowGraphMode :: Default ) ,
118
- ( "flowgraph,unlabelled" , true ) => PpmFlowGraph ( PpFlowGraphMode :: UnlabelledEdges ) ,
119
100
_ => {
120
101
if extended {
121
102
sess. fatal ( & format ! ( "argument to `unpretty` must be one of `normal`, \
122
- `expanded`, `flowgraph[,unlabelled]=<nodeid> `, \
123
- `identified `, `expanded,identified `, `everybody_loops `, \
124
- `hir`, `hir,identified `, `hir,typed`, `hir-tree`, \
125
- `mir` or `mir-cfg`; got {}",
103
+ `expanded`, `identified`, `expanded,identified `, \
104
+ `everybody_loops `, `hir `, `hir,identified `, \
105
+ `hir,typed `, `hir-tree `, `mir` or `mir-cfg`; \
106
+ got {}",
126
107
name) ) ;
127
108
} else {
128
109
sess. fatal ( & format ! ( "argument to `pretty` must be one of `normal`, `expanded`, \
@@ -501,24 +482,6 @@ impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> {
501
482
}
502
483
}
503
484
504
- fn gather_flowgraph_variants ( sess : & Session ) -> Vec < borrowck_dot:: Variant > {
505
- let print_loans = sess. opts . debugging_opts . flowgraph_print_loans ;
506
- let print_moves = sess. opts . debugging_opts . flowgraph_print_moves ;
507
- let print_assigns = sess. opts . debugging_opts . flowgraph_print_assigns ;
508
- let print_all = sess. opts . debugging_opts . flowgraph_print_all ;
509
- let mut variants = Vec :: new ( ) ;
510
- if print_all || print_loans {
511
- variants. push ( borrowck_dot:: Loans ) ;
512
- }
513
- if print_all || print_moves {
514
- variants. push ( borrowck_dot:: Moves ) ;
515
- }
516
- if print_all || print_assigns {
517
- variants. push ( borrowck_dot:: Assigns ) ;
518
- }
519
- variants
520
- }
521
-
522
485
#[ derive( Clone , Debug ) ]
523
486
pub enum UserIdentifiedItem {
524
487
ItemViaNode ( ast:: NodeId ) ,
@@ -609,81 +572,6 @@ impl UserIdentifiedItem {
609
572
}
610
573
}
611
574
612
- fn print_flowgraph < ' tcx , W : Write > (
613
- variants : Vec < borrowck_dot:: Variant > ,
614
- tcx : TyCtxt < ' tcx > ,
615
- code : blocks:: Code < ' tcx > ,
616
- mode : PpFlowGraphMode ,
617
- mut out : W ,
618
- ) -> io:: Result < ( ) > {
619
- let body_id = match code {
620
- blocks:: Code :: Expr ( expr) => {
621
- // Find the function this expression is from.
622
- let mut hir_id = expr. hir_id ;
623
- loop {
624
- let node = tcx. hir ( ) . get ( hir_id) ;
625
- if let Some ( n) = hir:: map:: blocks:: FnLikeNode :: from_node ( node) {
626
- break n. body ( ) ;
627
- }
628
- let parent = tcx. hir ( ) . get_parent_node ( hir_id) ;
629
- assert_ne ! ( hir_id, parent) ;
630
- hir_id = parent;
631
- }
632
- }
633
- blocks:: Code :: FnLike ( fn_like) => fn_like. body ( ) ,
634
- } ;
635
- let body = tcx. hir ( ) . body ( body_id) ;
636
- let cfg = cfg:: CFG :: new ( tcx, & body) ;
637
- let labelled_edges = mode != PpFlowGraphMode :: UnlabelledEdges ;
638
- let hir_id = code. id ( ) ;
639
- // We have to disassemble the hir_id because name must be ASCII
640
- // alphanumeric. This does not appear in the rendered graph, so it does not
641
- // have to be user friendly.
642
- let name = format ! (
643
- "hir_id_{}_{}" ,
644
- hir_id. owner. index( ) ,
645
- hir_id. local_id. index( ) ,
646
- ) ;
647
- let lcfg = LabelledCFG {
648
- tcx,
649
- cfg : & cfg,
650
- name,
651
- labelled_edges,
652
- } ;
653
-
654
- match code {
655
- _ if variants. is_empty ( ) => {
656
- let r = dot:: render ( & lcfg, & mut out) ;
657
- return expand_err_details ( r) ;
658
- }
659
- blocks:: Code :: Expr ( _) => {
660
- tcx. sess . err ( "--pretty flowgraph with -Z flowgraph-print annotations requires \
661
- fn-like node id.") ;
662
- return Ok ( ( ) ) ;
663
- }
664
- blocks:: Code :: FnLike ( fn_like) => {
665
- let ( bccx, analysis_data) =
666
- borrowck:: build_borrowck_dataflow_data_for_fn ( tcx, fn_like. body ( ) , & cfg) ;
667
-
668
- let lcfg = borrowck_dot:: DataflowLabeller {
669
- inner : lcfg,
670
- variants,
671
- borrowck_ctxt : & bccx,
672
- analysis_data : & analysis_data,
673
- } ;
674
- let r = dot:: render ( & lcfg, & mut out) ;
675
- return expand_err_details ( r) ;
676
- }
677
- }
678
-
679
- fn expand_err_details ( r : io:: Result < ( ) > ) -> io:: Result < ( ) > {
680
- r. map_err ( |ioerr| {
681
- io:: Error :: new ( io:: ErrorKind :: Other ,
682
- format ! ( "graphviz::render failed: {}" , ioerr) )
683
- } )
684
- }
685
- }
686
-
687
575
pub fn visit_crate ( sess : & Session , krate : & mut ast:: Crate , ppm : PpMode ) {
688
576
if let PpmSource ( PpmEveryBodyLoops ) = ppm {
689
577
ReplaceBodyWithLoop :: new ( sess) . visit_crate ( krate) ;
@@ -872,55 +760,17 @@ fn print_with_analysis(
872
760
873
761
tcx. analysis ( LOCAL_CRATE ) ?;
874
762
875
- let mut print = || match ppm {
763
+ match ppm {
876
764
PpmMir | PpmMirCFG => {
877
- if let Some ( nodeid) = nodeid {
878
- let def_id = tcx. hir ( ) . local_def_id_from_node_id ( nodeid) ;
879
- match ppm {
880
- PpmMir => write_mir_pretty ( tcx, Some ( def_id) , & mut out) ,
881
- PpmMirCFG => write_mir_graphviz ( tcx, Some ( def_id) , & mut out) ,
882
- _ => unreachable ! ( ) ,
883
- } ?;
884
- } else {
885
- match ppm {
886
- PpmMir => write_mir_pretty ( tcx, None , & mut out) ,
887
- PpmMirCFG => write_mir_graphviz ( tcx, None , & mut out) ,
888
- _ => unreachable ! ( ) ,
889
- } ?;
890
- }
891
- Ok ( ( ) )
892
- }
893
- PpmFlowGraph ( mode) => {
894
- let nodeid =
895
- nodeid. expect ( "`pretty flowgraph=..` needs NodeId (int) or unique path \
896
- suffix (b::c::d)") ;
897
- let hir_id = tcx. hir ( ) . node_to_hir_id ( nodeid) ;
898
- let node = tcx. hir ( ) . find ( hir_id) . unwrap_or_else ( || {
899
- tcx. sess . fatal ( & format ! ( "`--pretty=flowgraph` couldn't find ID: {}" , nodeid) )
900
- } ) ;
901
-
902
- match blocks:: Code :: from_node ( & tcx. hir ( ) , hir_id) {
903
- Some ( code) => {
904
- let variants = gather_flowgraph_variants ( tcx. sess ) ;
905
-
906
- let out: & mut dyn Write = & mut out;
907
-
908
- print_flowgraph ( variants, tcx, code, mode, out)
909
- }
910
- None => {
911
- let message = format ! ( "`--pretty=flowgraph` needs block, fn, or method; \
912
- got {:?}",
913
- node) ;
914
-
915
- let hir_id = tcx. hir ( ) . node_to_hir_id ( nodeid) ;
916
- tcx. sess . span_fatal ( tcx. hir ( ) . span ( hir_id) , & message)
917
- }
765
+ let def_id = nodeid. map ( |nid| tcx. hir ( ) . local_def_id_from_node_id ( nid) ) ;
766
+ match ppm {
767
+ PpmMir => write_mir_pretty ( tcx, def_id, & mut out) ,
768
+ PpmMirCFG => write_mir_graphviz ( tcx, def_id, & mut out) ,
769
+ _ => unreachable ! ( ) ,
918
770
}
919
771
}
920
772
_ => unreachable ! ( ) ,
921
- } ;
922
-
923
- print ( ) . unwrap ( ) ;
773
+ } . unwrap ( ) ;
924
774
925
775
write_output ( out, ofile) ;
926
776
0 commit comments