@@ -3021,43 +3021,39 @@ struct LocalArchetypeRequirementCollector {
3021
3021
// /
3022
3022
// / \param localArchetypes - the list of local archetypes to promote
3023
3023
// / into the signature, if any
3024
- // / \param inheritGenericSig - whether to inherit the generic signature from the
3025
- // / parent function.
3026
3024
// / \param genericEnv - the new generic environment
3027
3025
// / \param contextSubs - map non-local archetypes from the original function
3028
3026
// / to archetypes in the thunk
3029
3027
// / \param interfaceSubs - map interface types to old archetypes
3030
3028
static CanGenericSignature
3031
3029
buildThunkSignature (SILFunction *fn,
3032
- bool inheritGenericSig,
3033
3030
ArrayRef<CanLocalArchetypeType> localArchetypes,
3034
3031
GenericEnvironment *&genericEnv,
3035
3032
SubstitutionMap &contextSubs,
3036
3033
SubstitutionMap &interfaceSubs,
3037
3034
llvm::DenseMap<ArchetypeType*, Type> &contextLocalArchetypes) {
3038
3035
auto *mod = fn->getModule ().getSwiftModule ();
3039
3036
auto &ctx = mod->getASTContext ();
3037
+ auto forwardingSubs = fn->getForwardingSubstitutionMap ();
3040
3038
3041
3039
// If there are no local archetypes, we just inherit the generic
3042
3040
// environment from the parent function.
3043
3041
if (localArchetypes.empty ()) {
3044
3042
auto genericSig =
3045
3043
fn->getLoweredFunctionType ()->getInvocationGenericSignature ();
3046
3044
genericEnv = fn->getGenericEnvironment ();
3047
- interfaceSubs = fn-> getForwardingSubstitutionMap () ;
3045
+ interfaceSubs = forwardingSubs ;
3048
3046
contextSubs = interfaceSubs;
3049
3047
return genericSig;
3050
3048
}
3051
3049
3052
3050
// Add the existing generic signature.
3053
3051
unsigned depth = 0 ;
3054
3052
GenericSignature baseGenericSig;
3055
- if (inheritGenericSig) {
3056
- if (auto genericSig =
3057
- fn->getLoweredFunctionType ()->getInvocationGenericSignature ()) {
3058
- baseGenericSig = genericSig;
3059
- depth = genericSig.getGenericParams ().back ()->getDepth () + 1 ;
3060
- }
3053
+ if (auto genericSig =
3054
+ fn->getLoweredFunctionType ()->getInvocationGenericSignature ()) {
3055
+ baseGenericSig = genericSig;
3056
+ depth = genericSig.getGenericParams ().back ()->getDepth () + 1 ;
3061
3057
}
3062
3058
3063
3059
// Add new generic parameters to replace the local archetypes.
@@ -3088,13 +3084,11 @@ buildThunkSignature(SILFunction *fn,
3088
3084
->getInvocationGenericSignature ()) {
3089
3085
contextSubs = SubstitutionMap::get (
3090
3086
calleeGenericSig,
3091
- [&](SubstitutableType *type) -> Type {
3092
- return genericEnv->mapTypeIntoContext (type);
3093
- },
3094
- MakeAbstractConformanceForGenericType ());
3087
+ genericEnv->getForwardingSubstitutionMap ());
3095
3088
}
3096
3089
3097
3090
// Calculate substitutions to map interface types to the caller's archetypes.
3091
+
3098
3092
interfaceSubs = SubstitutionMap::get (
3099
3093
genericSig,
3100
3094
[&](SubstitutableType *type) -> Type {
@@ -3103,7 +3097,7 @@ buildThunkSignature(SILFunction *fn,
3103
3097
return collector.ParamSubs [param->getIndex ()];
3104
3098
}
3105
3099
}
3106
- return fn-> mapTypeIntoContext (type);
3100
+ return Type (type). subst (forwardingSubs );
3107
3101
},
3108
3102
MakeAbstractConformanceForGenericType ());
3109
3103
@@ -3142,18 +3136,14 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
3142
3136
if (withoutActuallyEscaping)
3143
3137
extInfoBuilder = extInfoBuilder.withNoEscape (false );
3144
3138
3145
- // Does the thunk type involve archetypes other than local archetypes?
3146
- bool hasArchetypes = false ;
3147
3139
// Does the thunk type involve a local archetype type?
3148
3140
SmallVector<CanLocalArchetypeType, 8 > localArchetypes;
3149
3141
auto archetypeVisitor = [&](CanType t) {
3150
3142
if (auto archetypeTy = dyn_cast<ArchetypeType>(t)) {
3151
- if (auto opened = dyn_cast<LocalArchetypeType>(archetypeTy)) {
3152
- auto root = opened .getRoot ();
3143
+ if (auto local = dyn_cast<LocalArchetypeType>(archetypeTy)) {
3144
+ auto root = local .getRoot ();
3153
3145
if (llvm::find (localArchetypes, root) == localArchetypes.end ())
3154
3146
localArchetypes.push_back (root);
3155
- } else {
3156
- hasArchetypes = true ;
3157
3147
}
3158
3148
}
3159
3149
};
@@ -3169,7 +3159,6 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
3169
3159
sourceType.visit (archetypeVisitor);
3170
3160
3171
3161
genericSig = buildThunkSignature (fn,
3172
- hasArchetypes,
3173
3162
localArchetypes,
3174
3163
genericEnv,
3175
3164
contextSubs,
0 commit comments