@@ -649,7 +649,7 @@ bool ReabstractionInfo::prepareAndCheck(ApplySite Apply, SILFunction *Callee,
649
649
650
650
bool ReabstractionInfo::canBeSpecialized (ApplySite Apply, SILFunction *Callee,
651
651
SubstitutionMap ParamSubs) {
652
- ReabstractionInfo ReInfo;
652
+ ReabstractionInfo ReInfo (Callee-> getModule ()) ;
653
653
return ReInfo.prepareAndCheck (Apply, Callee, ParamSubs);
654
654
}
655
655
@@ -659,6 +659,7 @@ ReabstractionInfo::ReabstractionInfo(
659
659
bool ConvertIndirectToDirect, bool dropMetatypeArgs, OptRemark::Emitter *ORE)
660
660
: ConvertIndirectToDirect(ConvertIndirectToDirect),
661
661
dropMetatypeArgs(dropMetatypeArgs),
662
+ M(&Callee->getModule ()),
662
663
TargetModule(targetModule), isWholeModule(isWholeModule),
663
664
Serialized(Serialized) {
664
665
if (!prepareAndCheck (Apply, Callee, ParamSubs, ORE))
@@ -772,8 +773,6 @@ bool ReabstractionInfo::isPartialSpecialization() const {
772
773
}
773
774
774
775
void ReabstractionInfo::createSubstitutedAndSpecializedTypes () {
775
- auto &M = Callee->getModule ();
776
-
777
776
// Find out how the function type looks like after applying the provided
778
777
// substitutions.
779
778
if (!SubstitutedType) {
@@ -792,7 +791,7 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
792
791
TrivialArgs.resize (NumArgs);
793
792
droppedMetatypeArgs.resize (NumArgs);
794
793
795
- SILFunctionConventions substConv (SubstitutedType, M );
794
+ SILFunctionConventions substConv (SubstitutedType, getModule () );
796
795
TypeExpansionContext resilienceExp = getResilienceExpansion ();
797
796
TypeExpansionContext minimalExp (ResilienceExpansion::Minimal,
798
797
TargetModule, isWholeModule);
@@ -863,26 +862,25 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
863
862
// Produce a specialized type, which is the substituted type with
864
863
// the parameters/results passing conventions adjusted according
865
864
// to the conversions selected above.
866
- SpecializedType = createSpecializedType (SubstitutedType, M );
865
+ SpecializedType = createSpecializedType (SubstitutedType, getModule () );
867
866
}
868
867
869
868
ReabstractionInfo::TypeCategory ReabstractionInfo::
870
869
getReturnTypeCategory (const SILResultInfo &RI,
871
870
const SILFunctionConventions &substConv,
872
871
TypeExpansionContext typeExpansion) {
873
- auto &M = Callee->getModule ();
874
872
auto ResultTy = substConv.getSILType (RI, typeExpansion);
875
873
ResultTy = Callee->mapTypeIntoContext (ResultTy);
876
- auto &TL = M .Types .getTypeLowering (ResultTy, typeExpansion);
874
+ auto &TL = getModule () .Types .getTypeLowering (ResultTy, typeExpansion);
877
875
878
876
if (!TL.isLoadable ())
879
877
return NotLoadable;
880
878
881
- if (RI.getReturnValueType (M , SubstitutedType, typeExpansion)
879
+ if (RI.getReturnValueType (getModule () , SubstitutedType, typeExpansion)
882
880
->isVoid ())
883
881
return NotLoadable;
884
882
885
- if (!shouldExpand (M , ResultTy))
883
+ if (!shouldExpand (getModule () , ResultTy))
886
884
return NotLoadable;
887
885
888
886
return TL.isTrivial () ? LoadableAndTrivial : Loadable;
@@ -892,10 +890,9 @@ ReabstractionInfo::TypeCategory ReabstractionInfo::
892
890
getParamTypeCategory (const SILParameterInfo &PI,
893
891
const SILFunctionConventions &substConv,
894
892
TypeExpansionContext typeExpansion) {
895
- auto &M = Callee->getModule ();
896
893
auto ParamTy = substConv.getSILType (PI, typeExpansion);
897
- ParamTy = Callee-> mapTypeIntoContext (ParamTy);
898
- auto &TL = M .Types .getTypeLowering (ParamTy, typeExpansion);
894
+ ParamTy = mapTypeIntoContext (ParamTy);
895
+ auto &TL = getModule () .Types .getTypeLowering (ParamTy, typeExpansion);
899
896
900
897
if (!TL.isLoadable ())
901
898
return NotLoadable;
@@ -908,7 +905,6 @@ CanSILFunctionType
908
905
ReabstractionInfo::createSubstitutedType (SILFunction *OrigF,
909
906
SubstitutionMap SubstMap,
910
907
bool HasUnboundGenericParams) {
911
- auto &M = OrigF->getModule ();
912
908
if ((SpecializedGenericSig &&
913
909
SpecializedGenericSig->areAllParamsConcrete ()) ||
914
910
!HasUnboundGenericParams) {
@@ -920,8 +916,8 @@ ReabstractionInfo::createSubstitutedType(SILFunction *OrigF,
920
916
921
917
auto lowered = OrigF->getLoweredFunctionType ();
922
918
auto genSub =
923
- lowered->substGenericArgs (M , SubstMap, getResilienceExpansion ());
924
- auto unsub = genSub->getUnsubstitutedType (M );
919
+ lowered->substGenericArgs (getModule () , SubstMap, getResilienceExpansion ());
920
+ auto unsub = genSub->getUnsubstitutedType (getModule () );
925
921
auto specialized = CanSpecializedGenericSig.getReducedType (unsub);
926
922
927
923
// First substitute concrete types into the existing function type.
@@ -935,7 +931,7 @@ ReabstractionInfo::createSubstitutedType(SILFunction *OrigF,
935
931
CanSpecializedGenericSig, FnTy->getExtInfo (), FnTy->getCoroutineKind (),
936
932
FnTy->getCalleeConvention (), FnTy->getParameters (), FnTy->getYields (),
937
933
FnTy->getResults (), FnTy->getOptionalErrorResult (),
938
- FnTy->getPatternSubstitutions (), SubstitutionMap (), M .getASTContext (),
934
+ FnTy->getPatternSubstitutions (), SubstitutionMap (), getModule () .getASTContext (),
939
935
FnTy->getWitnessMethodConformanceOrInvalid ());
940
936
941
937
// This is an interface type. It should not have any archetypes.
@@ -972,6 +968,16 @@ CanSILFunctionType ReabstractionInfo::createThunkType(PartialApplyInst *forPAI)
972
968
return newFnTy;
973
969
}
974
970
971
+ SILType ReabstractionInfo::mapTypeIntoContext (SILType type) const {
972
+ if (Callee) {
973
+ return Callee->mapTypeIntoContext (type);
974
+ }
975
+ assert (!methodDecl.isNull ());
976
+ if (auto *genericEnv = M->Types .getConstantGenericEnvironment (methodDecl))
977
+ return genericEnv->mapTypeIntoContext (getModule (), type);
978
+ return type;
979
+ }
980
+
975
981
// / Convert the substituted function type into a specialized function type based
976
982
// / on the ReabstractionInfo.
977
983
CanSILFunctionType ReabstractionInfo::
@@ -1081,15 +1087,13 @@ void ReabstractionInfo::performFullSpecializationPreparation(
1081
1087
assert ((!EnablePartialSpecialization || !HasUnboundGenericParams) &&
1082
1088
" Only full specializations are handled here" );
1083
1089
1084
- SILModule &M = Callee->getModule ();
1085
-
1086
1090
this ->Callee = Callee;
1087
1091
1088
1092
// Get the original substitution map.
1089
1093
ClonerParamSubMap = ParamSubs;
1090
1094
1091
1095
SubstitutedType = Callee->getLoweredFunctionType ()->substGenericArgs (
1092
- M , ClonerParamSubMap, getResilienceExpansion ());
1096
+ getModule () , ClonerParamSubMap, getResilienceExpansion ());
1093
1097
CallerParamSubMap = {};
1094
1098
createSubstitutedAndSpecializedTypes ();
1095
1099
}
@@ -1889,8 +1893,6 @@ void FunctionSignaturePartialSpecializer::createSpecializedGenericSignature(
1889
1893
void ReabstractionInfo::performPartialSpecializationPreparation (
1890
1894
SILFunction *Caller, SILFunction *Callee,
1891
1895
SubstitutionMap ParamSubs) {
1892
- SILModule &M = Callee->getModule ();
1893
-
1894
1896
// Caller is the SILFunction containing the apply instruction.
1895
1897
CanGenericSignature CallerGenericSig;
1896
1898
GenericEnvironment *CallerGenericEnv = nullptr ;
@@ -1910,7 +1912,7 @@ void ReabstractionInfo::performPartialSpecializationPreparation(
1910
1912
llvm::dbgs () << " Callee generic signature is:\n " ;
1911
1913
CalleeGenericSig->print (llvm::dbgs ()));
1912
1914
1913
- FunctionSignaturePartialSpecializer FSPS (M ,
1915
+ FunctionSignaturePartialSpecializer FSPS (getModule () ,
1914
1916
CallerGenericSig, CallerGenericEnv,
1915
1917
CalleeGenericSig, CalleeGenericEnv,
1916
1918
ParamSubs);
@@ -1968,7 +1970,7 @@ ReabstractionInfo::ReabstractionInfo(ModuleDecl *targetModule,
1968
1970
bool isWholeModule, SILFunction *Callee,
1969
1971
GenericSignature SpecializedSig,
1970
1972
bool isPrespecialization)
1971
- : TargetModule(targetModule), isWholeModule(isWholeModule),
1973
+ : M(&Callee-> getModule ()), TargetModule(targetModule), isWholeModule(isWholeModule),
1972
1974
isPrespecialization(isPrespecialization) {
1973
1975
Serialized =
1974
1976
this ->isPrespecialization ? IsNotSerialized : Callee->isSerialized ();
@@ -1979,13 +1981,11 @@ ReabstractionInfo::ReabstractionInfo(ModuleDecl *targetModule,
1979
1981
this ->Callee = Callee;
1980
1982
ConvertIndirectToDirect = true ;
1981
1983
1982
- SILModule &M = Callee->getModule ();
1983
-
1984
1984
auto CalleeGenericSig =
1985
1985
Callee->getLoweredFunctionType ()->getInvocationGenericSignature ();
1986
1986
auto *CalleeGenericEnv = Callee->getGenericEnvironment ();
1987
1987
1988
- FunctionSignaturePartialSpecializer FSPS (M ,
1988
+ FunctionSignaturePartialSpecializer FSPS (getModule () ,
1989
1989
CalleeGenericSig, CalleeGenericEnv,
1990
1990
SpecializedSig);
1991
1991
@@ -3091,7 +3091,7 @@ void swift::trySpecializeApplyOfGeneric(
3091
3091
3092
3092
// Check if there is a pre-specialization available in a library.
3093
3093
SpecializedFunction prespecializedF{};
3094
- ReabstractionInfo prespecializedReInfo;
3094
+ ReabstractionInfo prespecializedReInfo (FuncBuilder. getModule ()) ;
3095
3095
bool replacePartialApplyWithoutReabstraction = false ;
3096
3096
3097
3097
if (usePrespecialized (FuncBuilder, Apply, RefF, ReInfo, prespecializedReInfo,
0 commit comments