File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ impl FlagComputation {
8585 }
8686
8787 & ty:: Generator ( _, ref substs, _) => {
88+ self . add_flags ( TypeFlags :: MAY_POLYMORPHIZE ) ;
89+
8890 let substs = substs. as_generator ( ) ;
8991 let should_remove_further_specializable =
9092 !self . flags . contains ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE ) ;
@@ -107,6 +109,8 @@ impl FlagComputation {
107109 }
108110
109111 & ty:: Closure ( _, substs) => {
112+ self . add_flags ( TypeFlags :: MAY_POLYMORPHIZE ) ;
113+
110114 let substs = substs. as_closure ( ) ;
111115 let should_remove_further_specializable =
112116 !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 {
150150 self . has_type_flags ( TypeFlags :: STILL_FURTHER_SPECIALIZABLE )
151151 }
152152
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+
153159 /// A visitor that does not recurse into types, works like `fn walk_shallow` in `Ty`.
154160 fn visit_tys_shallow ( & self , visit : impl FnMut ( Ty < ' tcx > ) -> bool ) -> bool {
155161 pub struct Visitor < F > ( F ) ;
Original file line number Diff line number Diff line change @@ -528,7 +528,11 @@ fn polymorphize<'tcx>(
528528 // ..then use the identity for this parameter.
529529 tcx. mk_param_from_def ( param) ,
530530
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.
532536 _ => {
533537 let arg = substs[ param. index as usize ] ;
534538 let polymorphized_arg = arg. fold_with ( & mut PolymorphizationFolder { tcx } ) ;
Original file line number Diff line number Diff line change @@ -575,6 +575,10 @@ bitflags! {
575575 /// Does this value have parameters/placeholders/inference variables which could be
576576 /// replaced later, in a way that would change the results of `impl` specialization?
577577 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 ;
578582 }
579583}
580584
You can’t perform that action at this time.
0 commit comments