@@ -530,13 +530,14 @@ bool ReabstractionInfo::canBeSpecialized(ApplySite Apply, SILFunction *Callee,
530
530
531
531
ReabstractionInfo::ReabstractionInfo (ApplySite Apply, SILFunction *Callee,
532
532
SubstitutionMap ParamSubs,
533
+ IsSerialized_t Serialized,
533
534
bool ConvertIndirectToDirect,
534
- OptRemark::Emitter *ORE) {
535
+ OptRemark::Emitter *ORE)
536
+ : ConvertIndirectToDirect(ConvertIndirectToDirect),
537
+ Serialized(Serialized) {
535
538
if (!prepareAndCheck (Apply, Callee, ParamSubs, ORE))
536
539
return ;
537
540
538
- this ->ConvertIndirectToDirect = ConvertIndirectToDirect;
539
-
540
541
SILFunction *Caller = nullptr ;
541
542
if (Apply)
542
543
Caller = Apply.getFunction ();
@@ -557,7 +558,7 @@ ReabstractionInfo::ReabstractionInfo(ApplySite Apply, SILFunction *Callee,
557
558
<< SpecializedType << " \n\n " );
558
559
}
559
560
560
- // Some sanity checks.
561
+ // Some correctness checks.
561
562
auto SpecializedFnTy = getSpecializedType ();
562
563
auto SpecializedSubstFnTy = SpecializedFnTy;
563
564
@@ -777,10 +778,15 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const {
777
778
if (isFormalResultConverted (IndirectResultIdx++)) {
778
779
// Convert the indirect result to a direct result.
779
780
SILType SILResTy = SILType::getPrimitiveObjectType (RI.getType ());
781
+ // FIXME: Expansion
782
+ auto &TL = M.Types .getTypeLowering (SILResTy,
783
+ ResilienceExpansion::Minimal);
784
+
780
785
// Indirect results are passed as owned, so we also need to pass the
781
786
// 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);
784
790
SpecializedResults.push_back (SILResultInfo (RI.getType (), C));
785
791
continue ;
786
792
}
@@ -798,11 +804,15 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const {
798
804
799
805
// Convert the indirect parameter to a direct parameter.
800
806
SILType SILParamTy = SILType::getPrimitiveObjectType (PI.getType ());
807
+ // FIXME: Expansion
808
+ auto &TL = M.Types .getTypeLowering (SILParamTy,
809
+ ResilienceExpansion::Minimal);
810
+
801
811
// Indirect parameters are passed as owned/guaranteed, so we also
802
812
// need to pass the direct/guaranteed parameter as
803
813
// owned/guaranteed (except it's a trivial type).
804
814
auto C = ParameterConvention::Direct_Unowned;
805
- if (!SILParamTy .isTrivial (M )) {
815
+ if (!TL .isTrivial ()) {
806
816
if (PI.isGuaranteed ()) {
807
817
C = ParameterConvention::Direct_Guaranteed;
808
818
} else {
@@ -1774,6 +1784,8 @@ checkSpecializationRequirements(ArrayRef<Requirement> Requirements) {
1774
1784
// / This constructor is used when processing @_specialize.
1775
1785
ReabstractionInfo::ReabstractionInfo (SILFunction *Callee,
1776
1786
ArrayRef<Requirement> Requirements) {
1787
+ Serialized = Callee->isSerialized ();
1788
+
1777
1789
if (shouldNotSpecialize (Callee, nullptr ))
1778
1790
return ;
1779
1791
@@ -1802,24 +1814,23 @@ ReabstractionInfo::ReabstractionInfo(SILFunction *Callee,
1802
1814
1803
1815
GenericFuncSpecializer::GenericFuncSpecializer (
1804
1816
SILOptFunctionBuilder &FuncBuilder, SILFunction *GenericFunc,
1805
- SubstitutionMap ParamSubs, IsSerialized_t Serialized,
1817
+ SubstitutionMap ParamSubs,
1806
1818
const ReabstractionInfo &ReInfo)
1807
1819
: FuncBuilder(FuncBuilder), M(GenericFunc->getModule ()),
1808
1820
GenericFunc(GenericFunc),
1809
1821
ParamSubs(ParamSubs),
1810
- Serialized(Serialized),
1811
1822
ReInfo(ReInfo) {
1812
1823
1813
1824
assert (GenericFunc->isDefinition () && " Expected definition to specialize!" );
1814
1825
auto FnTy = ReInfo.getSpecializedType ();
1815
1826
1816
1827
if (ReInfo.isPartialSpecialization ()) {
1817
1828
Mangle::PartialSpecializationMangler Mangler (
1818
- GenericFunc, FnTy, Serialized , /* isReAbstracted*/ true );
1829
+ GenericFunc, FnTy, ReInfo. isSerialized () , /* isReAbstracted*/ true );
1819
1830
ClonedName = Mangler.mangle ();
1820
1831
} else {
1821
1832
Mangle::GenericSpecializationMangler Mangler (
1822
- GenericFunc, ParamSubs, Serialized , /* isReAbstracted*/ true );
1833
+ GenericFunc, ParamSubs, ReInfo. isSerialized () , /* isReAbstracted*/ true );
1823
1834
ClonedName = Mangler.mangle ();
1824
1835
}
1825
1836
LLVM_DEBUG (llvm::dbgs () << " Specialized function " << ClonedName << ' \n ' );
@@ -1869,7 +1880,7 @@ SILFunction *GenericFuncSpecializer::tryCreateSpecialization() {
1869
1880
1870
1881
// Create a new function.
1871
1882
SILFunction *SpecializedF = GenericCloner::cloneFunction (
1872
- FuncBuilder, GenericFunc, Serialized, ReInfo,
1883
+ FuncBuilder, GenericFunc, ReInfo,
1873
1884
// Use these substitutions inside the new specialized function being
1874
1885
// created.
1875
1886
ReInfo.getClonerParamSubstitutionMap (),
@@ -2065,7 +2076,6 @@ class ReabstractionThunkGenerator {
2065
2076
const ReabstractionInfo &ReInfo;
2066
2077
PartialApplyInst *OrigPAI;
2067
2078
2068
- IsSerialized_t Serialized = IsNotSerialized;
2069
2079
std::string ThunkName;
2070
2080
RegularLocation Loc;
2071
2081
SmallVector<SILValue, 4 > Arguments;
@@ -2078,23 +2088,18 @@ class ReabstractionThunkGenerator {
2078
2088
: FunctionBuilder(FunctionBuilder), OrigF(OrigPAI->getCalleeFunction ()), M(OrigF->getModule ()),
2079
2089
SpecializedFunc(SpecializedFunc), ReInfo(ReInfo), OrigPAI(OrigPAI),
2080
2090
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 );
2083
2095
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 );
2095
2101
2096
- ThunkName = Mangler.mangle ();
2097
- }
2102
+ ThunkName = Mangler.mangle ();
2098
2103
}
2099
2104
}
2100
2105
@@ -2109,7 +2114,7 @@ class ReabstractionThunkGenerator {
2109
2114
SILFunction *ReabstractionThunkGenerator::createThunk () {
2110
2115
SILFunction *Thunk = FunctionBuilder.getOrCreateSharedFunction (
2111
2116
Loc, ThunkName, ReInfo.getSubstitutedType (), IsBare, IsTransparent,
2112
- Serialized , ProfileCounter (), IsThunk, IsNotDynamic);
2117
+ ReInfo. isSerialized () , ProfileCounter (), IsThunk, IsNotDynamic);
2113
2118
// Re-use an existing thunk.
2114
2119
if (!Thunk->empty ())
2115
2120
return Thunk;
@@ -2320,7 +2325,8 @@ void swift::trySpecializeApplyOfGeneric(
2320
2325
Serialized = IsNotSerialized;
2321
2326
2322
2327
ReabstractionInfo ReInfo (Apply, RefF, Apply.getSubstitutionMap (),
2323
- /* ConvertIndirectToDirect=*/ true , &ORE);
2328
+ Serialized, /* ConvertIndirectToDirect=*/ true ,
2329
+ &ORE);
2324
2330
if (!ReInfo.canBeSpecialized ())
2325
2331
return ;
2326
2332
@@ -2365,7 +2371,7 @@ void swift::trySpecializeApplyOfGeneric(
2365
2371
2366
2372
GenericFuncSpecializer FuncSpecializer (FuncBuilder,
2367
2373
RefF, Apply.getSubstitutionMap (),
2368
- Serialized, ReInfo);
2374
+ ReInfo);
2369
2375
SILFunction *SpecializedF = FuncSpecializer.lookupSpecialization ();
2370
2376
if (SpecializedF) {
2371
2377
// Even if the pre-specialization exists already, try to preserve it
@@ -2408,7 +2414,8 @@ void swift::trySpecializeApplyOfGeneric(
2408
2414
auto *PAI = cast<PartialApplyInst>(Apply.getInstruction ());
2409
2415
SILBuilderWithScope Builder (PAI);
2410
2416
SILFunction *Thunk =
2411
- ReabstractionThunkGenerator (FuncBuilder, ReInfo, PAI, SpecializedF).createThunk ();
2417
+ ReabstractionThunkGenerator (FuncBuilder, ReInfo, PAI, SpecializedF)
2418
+ .createThunk ();
2412
2419
NewFunctions.push_back (Thunk);
2413
2420
auto *FRI = Builder.createFunctionRef (PAI->getLoc (), Thunk);
2414
2421
SmallVector<SILValue, 4 > Arguments;
0 commit comments