@@ -3021,43 +3021,39 @@ struct LocalArchetypeRequirementCollector {
30213021// /
30223022// / \param localArchetypes - the list of local archetypes to promote
30233023// / into the signature, if any
3024- // / \param inheritGenericSig - whether to inherit the generic signature from the
3025- // / parent function.
30263024// / \param genericEnv - the new generic environment
30273025// / \param contextSubs - map non-local archetypes from the original function
30283026// / to archetypes in the thunk
30293027// / \param interfaceSubs - map interface types to old archetypes
30303028static CanGenericSignature
30313029buildThunkSignature (SILFunction *fn,
3032- bool inheritGenericSig,
30333030 ArrayRef<CanLocalArchetypeType> localArchetypes,
30343031 GenericEnvironment *&genericEnv,
30353032 SubstitutionMap &contextSubs,
30363033 SubstitutionMap &interfaceSubs,
30373034 llvm::DenseMap<ArchetypeType*, Type> &contextLocalArchetypes) {
30383035 auto *mod = fn->getModule ().getSwiftModule ();
30393036 auto &ctx = mod->getASTContext ();
3037+ auto forwardingSubs = fn->getForwardingSubstitutionMap ();
30403038
30413039 // If there are no local archetypes, we just inherit the generic
30423040 // environment from the parent function.
30433041 if (localArchetypes.empty ()) {
30443042 auto genericSig =
30453043 fn->getLoweredFunctionType ()->getInvocationGenericSignature ();
30463044 genericEnv = fn->getGenericEnvironment ();
3047- interfaceSubs = fn-> getForwardingSubstitutionMap () ;
3045+ interfaceSubs = forwardingSubs ;
30483046 contextSubs = interfaceSubs;
30493047 return genericSig;
30503048 }
30513049
30523050 // Add the existing generic signature.
30533051 unsigned depth = 0 ;
30543052 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 ;
30613057 }
30623058
30633059 // Add new generic parameters to replace the local archetypes.
@@ -3088,13 +3084,11 @@ buildThunkSignature(SILFunction *fn,
30883084 ->getInvocationGenericSignature ()) {
30893085 contextSubs = SubstitutionMap::get (
30903086 calleeGenericSig,
3091- [&](SubstitutableType *type) -> Type {
3092- return genericEnv->mapTypeIntoContext (type);
3093- },
3094- MakeAbstractConformanceForGenericType ());
3087+ genericEnv->getForwardingSubstitutionMap ());
30953088 }
30963089
30973090 // Calculate substitutions to map interface types to the caller's archetypes.
3091+
30983092 interfaceSubs = SubstitutionMap::get (
30993093 genericSig,
31003094 [&](SubstitutableType *type) -> Type {
@@ -3103,7 +3097,7 @@ buildThunkSignature(SILFunction *fn,
31033097 return collector.ParamSubs [param->getIndex ()];
31043098 }
31053099 }
3106- return fn-> mapTypeIntoContext (type);
3100+ return Type (type). subst (forwardingSubs );
31073101 },
31083102 MakeAbstractConformanceForGenericType ());
31093103
@@ -3142,18 +3136,14 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
31423136 if (withoutActuallyEscaping)
31433137 extInfoBuilder = extInfoBuilder.withNoEscape (false );
31443138
3145- // Does the thunk type involve archetypes other than local archetypes?
3146- bool hasArchetypes = false ;
31473139 // Does the thunk type involve a local archetype type?
31483140 SmallVector<CanLocalArchetypeType, 8 > localArchetypes;
31493141 auto archetypeVisitor = [&](CanType t) {
31503142 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 ();
31533145 if (llvm::find (localArchetypes, root) == localArchetypes.end ())
31543146 localArchetypes.push_back (root);
3155- } else {
3156- hasArchetypes = true ;
31573147 }
31583148 }
31593149 };
@@ -3169,7 +3159,6 @@ CanSILFunctionType swift::buildSILFunctionThunkType(
31693159 sourceType.visit (archetypeVisitor);
31703160
31713161 genericSig = buildThunkSignature (fn,
3172- hasArchetypes,
31733162 localArchetypes,
31743163 genericEnv,
31753164 contextSubs,
0 commit comments