11// Type Names for Debug Info.
22
3- use crate :: common:: CodegenCx ;
4- use rustc:: hir:: def_id:: DefId ;
5- use rustc:: ty:: subst:: SubstsRef ;
6- use rustc:: ty:: { self , Ty } ;
7- use rustc_codegen_ssa:: traits:: * ;
3+ use rustc:: hir:: { self , def_id:: DefId } ;
4+ use rustc:: ty:: { self , Ty , TyCtxt , subst:: SubstsRef } ;
85use rustc_data_structures:: fx:: FxHashSet ;
96
10- use rustc:: hir;
11-
127// Compute the name of the type as it should be stored in debuginfo. Does not do
138// any caching, i.e., calling the function twice with the same type will also do
149// the work twice. The `qualified` parameter only affects the first level of the
1510// type name, further levels (i.e., type parameters) are always fully qualified.
16- pub fn compute_debuginfo_type_name < ' a , ' tcx > ( cx : & CodegenCx < ' a , ' tcx > ,
11+ pub fn compute_debuginfo_type_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1712 t : Ty < ' tcx > ,
1813 qualified : bool )
1914 -> String {
2015 let mut result = String :: with_capacity ( 64 ) ;
2116 let mut visited = FxHashSet :: default ( ) ;
22- push_debuginfo_type_name ( cx , t, qualified, & mut result, & mut visited) ;
17+ push_debuginfo_type_name ( tcx , t, qualified, & mut result, & mut visited) ;
2318 result
2419}
2520
2621// Pushes the name of the type as it should be stored in debuginfo on the
2722// `output` String. See also compute_debuginfo_type_name().
28- pub fn push_debuginfo_type_name < ' a , ' tcx > ( cx : & CodegenCx < ' a , ' tcx > ,
23+ pub fn push_debuginfo_type_name < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
2924 t : Ty < ' tcx > ,
3025 qualified : bool ,
3126 output : & mut String ,
3227 visited : & mut FxHashSet < Ty < ' tcx > > ) {
3328
3429 // When targeting MSVC, emit C++ style type names for compatibility with
3530 // .natvis visualizers (and perhaps other existing native debuggers?)
36- let cpp_like_names = cx . sess ( ) . target . target . options . is_like_msvc ;
31+ let cpp_like_names = tcx . sess . target . target . options . is_like_msvc ;
3732
3833 match t. sty {
3934 ty:: Bool => output. push_str ( "bool" ) ,
@@ -43,15 +38,15 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
4338 ty:: Int ( int_ty) => output. push_str ( int_ty. ty_to_string ( ) ) ,
4439 ty:: Uint ( uint_ty) => output. push_str ( uint_ty. ty_to_string ( ) ) ,
4540 ty:: Float ( float_ty) => output. push_str ( float_ty. ty_to_string ( ) ) ,
46- ty:: Foreign ( def_id) => push_item_name ( cx , def_id, qualified, output) ,
41+ ty:: Foreign ( def_id) => push_item_name ( tcx , def_id, qualified, output) ,
4742 ty:: Adt ( def, substs) => {
48- push_item_name ( cx , def. did , qualified, output) ;
49- push_type_params ( cx , substs, output, visited) ;
43+ push_item_name ( tcx , def. did , qualified, output) ;
44+ push_type_params ( tcx , substs, output, visited) ;
5045 } ,
5146 ty:: Tuple ( component_types) => {
5247 output. push ( '(' ) ;
5348 for & component_type in component_types {
54- push_debuginfo_type_name ( cx , component_type, true , output, visited) ;
49+ push_debuginfo_type_name ( tcx , component_type, true , output, visited) ;
5550 output. push_str ( ", " ) ;
5651 }
5752 if !component_types. is_empty ( ) {
@@ -69,7 +64,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
6964 hir:: MutMutable => output. push_str ( "mut " ) ,
7065 }
7166
72- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
67+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
7368
7469 if cpp_like_names {
7570 output. push ( '*' ) ;
@@ -83,16 +78,16 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
8378 output. push_str ( "mut " ) ;
8479 }
8580
86- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
81+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
8782
8883 if cpp_like_names {
8984 output. push ( '*' ) ;
9085 }
9186 } ,
9287 ty:: Array ( inner_type, len) => {
9388 output. push ( '[' ) ;
94- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
95- output. push_str ( & format ! ( "; {}" , len. unwrap_usize( cx . tcx) ) ) ;
89+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
90+ output. push_str ( & format ! ( "; {}" , len. unwrap_usize( tcx) ) ) ;
9691 output. push ( ']' ) ;
9792 } ,
9893 ty:: Slice ( inner_type) => {
@@ -102,7 +97,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
10297 output. push ( '[' ) ;
10398 }
10499
105- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
100+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
106101
107102 if cpp_like_names {
108103 output. push ( '>' ) ;
@@ -112,12 +107,12 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
112107 } ,
113108 ty:: Dynamic ( ref trait_data, ..) => {
114109 if let Some ( principal) = trait_data. principal ( ) {
115- let principal = cx . tcx . normalize_erasing_late_bound_regions (
110+ let principal = tcx. normalize_erasing_late_bound_regions (
116111 ty:: ParamEnv :: reveal_all ( ) ,
117112 & principal,
118113 ) ;
119- push_item_name ( cx , principal. def_id , false , output) ;
120- push_type_params ( cx , principal. substs , output, visited) ;
114+ push_item_name ( tcx , principal. def_id , false , output) ;
115+ push_type_params ( tcx , principal. substs , output, visited) ;
121116 } else {
122117 output. push_str ( "dyn '_" ) ;
123118 }
@@ -142,24 +137,24 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
142137 }
143138
144139
145- let sig = t. fn_sig ( cx . tcx ) ;
140+ let sig = t. fn_sig ( tcx) ;
146141 if sig. unsafety ( ) == hir:: Unsafety :: Unsafe {
147142 output. push_str ( "unsafe " ) ;
148143 }
149144
150145 let abi = sig. abi ( ) ;
151- if abi != crate :: abi:: Abi :: Rust {
146+ if abi != rustc_target :: spec :: abi:: Abi :: Rust {
152147 output. push_str ( "extern \" " ) ;
153148 output. push_str ( abi. name ( ) ) ;
154149 output. push_str ( "\" " ) ;
155150 }
156151
157152 output. push_str ( "fn(" ) ;
158153
159- let sig = cx . tcx . normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & sig) ;
154+ let sig = tcx. normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & sig) ;
160155 if !sig. inputs ( ) . is_empty ( ) {
161156 for & parameter_type in sig. inputs ( ) {
162- push_debuginfo_type_name ( cx , parameter_type, true , output, visited) ;
157+ push_debuginfo_type_name ( tcx , parameter_type, true , output, visited) ;
163158 output. push_str ( ", " ) ;
164159 }
165160 output. pop ( ) ;
@@ -178,7 +173,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
178173
179174 if !sig. output ( ) . is_unit ( ) {
180175 output. push_str ( " -> " ) ;
181- push_debuginfo_type_name ( cx , sig. output ( ) , true , output, visited) ;
176+ push_debuginfo_type_name ( tcx , sig. output ( ) , true , output, visited) ;
182177 }
183178
184179
@@ -213,18 +208,18 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
213208 }
214209 }
215210
216- fn push_item_name ( cx : & CodegenCx < ' _ , ' _ > ,
211+ fn push_item_name ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
217212 def_id : DefId ,
218213 qualified : bool ,
219214 output : & mut String ) {
220215 if qualified {
221- output. push_str ( & cx . tcx . crate_name ( def_id. krate ) . as_str ( ) ) ;
222- for path_element in cx . tcx . def_path ( def_id) . data {
216+ output. push_str ( & tcx. crate_name ( def_id. krate ) . as_str ( ) ) ;
217+ for path_element in tcx. def_path ( def_id) . data {
223218 output. push_str ( "::" ) ;
224219 output. push_str ( & path_element. data . as_interned_str ( ) . as_str ( ) ) ;
225220 }
226221 } else {
227- output. push_str ( & cx . tcx . item_name ( def_id) . as_str ( ) ) ;
222+ output. push_str ( & tcx. item_name ( def_id) . as_str ( ) ) ;
228223 }
229224 }
230225
@@ -233,7 +228,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
233228 // reconstructed for items from non-local crates. For local crates, this
234229 // would be possible but with inlining and LTO we have to use the least
235230 // common denominator - otherwise we would run into conflicts.
236- fn push_type_params < ' a , ' tcx > ( cx : & CodegenCx < ' a , ' tcx > ,
231+ fn push_type_params < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
237232 substs : SubstsRef < ' tcx > ,
238233 output : & mut String ,
239234 visited : & mut FxHashSet < Ty < ' tcx > > ) {
@@ -244,7 +239,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
244239 output. push ( '<' ) ;
245240
246241 for type_parameter in substs. types ( ) {
247- push_debuginfo_type_name ( cx , type_parameter, true , output, visited) ;
242+ push_debuginfo_type_name ( tcx , type_parameter, true , output, visited) ;
248243 output. push_str ( ", " ) ;
249244 }
250245
0 commit comments