File tree 4 files changed +19
-1
lines changed
4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ impl FlagComputation {
85
85
}
86
86
87
87
& ty:: Generator ( _, ref substs, _) => {
88
+ self . add_flags ( TypeFlags :: MAY_POLYMORPHIZE ) ;
89
+
88
90
let substs = substs. as_generator ( ) ;
89
91
let should_remove_further_specializable =
90
92
!self . flags . contains ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
@@ -107,6 +109,8 @@ impl FlagComputation {
107
109
}
108
110
109
111
& ty:: Closure ( _, substs) => {
112
+ self . add_flags ( TypeFlags :: MAY_POLYMORPHIZE ) ;
113
+
110
114
let substs = substs. as_closure ( ) ;
111
115
let should_remove_further_specializable =
112
116
!self . flags . contains ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
150
150
self . has_type_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE )
151
151
}
152
152
153
+ /// Does this value contain closures or generators such that it may require
154
+ /// polymorphization?
155
+ fn may_polymorphize ( & self ) -> bool {
156
+ self . has_type_flags ( TypeFlags :: MAY_POLYMORPHIZE )
157
+ }
158
+
153
159
/// A visitor that does not recurse into types, works like `fn walk_shallow` in `Ty`.
154
160
fn visit_tys_shallow ( & self , visit : impl FnMut ( Ty < ' tcx > ) -> bool ) -> bool {
155
161
pub struct Visitor < F > ( F ) ;
Original file line number Diff line number Diff line change @@ -528,7 +528,11 @@ fn polymorphize<'tcx>(
528
528
// ..then use the identity for this parameter.
529
529
tcx. mk_param_from_def ( param) ,
530
530
531
- // Otherwise, use the parameter as before (polymorphizing any closures or generators).
531
+ // If the parameter does not contain any closures or generators, then use the
532
+ // substitution directly.
533
+ _ if !substs. may_polymorphize ( ) => substs[ param. index as usize ] ,
534
+
535
+ // Otherwise, use the substitution after polymorphizing.
532
536
_ => {
533
537
let arg = substs[ param. index as usize ] ;
534
538
let polymorphized_arg = arg. fold_with ( & mut PolymorphizationFolder { tcx } ) ;
Original file line number Diff line number Diff line change @@ -575,6 +575,10 @@ bitflags! {
575
575
/// Does this value have parameters/placeholders/inference variables which could be
576
576
/// replaced later, in a way that would change the results of `impl` specialization?
577
577
const STILL_FURTHER_SPECIALIZABLE = 1 << 17 ;
578
+
579
+ /// Does this value contain closures or generators such that it may require
580
+ /// polymorphization?
581
+ const MAY_POLYMORPHIZE = 1 << 18 ;
578
582
}
579
583
}
580
584
You can’t perform that action at this time.
0 commit comments