@@ -683,6 +683,9 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
683683 TrivialArgs.resize (NumArgs);
684684
685685 SILFunctionConventions substConv (SubstitutedType, M);
686+ TypeExpansionContext resilienceExp = getResilienceExpansion ();
687+ TypeExpansionContext minimalExp (ResilienceExpansion::Minimal,
688+ TargetModule, isWholeModule);
686689
687690 if (SubstitutedType->getNumDirectFormalResults () == 0 ) {
688691 // The original function has no direct result yet. Try to convert the first
@@ -693,18 +696,15 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
693696 for (SILResultInfo RI : SubstitutedType->getIndirectFormalResults ()) {
694697 assert (RI.isFormalIndirect ());
695698
696- auto ResultTy = substConv.getSILType (RI, getResilienceExpansion ());
697- ResultTy = Callee->mapTypeIntoContext (ResultTy);
698- auto &TL = M.Types .getTypeLowering (ResultTy,
699- getResilienceExpansion ());
700-
701- if (TL.isLoadable () &&
702- !RI.getReturnValueType (M, SubstitutedType, getResilienceExpansion ())
703- ->isVoid () &&
704- shouldExpand (M, ResultTy)) {
699+ TypeCategory tc = getReturnTypeCategory (RI, substConv, resilienceExp);
700+ if (tc != NotLoadable) {
705701 Conversions.set (IdxForResult);
706- if (TL. isTrivial () )
702+ if (tc == LoadableAndTrivial )
707703 TrivialArgs.set (IdxForResult);
704+ if (resilienceExp != minimalExp &&
705+ getReturnTypeCategory (RI, substConv, minimalExp) == NotLoadable) {
706+ hasConvertedResilientParams = true ;
707+ }
708708 break ;
709709 }
710710 ++IdxForResult;
@@ -717,21 +717,20 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
717717 auto IdxToInsert = IdxForParam;
718718 ++IdxForParam;
719719
720- auto ParamTy = substConv.getSILType (PI, getResilienceExpansion ());
721- ParamTy = Callee->mapTypeIntoContext (ParamTy);
722- auto &TL = M.Types .getTypeLowering (ParamTy,
723- getResilienceExpansion ());
724-
725- if (!TL.isLoadable ()) {
720+ TypeCategory tc = getParamTypeCategory (PI, substConv, resilienceExp);
721+ if (tc == NotLoadable)
726722 continue ;
727- }
728723
729724 switch (PI.getConvention ()) {
730725 case ParameterConvention::Indirect_In:
731726 case ParameterConvention::Indirect_In_Guaranteed:
732727 Conversions.set (IdxToInsert);
733- if (TL. isTrivial () )
728+ if (tc == LoadableAndTrivial )
734729 TrivialArgs.set (IdxToInsert);
730+ if (resilienceExp != minimalExp &&
731+ getParamTypeCategory (PI, substConv, minimalExp) == NotLoadable) {
732+ hasConvertedResilientParams = true ;
733+ }
735734 break ;
736735 case ParameterConvention::Indirect_In_Constant:
737736 case ParameterConvention::Indirect_Inout:
@@ -749,6 +748,43 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
749748 SpecializedType = createSpecializedType (SubstitutedType, M);
750749}
751750
751+ ReabstractionInfo::TypeCategory ReabstractionInfo::
752+ getReturnTypeCategory (const SILResultInfo &RI,
753+ const SILFunctionConventions &substConv,
754+ TypeExpansionContext typeExpansion) {
755+ auto &M = Callee->getModule ();
756+ auto ResultTy = substConv.getSILType (RI, typeExpansion);
757+ ResultTy = Callee->mapTypeIntoContext (ResultTy);
758+ auto &TL = M.Types .getTypeLowering (ResultTy, typeExpansion);
759+
760+ if (!TL.isLoadable ())
761+ return NotLoadable;
762+
763+ if (RI.getReturnValueType (M, SubstitutedType, typeExpansion)
764+ ->isVoid ())
765+ return NotLoadable;
766+
767+ if (!shouldExpand (M, ResultTy))
768+ return NotLoadable;
769+
770+ return TL.isTrivial () ? LoadableAndTrivial : Loadable;
771+ }
772+
773+ ReabstractionInfo::TypeCategory ReabstractionInfo::
774+ getParamTypeCategory (const SILParameterInfo &PI,
775+ const SILFunctionConventions &substConv,
776+ TypeExpansionContext typeExpansion) {
777+ auto &M = Callee->getModule ();
778+ auto ParamTy = substConv.getSILType (PI, typeExpansion);
779+ ParamTy = Callee->mapTypeIntoContext (ParamTy);
780+ auto &TL = M.Types .getTypeLowering (ParamTy, typeExpansion);
781+
782+ if (!TL.isLoadable ())
783+ return NotLoadable;
784+
785+ return TL.isTrivial () ? LoadableAndTrivial : Loadable;
786+ }
787+
752788// / Create a new substituted type with the updated signature.
753789CanSILFunctionType
754790ReabstractionInfo::createSubstitutedType (SILFunction *OrigF,
@@ -1822,7 +1858,8 @@ GenericFuncSpecializer::GenericFuncSpecializer(
18221858 if (ReInfo.isPrespecialized ()) {
18231859 ClonedName = Mangler.manglePrespecialized (ParamSubs);
18241860 } else {
1825- ClonedName = Mangler.mangleReabstracted (ParamSubs);
1861+ ClonedName = Mangler.mangleReabstracted (ParamSubs,
1862+ ReInfo.needAlternativeMangling ());
18261863 }
18271864 }
18281865 LLVM_DEBUG (llvm::dbgs () << " Specialized function " << ClonedName << ' \n ' );
@@ -2467,7 +2504,7 @@ usePrespecialized(SILOptFunctionBuilder &funcBuilder, ApplySite apply,
24672504 Mangle::GenericSpecializationMangler mangler (refF, reInfo.isSerialized ());
24682505 std::string name = reInfo.isPrespecialized () ?
24692506 mangler.manglePrespecialized (subs) :
2470- mangler.mangleReabstracted (subs);
2507+ mangler.mangleReabstracted (subs, reInfo. needAlternativeMangling () );
24712508
24722509 prespecializedReInfo = reInfo;
24732510 return lookupOrCreatePrespecialization (funcBuilder, refF, name, reInfo);
0 commit comments