@@ -550,8 +550,9 @@ bool ReabstractionInfo::canBeSpecialized(ApplySite Apply, SILFunction *Callee,
550
550
ReabstractionInfo::ReabstractionInfo (
551
551
ModuleDecl *targetModule, bool isWholeModule, ApplySite Apply,
552
552
SILFunction *Callee, SubstitutionMap ParamSubs, IsSerialized_t Serialized,
553
- bool ConvertIndirectToDirect, OptRemark::Emitter *ORE)
553
+ bool ConvertIndirectToDirect, bool dropMetatypeArgs, OptRemark::Emitter *ORE)
554
554
: ConvertIndirectToDirect(ConvertIndirectToDirect),
555
+ dropMetatypeArgs(dropMetatypeArgs),
555
556
TargetModule(targetModule), isWholeModule(isWholeModule),
556
557
Serialized(Serialized) {
557
558
if (!prepareAndCheck (Apply, Callee, ParamSubs, ORE))
@@ -683,6 +684,7 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
683
684
SubstitutedType->getParameters ().size ();
684
685
Conversions.resize (NumArgs);
685
686
TrivialArgs.resize (NumArgs);
687
+ droppedMetatypeArgs.resize (NumArgs);
686
688
687
689
SILFunctionConventions substConv (SubstitutedType, M);
688
690
TypeExpansionContext resilienceExp = getResilienceExpansion ();
@@ -737,11 +739,17 @@ void ReabstractionInfo::createSubstitutedAndSpecializedTypes() {
737
739
case ParameterConvention::Indirect_In_Constant:
738
740
case ParameterConvention::Indirect_Inout:
739
741
case ParameterConvention::Indirect_InoutAliasable:
742
+ break ;
743
+
740
744
case ParameterConvention::Direct_Owned:
741
745
case ParameterConvention::Direct_Unowned:
742
- case ParameterConvention::Direct_Guaranteed:
746
+ case ParameterConvention::Direct_Guaranteed: {
747
+ CanType ty = PI.getInterfaceType ();
748
+ if (dropMetatypeArgs && isa<MetatypeType>(ty) && !ty->hasArchetype ())
749
+ droppedMetatypeArgs.set (IdxToInsert);
743
750
break ;
744
751
}
752
+ }
745
753
}
746
754
747
755
// Produce a specialized type, which is the substituted type with
@@ -852,11 +860,16 @@ createSpecializedType(CanSILFunctionType SubstFTy, SILModule &M) const {
852
860
// No conversion: re-use the original, substituted result info.
853
861
SpecializedResults.push_back (RI);
854
862
}
855
- unsigned ParamIdx = 0 ;
863
+ unsigned idx = 0 ;
856
864
for (SILParameterInfo PI : SubstFTy->getParameters ()) {
865
+ unsigned paramIdx = idx++;
857
866
PI = PI.getUnsubstituted (M, SubstFTy, context);
858
- bool isTrivial = TrivialArgs.test (param2ArgIndex (ParamIdx));
859
- if (!isParamConverted (ParamIdx++)) {
867
+
868
+ if (isDroppedMetatypeArg (param2ArgIndex (paramIdx)))
869
+ continue ;
870
+
871
+ bool isTrivial = TrivialArgs.test (param2ArgIndex (paramIdx));
872
+ if (!isParamConverted (paramIdx)) {
860
873
// No conversion: re-use the original, substituted parameter info.
861
874
SpecializedParams.push_back (PI);
862
875
continue ;
@@ -1854,7 +1867,8 @@ GenericFuncSpecializer::GenericFuncSpecializer(
1854
1867
ClonedName = Mangler.manglePrespecialized (ParamSubs);
1855
1868
} else {
1856
1869
ClonedName = Mangler.mangleReabstracted (ParamSubs,
1857
- ReInfo.needAlternativeMangling ());
1870
+ ReInfo.needAlternativeMangling (),
1871
+ ReInfo.hasDroppedMetatypeArgs ());
1858
1872
}
1859
1873
}
1860
1874
LLVM_DEBUG (llvm::dbgs () << " Specialized function " << ClonedName << ' \n ' );
@@ -1995,6 +2009,9 @@ prepareCallArguments(ApplySite AI, SILBuilder &Builder,
1995
2009
return true ;
1996
2010
}
1997
2011
2012
+ if (ReInfo.isDroppedMetatypeArg (ArgIdx))
2013
+ return true ;
2014
+
1998
2015
// Handle arguments for formal parameters.
1999
2016
unsigned paramIdx = ArgIdx - substConv.getSILArgIndexOfFirstParam ();
2000
2017
if (!ReInfo.isParamConverted (paramIdx)) {
@@ -2418,7 +2435,7 @@ static bool createPrespecialized(StringRef UnspecializedName,
2418
2435
ReabstractionInfo ReInfo (M.getSwiftModule (), M.isWholeModule (), ApplySite (),
2419
2436
UnspecFunc, Apply.getSubstitutionMap (),
2420
2437
IsNotSerialized,
2421
- /* ConvertIndirectToDirect=*/ true , nullptr );
2438
+ /* ConvertIndirectToDirect=*/ true );
2422
2439
2423
2440
if (!ReInfo.canBeSpecialized ())
2424
2441
return false ;
@@ -2599,7 +2616,9 @@ void swift::trySpecializeApplyOfGeneric(
2599
2616
ReabstractionInfo ReInfo (FuncBuilder.getModule ().getSwiftModule (),
2600
2617
FuncBuilder.getModule ().isWholeModule (), Apply, RefF,
2601
2618
Apply.getSubstitutionMap (), Serialized,
2602
- /* ConvertIndirectToDirect=*/ true , &ORE);
2619
+ /* ConvertIndirectToDirect=*/ true ,
2620
+ /* dropMetatypeArgs=*/ isMandatory,
2621
+ &ORE);
2603
2622
if (!ReInfo.canBeSpecialized ())
2604
2623
return ;
2605
2624
0 commit comments