@@ -530,13 +530,14 @@ bool ReabstractionInfo::canBeSpecialized(ApplySite Apply, SILFunction *Callee,
530530
531531ReabstractionInfo::ReabstractionInfo (ApplySite Apply, SILFunction *Callee,
532532 SubstitutionMap ParamSubs,
533+ IsSerialized_t Serialized,
533534 bool ConvertIndirectToDirect,
534- OptRemark::Emitter *ORE) {
535+ OptRemark::Emitter *ORE)
536+ : ConvertIndirectToDirect(ConvertIndirectToDirect),
537+ Serialized(Serialized) {
535538 if (!prepareAndCheck (Apply, Callee, ParamSubs, ORE))
536539 return ;
537540
538- this ->ConvertIndirectToDirect = ConvertIndirectToDirect;
539-
540541 SILFunction *Caller = nullptr ;
541542 if (Apply)
542543 Caller = Apply.getFunction ();
@@ -557,7 +558,7 @@ ReabstractionInfo::ReabstractionInfo(ApplySite Apply, SILFunction *Callee,
557558 << SpecializedType << " \n\n " );
558559 }
559560
560- // Some sanity checks.
561+ // Some correctness checks.
561562 auto SpecializedFnTy = getSpecializedType ();
562563 auto SpecializedSubstFnTy = SpecializedFnTy;
563564
@@ -777,10 +778,15 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const {
777778 if (isFormalResultConverted (IndirectResultIdx++)) {
778779 // Convert the indirect result to a direct result.
779780 SILType SILResTy = SILType::getPrimitiveObjectType (RI.getType ());
781+ // FIXME: Expansion
782+ auto &TL = M.Types .getTypeLowering (SILResTy,
783+ ResilienceExpansion::Minimal);
784+
780785 // Indirect results are passed as owned, so we also need to pass the
781786 // direct result as owned (except it's a trivial type).
782- auto C = (SILResTy.isTrivial (M) ? ResultConvention::Unowned :
783- ResultConvention::Owned);
787+ auto C = (TL.isTrivial ()
788+ ? ResultConvention::Unowned
789+ : ResultConvention::Owned);
784790 SpecializedResults.push_back (SILResultInfo (RI.getType (), C));
785791 continue ;
786792 }
@@ -798,11 +804,15 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const {
798804
799805 // Convert the indirect parameter to a direct parameter.
800806 SILType SILParamTy = SILType::getPrimitiveObjectType (PI.getType ());
807+ // FIXME: Expansion
808+ auto &TL = M.Types .getTypeLowering (SILParamTy,
809+ ResilienceExpansion::Minimal);
810+
801811 // Indirect parameters are passed as owned/guaranteed, so we also
802812 // need to pass the direct/guaranteed parameter as
803813 // owned/guaranteed (except it's a trivial type).
804814 auto C = ParameterConvention::Direct_Unowned;
805- if (!SILParamTy .isTrivial (M )) {
815+ if (!TL .isTrivial ()) {
806816 if (PI.isGuaranteed ()) {
807817 C = ParameterConvention::Direct_Guaranteed;
808818 } else {
@@ -1774,6 +1784,8 @@ checkSpecializationRequirements(ArrayRef<Requirement> Requirements) {
17741784// / This constructor is used when processing @_specialize.
17751785ReabstractionInfo::ReabstractionInfo (SILFunction *Callee,
17761786 ArrayRef<Requirement> Requirements) {
1787+ Serialized = Callee->isSerialized ();
1788+
17771789 if (shouldNotSpecialize (Callee, nullptr ))
17781790 return ;
17791791
@@ -1802,24 +1814,23 @@ ReabstractionInfo::ReabstractionInfo(SILFunction *Callee,
18021814
18031815GenericFuncSpecializer::GenericFuncSpecializer (
18041816 SILOptFunctionBuilder &FuncBuilder, SILFunction *GenericFunc,
1805- SubstitutionMap ParamSubs, IsSerialized_t Serialized,
1817+ SubstitutionMap ParamSubs,
18061818 const ReabstractionInfo &ReInfo)
18071819 : FuncBuilder(FuncBuilder), M(GenericFunc->getModule ()),
18081820 GenericFunc(GenericFunc),
18091821 ParamSubs(ParamSubs),
1810- Serialized(Serialized),
18111822 ReInfo(ReInfo) {
18121823
18131824 assert (GenericFunc->isDefinition () && " Expected definition to specialize!" );
18141825 auto FnTy = ReInfo.getSpecializedType ();
18151826
18161827 if (ReInfo.isPartialSpecialization ()) {
18171828 Mangle::PartialSpecializationMangler Mangler (
1818- GenericFunc, FnTy, Serialized , /* isReAbstracted*/ true );
1829+ GenericFunc, FnTy, ReInfo. isSerialized () , /* isReAbstracted*/ true );
18191830 ClonedName = Mangler.mangle ();
18201831 } else {
18211832 Mangle::GenericSpecializationMangler Mangler (
1822- GenericFunc, ParamSubs, Serialized , /* isReAbstracted*/ true );
1833+ GenericFunc, ParamSubs, ReInfo. isSerialized () , /* isReAbstracted*/ true );
18231834 ClonedName = Mangler.mangle ();
18241835 }
18251836 LLVM_DEBUG (llvm::dbgs () << " Specialized function " << ClonedName << ' \n ' );
@@ -1869,7 +1880,7 @@ SILFunction *GenericFuncSpecializer::tryCreateSpecialization() {
18691880
18701881 // Create a new function.
18711882 SILFunction *SpecializedF = GenericCloner::cloneFunction (
1872- FuncBuilder, GenericFunc, Serialized, ReInfo,
1883+ FuncBuilder, GenericFunc, ReInfo,
18731884 // Use these substitutions inside the new specialized function being
18741885 // created.
18751886 ReInfo.getClonerParamSubstitutionMap (),
@@ -2065,7 +2076,6 @@ class ReabstractionThunkGenerator {
20652076 const ReabstractionInfo &ReInfo;
20662077 PartialApplyInst *OrigPAI;
20672078
2068- IsSerialized_t Serialized = IsNotSerialized;
20692079 std::string ThunkName;
20702080 RegularLocation Loc;
20712081 SmallVector<SILValue, 4 > Arguments;
@@ -2078,23 +2088,18 @@ class ReabstractionThunkGenerator {
20782088 : FunctionBuilder(FunctionBuilder), OrigF(OrigPAI->getCalleeFunction ()), M(OrigF->getModule ()),
20792089 SpecializedFunc(SpecializedFunc), ReInfo(ReInfo), OrigPAI(OrigPAI),
20802090 Loc(RegularLocation::getAutoGeneratedLocation()) {
2081- if (OrigF->isSerialized () && OrigPAI->getFunction ()->isSerialized ())
2082- Serialized = IsSerializable;
2091+ if (!ReInfo.isPartialSpecialization ()) {
2092+ Mangle::GenericSpecializationMangler Mangler (
2093+ OrigF, ReInfo.getCalleeParamSubstitutionMap (), ReInfo.isSerialized (),
2094+ /* isReAbstracted*/ false );
20832095
2084- {
2085- if (!ReInfo.isPartialSpecialization ()) {
2086- Mangle::GenericSpecializationMangler Mangler (
2087- OrigF, ReInfo.getCalleeParamSubstitutionMap (), Serialized,
2088- /* isReAbstracted*/ false );
2089-
2090- ThunkName = Mangler.mangle ();
2091- } else {
2092- Mangle::PartialSpecializationMangler Mangler (
2093- OrigF, ReInfo.getSpecializedType (), Serialized,
2094- /* isReAbstracted*/ false );
2096+ ThunkName = Mangler.mangle ();
2097+ } else {
2098+ Mangle::PartialSpecializationMangler Mangler (
2099+ OrigF, ReInfo.getSpecializedType (), ReInfo.isSerialized (),
2100+ /* isReAbstracted*/ false );
20952101
2096- ThunkName = Mangler.mangle ();
2097- }
2102+ ThunkName = Mangler.mangle ();
20982103 }
20992104 }
21002105
@@ -2109,7 +2114,7 @@ class ReabstractionThunkGenerator {
21092114SILFunction *ReabstractionThunkGenerator::createThunk () {
21102115 SILFunction *Thunk = FunctionBuilder.getOrCreateSharedFunction (
21112116 Loc, ThunkName, ReInfo.getSubstitutedType (), IsBare, IsTransparent,
2112- Serialized , ProfileCounter (), IsThunk, IsNotDynamic);
2117+ ReInfo. isSerialized () , ProfileCounter (), IsThunk, IsNotDynamic);
21132118 // Re-use an existing thunk.
21142119 if (!Thunk->empty ())
21152120 return Thunk;
@@ -2320,7 +2325,8 @@ void swift::trySpecializeApplyOfGeneric(
23202325 Serialized = IsNotSerialized;
23212326
23222327 ReabstractionInfo ReInfo (Apply, RefF, Apply.getSubstitutionMap (),
2323- /* ConvertIndirectToDirect=*/ true , &ORE);
2328+ Serialized, /* ConvertIndirectToDirect=*/ true ,
2329+ &ORE);
23242330 if (!ReInfo.canBeSpecialized ())
23252331 return ;
23262332
@@ -2365,7 +2371,7 @@ void swift::trySpecializeApplyOfGeneric(
23652371
23662372 GenericFuncSpecializer FuncSpecializer (FuncBuilder,
23672373 RefF, Apply.getSubstitutionMap (),
2368- Serialized, ReInfo);
2374+ ReInfo);
23692375 SILFunction *SpecializedF = FuncSpecializer.lookupSpecialization ();
23702376 if (SpecializedF) {
23712377 // Even if the pre-specialization exists already, try to preserve it
@@ -2408,7 +2414,8 @@ void swift::trySpecializeApplyOfGeneric(
24082414 auto *PAI = cast<PartialApplyInst>(Apply.getInstruction ());
24092415 SILBuilderWithScope Builder (PAI);
24102416 SILFunction *Thunk =
2411- ReabstractionThunkGenerator (FuncBuilder, ReInfo, PAI, SpecializedF).createThunk ();
2417+ ReabstractionThunkGenerator (FuncBuilder, ReInfo, PAI, SpecializedF)
2418+ .createThunk ();
24122419 NewFunctions.push_back (Thunk);
24132420 auto *FRI = Builder.createFunctionRef (PAI->getLoc (), Thunk);
24142421 SmallVector<SILValue, 4 > Arguments;
0 commit comments