1
1
// Type Names for Debug Info.
2
2
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 } ;
8
5
use rustc_data_structures:: fx:: FxHashSet ;
9
6
10
- use rustc:: hir;
11
-
12
7
// Compute the name of the type as it should be stored in debuginfo. Does not do
13
8
// any caching, i.e., calling the function twice with the same type will also do
14
9
// the work twice. The `qualified` parameter only affects the first level of the
15
10
// 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 > ,
17
12
t : Ty < ' tcx > ,
18
13
qualified : bool )
19
14
-> String {
20
15
let mut result = String :: with_capacity ( 64 ) ;
21
16
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) ;
23
18
result
24
19
}
25
20
26
21
// Pushes the name of the type as it should be stored in debuginfo on the
27
22
// `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 > ,
29
24
t : Ty < ' tcx > ,
30
25
qualified : bool ,
31
26
output : & mut String ,
32
27
visited : & mut FxHashSet < Ty < ' tcx > > ) {
33
28
34
29
// When targeting MSVC, emit C++ style type names for compatibility with
35
30
// .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 ;
37
32
38
33
match t. sty {
39
34
ty:: Bool => output. push_str ( "bool" ) ,
@@ -43,15 +38,15 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
43
38
ty:: Int ( int_ty) => output. push_str ( int_ty. ty_to_string ( ) ) ,
44
39
ty:: Uint ( uint_ty) => output. push_str ( uint_ty. ty_to_string ( ) ) ,
45
40
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) ,
47
42
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) ;
50
45
} ,
51
46
ty:: Tuple ( component_types) => {
52
47
output. push ( '(' ) ;
53
48
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) ;
55
50
output. push_str ( ", " ) ;
56
51
}
57
52
if !component_types. is_empty ( ) {
@@ -69,7 +64,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
69
64
hir:: MutMutable => output. push_str ( "mut " ) ,
70
65
}
71
66
72
- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
67
+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
73
68
74
69
if cpp_like_names {
75
70
output. push ( '*' ) ;
@@ -83,16 +78,16 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
83
78
output. push_str ( "mut " ) ;
84
79
}
85
80
86
- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
81
+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
87
82
88
83
if cpp_like_names {
89
84
output. push ( '*' ) ;
90
85
}
91
86
} ,
92
87
ty:: Array ( inner_type, len) => {
93
88
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) ) ) ;
96
91
output. push ( ']' ) ;
97
92
} ,
98
93
ty:: Slice ( inner_type) => {
@@ -102,7 +97,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
102
97
output. push ( '[' ) ;
103
98
}
104
99
105
- push_debuginfo_type_name ( cx , inner_type, true , output, visited) ;
100
+ push_debuginfo_type_name ( tcx , inner_type, true , output, visited) ;
106
101
107
102
if cpp_like_names {
108
103
output. push ( '>' ) ;
@@ -112,12 +107,12 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
112
107
} ,
113
108
ty:: Dynamic ( ref trait_data, ..) => {
114
109
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 (
116
111
ty:: ParamEnv :: reveal_all ( ) ,
117
112
& principal,
118
113
) ;
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) ;
121
116
} else {
122
117
output. push_str ( "dyn '_" ) ;
123
118
}
@@ -142,24 +137,24 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
142
137
}
143
138
144
139
145
- let sig = t. fn_sig ( cx . tcx ) ;
140
+ let sig = t. fn_sig ( tcx) ;
146
141
if sig. unsafety ( ) == hir:: Unsafety :: Unsafe {
147
142
output. push_str ( "unsafe " ) ;
148
143
}
149
144
150
145
let abi = sig. abi ( ) ;
151
- if abi != crate :: abi:: Abi :: Rust {
146
+ if abi != rustc_target :: spec :: abi:: Abi :: Rust {
152
147
output. push_str ( "extern \" " ) ;
153
148
output. push_str ( abi. name ( ) ) ;
154
149
output. push_str ( "\" " ) ;
155
150
}
156
151
157
152
output. push_str ( "fn(" ) ;
158
153
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) ;
160
155
if !sig. inputs ( ) . is_empty ( ) {
161
156
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) ;
163
158
output. push_str ( ", " ) ;
164
159
}
165
160
output. pop ( ) ;
@@ -178,7 +173,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
178
173
179
174
if !sig. output ( ) . is_unit ( ) {
180
175
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) ;
182
177
}
183
178
184
179
@@ -213,18 +208,18 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
213
208
}
214
209
}
215
210
216
- fn push_item_name ( cx : & CodegenCx < ' _ , ' _ > ,
211
+ fn push_item_name ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
217
212
def_id : DefId ,
218
213
qualified : bool ,
219
214
output : & mut String ) {
220
215
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 {
223
218
output. push_str ( "::" ) ;
224
219
output. push_str ( & path_element. data . as_interned_str ( ) . as_str ( ) ) ;
225
220
}
226
221
} else {
227
- output. push_str ( & cx . tcx . item_name ( def_id) . as_str ( ) ) ;
222
+ output. push_str ( & tcx. item_name ( def_id) . as_str ( ) ) ;
228
223
}
229
224
}
230
225
@@ -233,7 +228,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
233
228
// reconstructed for items from non-local crates. For local crates, this
234
229
// would be possible but with inlining and LTO we have to use the least
235
230
// 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 > ,
237
232
substs : SubstsRef < ' tcx > ,
238
233
output : & mut String ,
239
234
visited : & mut FxHashSet < Ty < ' tcx > > ) {
@@ -244,7 +239,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
244
239
output. push ( '<' ) ;
245
240
246
241
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) ;
248
243
output. push_str ( ", " ) ;
249
244
}
250
245
0 commit comments