@@ -11,10 +11,10 @@ use hir::{
11
11
use hir_analysis:: {
12
12
analysis_pass:: { AnalysisPassManager , ParsingPass } ,
13
13
diagnostics:: DiagnosticVoucher ,
14
- name_resolution:: { DefConflictAnalysisPass , ImportAnalysisPass , PathAnalysisPass } ,
14
+ name_resolution:: ImportAnalysisPass ,
15
15
ty:: {
16
- AdtDefAnalysisPass , BodyAnalysisPass , FuncAnalysisPass , ImplAnalysisPass ,
17
- ImplTraitAnalysisPass , TraitAnalysisPass , TypeAliasAnalysisPass ,
16
+ AdtDefAnalysisPass , BodyAnalysisPass , DefConflictAnalysisPass , FuncAnalysisPass ,
17
+ ImplAnalysisPass , ImplTraitAnalysisPass , TraitAnalysisPass , TypeAliasAnalysisPass ,
18
18
} ,
19
19
} ;
20
20
@@ -33,50 +33,42 @@ impl salsa::Database for DriverDataBase {
33
33
impl DriverDataBase {
34
34
// TODO: An temporary implementation for ui testing.
35
35
pub fn run_on_top_mod < ' db > ( & ' db self , top_mod : TopLevelMod < ' db > ) -> DiagnosticsCollection < ' db > {
36
- self . run_on_file_with_pass_manager ( top_mod, initialize_analysis_pass)
36
+ self . run_on_file_with_pass_manager ( top_mod, initialize_analysis_pass ( ) )
37
37
}
38
38
39
- pub fn run_on_file_with_pass_manager < ' db , F > (
39
+ pub fn run_on_file_with_pass_manager < ' db > (
40
40
& ' db self ,
41
41
top_mod : TopLevelMod < ' db > ,
42
- pm_builder : F ,
43
- ) -> DiagnosticsCollection < ' db >
44
- where
45
- F : FnOnce ( & ' db DriverDataBase ) -> AnalysisPassManager < ' db > ,
46
- {
47
- let mut pass_manager = pm_builder ( self ) ;
48
- DiagnosticsCollection ( pass_manager. run_on_module ( top_mod) )
42
+ mut pass_manager : AnalysisPassManager ,
43
+ ) -> DiagnosticsCollection < ' db > {
44
+ DiagnosticsCollection ( pass_manager. run_on_module ( self , top_mod) )
49
45
}
50
46
51
47
pub fn run_on_ingot ( & self , ingot : InputIngot ) -> DiagnosticsCollection {
52
- self . run_on_ingot_with_pass_manager ( ingot, initialize_analysis_pass)
48
+ self . run_on_ingot_with_pass_manager ( ingot, initialize_analysis_pass ( ) )
53
49
}
54
50
55
- pub fn run_on_ingot_with_pass_manager < ' db , F > (
56
- & ' db self ,
51
+ pub fn run_on_ingot_with_pass_manager (
52
+ & self ,
57
53
ingot : InputIngot ,
58
- pm_builder : F ,
59
- ) -> DiagnosticsCollection < ' db >
60
- where
61
- F : FnOnce ( & ' db DriverDataBase ) -> AnalysisPassManager < ' db > ,
62
- {
54
+ mut pass_manager : AnalysisPassManager ,
55
+ ) -> DiagnosticsCollection {
63
56
let tree = module_tree ( self , ingot) ;
64
- let mut pass_manager = pm_builder ( self ) ;
65
- DiagnosticsCollection ( pass_manager. run_on_module_tree ( tree) )
57
+ DiagnosticsCollection ( pass_manager. run_on_module_tree ( self , tree) )
66
58
}
67
59
68
60
pub fn top_mod ( & self , ingot : InputIngot , input : InputFile ) -> TopLevelMod {
69
61
map_file_to_mod ( self , ingot, input)
70
62
}
71
63
}
72
64
73
- pub struct DiagnosticsCollection < ' db > ( Vec < Box < dyn DiagnosticVoucher < ' db > + ' db > > ) ;
74
- impl < ' db > DiagnosticsCollection < ' db > {
65
+ pub struct DiagnosticsCollection < ' db > ( Vec < Box < dyn DiagnosticVoucher + ' db > > ) ;
66
+ impl DiagnosticsCollection < ' _ > {
75
67
pub fn is_empty ( & self ) -> bool {
76
68
self . 0 . is_empty ( )
77
69
}
78
70
79
- pub fn emit ( & self , db : & ' db DriverDataBase ) {
71
+ pub fn emit ( & self , db : & DriverDataBase ) {
80
72
let writer = BufferWriter :: stderr ( ColorChoice :: Auto ) ;
81
73
let mut buffer = writer. buffer ( ) ;
82
74
let config = term:: Config :: default ( ) ;
@@ -89,7 +81,7 @@ impl<'db> DiagnosticsCollection<'db> {
89
81
}
90
82
91
83
/// Format the accumulated diagnostics to a string.
92
- pub fn format_diags ( & self , db : & ' db DriverDataBase ) -> String {
84
+ pub fn format_diags ( & self , db : & DriverDataBase ) -> String {
93
85
let writer = BufferWriter :: stderr ( ColorChoice :: Never ) ;
94
86
let mut buffer = writer. buffer ( ) ;
95
87
let config = term:: Config :: default ( ) ;
@@ -101,8 +93,8 @@ impl<'db> DiagnosticsCollection<'db> {
101
93
std:: str:: from_utf8 ( buffer. as_slice ( ) ) . unwrap ( ) . to_string ( )
102
94
}
103
95
104
- fn finalize ( & self , db : & ' db DriverDataBase ) -> Vec < CompleteDiagnostic > {
105
- let mut diags: Vec < _ > = self . 0 . iter ( ) . map ( |d| d. to_complete ( db) ) . collect ( ) ;
96
+ fn finalize ( & self , db : & DriverDataBase ) -> Vec < CompleteDiagnostic > {
97
+ let mut diags: Vec < _ > = self . 0 . iter ( ) . map ( |d| d. as_ref ( ) . to_complete ( db) ) . collect ( ) ;
106
98
diags. sort_by ( |lhs, rhs| match lhs. error_code . cmp ( & rhs. error_code ) {
107
99
std:: cmp:: Ordering :: Equal => lhs. primary_span ( ) . cmp ( & rhs. primary_span ( ) ) ,
108
100
ord => ord,
@@ -111,18 +103,17 @@ impl<'db> DiagnosticsCollection<'db> {
111
103
}
112
104
}
113
105
114
- fn initialize_analysis_pass ( db : & DriverDataBase ) -> AnalysisPassManager < ' _ > {
106
+ fn initialize_analysis_pass ( ) -> AnalysisPassManager {
115
107
let mut pass_manager = AnalysisPassManager :: new ( ) ;
116
- pass_manager. add_module_pass ( Box :: new ( ParsingPass :: new ( db) ) ) ;
117
- pass_manager. add_module_pass ( Box :: new ( DefConflictAnalysisPass :: new ( db) ) ) ;
118
- pass_manager. add_module_pass ( Box :: new ( ImportAnalysisPass :: new ( db) ) ) ;
119
- pass_manager. add_module_pass ( Box :: new ( PathAnalysisPass :: new ( db) ) ) ;
120
- pass_manager. add_module_pass ( Box :: new ( AdtDefAnalysisPass :: new ( db) ) ) ;
121
- pass_manager. add_module_pass ( Box :: new ( TypeAliasAnalysisPass :: new ( db) ) ) ;
122
- pass_manager. add_module_pass ( Box :: new ( TraitAnalysisPass :: new ( db) ) ) ;
123
- pass_manager. add_module_pass ( Box :: new ( ImplAnalysisPass :: new ( db) ) ) ;
124
- pass_manager. add_module_pass ( Box :: new ( ImplTraitAnalysisPass :: new ( db) ) ) ;
125
- pass_manager. add_module_pass ( Box :: new ( FuncAnalysisPass :: new ( db) ) ) ;
126
- pass_manager. add_module_pass ( Box :: new ( BodyAnalysisPass :: new ( db) ) ) ;
108
+ pass_manager. add_module_pass ( Box :: new ( ParsingPass { } ) ) ;
109
+ pass_manager. add_module_pass ( Box :: new ( DefConflictAnalysisPass { } ) ) ;
110
+ pass_manager. add_module_pass ( Box :: new ( ImportAnalysisPass { } ) ) ;
111
+ pass_manager. add_module_pass ( Box :: new ( AdtDefAnalysisPass { } ) ) ;
112
+ pass_manager. add_module_pass ( Box :: new ( TypeAliasAnalysisPass { } ) ) ;
113
+ pass_manager. add_module_pass ( Box :: new ( TraitAnalysisPass { } ) ) ;
114
+ pass_manager. add_module_pass ( Box :: new ( ImplAnalysisPass { } ) ) ;
115
+ pass_manager. add_module_pass ( Box :: new ( ImplTraitAnalysisPass { } ) ) ;
116
+ pass_manager. add_module_pass ( Box :: new ( FuncAnalysisPass { } ) ) ;
117
+ pass_manager. add_module_pass ( Box :: new ( BodyAnalysisPass { } ) ) ;
127
118
pass_manager
128
119
}
0 commit comments