@@ -23,15 +23,12 @@ pub(super) fn mangle(
23
23
let substs = tcx. normalize_erasing_regions ( ty:: ParamEnv :: reveal_all ( ) , instance. substs ) ;
24
24
25
25
let prefix = "_R" ;
26
- let mut cx = SymbolMangler {
26
+ let mut cx = & mut SymbolMangler {
27
27
tcx,
28
- compress : Some ( Box :: new ( CompressionCaches {
29
- start_offset : prefix. len ( ) ,
30
-
31
- paths : FxHashMap :: default ( ) ,
32
- types : FxHashMap :: default ( ) ,
33
- consts : FxHashMap :: default ( ) ,
34
- } ) ) ,
28
+ start_offset : prefix. len ( ) ,
29
+ paths : FxHashMap :: default ( ) ,
30
+ types : FxHashMap :: default ( ) ,
31
+ consts : FxHashMap :: default ( ) ,
35
32
binders : vec ! [ ] ,
36
33
out : String :: from ( prefix) ,
37
34
} ;
@@ -52,17 +49,7 @@ pub(super) fn mangle(
52
49
if let Some ( instantiating_crate) = instantiating_crate {
53
50
cx = cx. print_def_path ( instantiating_crate. as_def_id ( ) , & [ ] ) . unwrap ( ) ;
54
51
}
55
- cx. out
56
- }
57
-
58
- struct CompressionCaches < ' tcx > {
59
- // The length of the prefix in `out` (e.g. 2 for `_R`).
60
- start_offset : usize ,
61
-
62
- // The values are start positions in `out`, in bytes.
63
- paths : FxHashMap < ( DefId , & ' tcx [ GenericArg < ' tcx > ] ) , usize > ,
64
- types : FxHashMap < Ty < ' tcx > , usize > ,
65
- consts : FxHashMap < & ' tcx ty:: Const < ' tcx > , usize > ,
52
+ std:: mem:: take ( & mut cx. out )
66
53
}
67
54
68
55
struct BinderLevel {
@@ -81,9 +68,15 @@ struct BinderLevel {
81
68
82
69
struct SymbolMangler < ' tcx > {
83
70
tcx : TyCtxt < ' tcx > ,
84
- compress : Option < Box < CompressionCaches < ' tcx > > > ,
85
71
binders : Vec < BinderLevel > ,
86
72
out : String ,
73
+
74
+ /// The length of the prefix in `out` (e.g. 2 for `_R`).
75
+ start_offset : usize ,
76
+ /// The values are start positions in `out`, in bytes.
77
+ paths : FxHashMap < ( DefId , & ' tcx [ GenericArg < ' tcx > ] ) , usize > ,
78
+ types : FxHashMap < Ty < ' tcx > , usize > ,
79
+ consts : FxHashMap < & ' tcx ty:: Const < ' tcx > , usize > ,
87
80
}
88
81
89
82
impl SymbolMangler < ' tcx > {
@@ -160,13 +153,13 @@ impl SymbolMangler<'tcx> {
160
153
self . push ( ident) ;
161
154
}
162
155
163
- fn path_append_ns (
164
- mut self ,
165
- print_prefix : impl FnOnce ( Self ) -> Result < Self , !> ,
156
+ fn path_append_ns < ' a > (
157
+ mut self : & ' a mut Self ,
158
+ print_prefix : impl FnOnce ( & ' a mut Self ) -> Result < & ' a mut Self , !> ,
166
159
ns : char ,
167
160
disambiguator : u64 ,
168
161
name : & str ,
169
- ) -> Result < Self , !> {
162
+ ) -> Result < & ' a mut Self , !> {
170
163
self . push ( "N" ) ;
171
164
self . out . push ( ns) ;
172
165
self = print_prefix ( self ) ?;
@@ -175,17 +168,17 @@ impl SymbolMangler<'tcx> {
175
168
Ok ( self )
176
169
}
177
170
178
- fn print_backref ( mut self , i : usize ) -> Result < Self , !> {
171
+ fn print_backref ( & mut self , i : usize ) -> Result < & mut Self , !> {
179
172
self . push ( "B" ) ;
180
- self . push_integer_62 ( ( i - self . compress . as_ref ( ) . unwrap ( ) . start_offset ) as u64 ) ;
173
+ self . push_integer_62 ( ( i - self . start_offset ) as u64 ) ;
181
174
Ok ( self )
182
175
}
183
176
184
- fn in_binder < T > (
185
- mut self ,
177
+ fn in_binder < ' a , T > (
178
+ mut self : & ' a mut Self ,
186
179
value : & ty:: Binder < ' tcx , T > ,
187
- print_value : impl FnOnce ( Self , & T ) -> Result < Self , !> ,
188
- ) -> Result < Self , !>
180
+ print_value : impl FnOnce ( & ' a mut Self , & T ) -> Result < & ' a mut Self , !> ,
181
+ ) -> Result < & ' a mut Self , !>
189
182
where
190
183
T : TypeFoldable < ' tcx > ,
191
184
{
@@ -218,7 +211,7 @@ impl SymbolMangler<'tcx> {
218
211
}
219
212
}
220
213
221
- impl Printer < ' tcx > for SymbolMangler < ' tcx > {
214
+ impl Printer < ' tcx > for & mut SymbolMangler < ' tcx > {
222
215
type Error = !;
223
216
224
217
type Path = Self ;
@@ -236,7 +229,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
236
229
def_id : DefId ,
237
230
substs : & ' tcx [ GenericArg < ' tcx > ] ,
238
231
) -> Result < Self :: Path , Self :: Error > {
239
- if let Some ( & i) = self . compress . as_ref ( ) . and_then ( |c| c . paths . get ( & ( def_id, substs) ) ) {
232
+ if let Some ( & i) = self . paths . get ( & ( def_id, substs) ) {
240
233
return self . print_backref ( i) ;
241
234
}
242
235
let start = self . out . len ( ) ;
@@ -246,9 +239,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
246
239
// Only cache paths that do not refer to an enclosing
247
240
// binder (which would change depending on context).
248
241
if !substs. iter ( ) . any ( |k| k. has_escaping_bound_vars ( ) ) {
249
- if let Some ( c) = & mut self . compress {
250
- c. paths . insert ( ( def_id, substs) , start) ;
251
- }
242
+ self . paths . insert ( ( def_id, substs) , start) ;
252
243
}
253
244
Ok ( self )
254
245
}
@@ -312,7 +303,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
312
303
Ok ( self )
313
304
}
314
305
315
- fn print_region ( mut self , region : ty:: Region < ' _ > ) -> Result < Self :: Region , Self :: Error > {
306
+ fn print_region ( self , region : ty:: Region < ' _ > ) -> Result < Self :: Region , Self :: Error > {
316
307
let i = match * region {
317
308
// Erased lifetimes use the index 0, for a
318
309
// shorter mangling of `L_`.
@@ -367,7 +358,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
367
358
return Ok ( self ) ;
368
359
}
369
360
370
- if let Some ( & i) = self . compress . as_ref ( ) . and_then ( |c| c . types . get ( & ty) ) {
361
+ if let Some ( & i) = self . types . get ( & ty) {
371
362
return self . print_backref ( i) ;
372
363
}
373
364
let start = self . out . len ( ) ;
@@ -476,9 +467,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
476
467
// Only cache types that do not refer to an enclosing
477
468
// binder (which would change depending on context).
478
469
if !ty. has_escaping_bound_vars ( ) {
479
- if let Some ( c) = & mut self . compress {
480
- c. types . insert ( ty, start) ;
481
- }
470
+ self . types . insert ( ty, start) ;
482
471
}
483
472
Ok ( self )
484
473
}
@@ -545,7 +534,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
545
534
}
546
535
547
536
fn print_const ( mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> Result < Self :: Const , Self :: Error > {
548
- if let Some ( & i) = self . compress . as_ref ( ) . and_then ( |c| c . consts . get ( & ct) ) {
537
+ if let Some ( & i) = self . consts . get ( & ct) {
549
538
return self . print_backref ( i) ;
550
539
}
551
540
let start = self . out . len ( ) ;
@@ -583,14 +572,12 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
583
572
// Only cache consts that do not refer to an enclosing
584
573
// binder (which would change depending on context).
585
574
if !ct. has_escaping_bound_vars ( ) {
586
- if let Some ( c) = & mut self . compress {
587
- c. consts . insert ( ct, start) ;
588
- }
575
+ self . consts . insert ( ct, start) ;
589
576
}
590
577
Ok ( self )
591
578
}
592
579
593
- fn path_crate ( mut self , cnum : CrateNum ) -> Result < Self :: Path , Self :: Error > {
580
+ fn path_crate ( self , cnum : CrateNum ) -> Result < Self :: Path , Self :: Error > {
594
581
self . push ( "C" ) ;
595
582
let stable_crate_id = self . tcx . def_path_hash ( cnum. as_def_id ( ) ) . stable_crate_id ( ) ;
596
583
self . push_disambiguator ( stable_crate_id. to_u64 ( ) ) ;
0 commit comments