@@ -778,23 +778,21 @@ getSubstitutionsForProtocolConformance(ProtocolConformanceRef CRef) {
778
778
// / \param requirementSig The generic signature of the requirement
779
779
// / \param witnessThunkSig The generic signature of the witness method
780
780
// / \param origSubs The substitutions from the call instruction
781
- // / \param newSubs New substitutions are stored here
782
- static void getWitnessMethodSubstitutions (
783
- SILModule &M,
781
+ static SubstitutionMap
782
+ getWitnessMethodSubstitutions (
784
783
ProtocolConformanceRef conformanceRef,
785
784
GenericSignature *requirementSig,
786
785
GenericSignature *witnessThunkSig,
787
786
SubstitutionList origSubs,
788
- bool isDefaultWitness,
789
- SmallVectorImpl<Substitution> &newSubs) {
787
+ bool isDefaultWitness) {
790
788
791
789
if (witnessThunkSig == nullptr )
792
- return ;
790
+ return SubstitutionMap () ;
793
791
794
- if (isDefaultWitness) {
795
- newSubs. append (origSubs. begin (), origSubs. end ());
796
- return ;
797
- }
792
+ auto origSubMap = requirementSig-> getSubstitutionMap (origSubs);
793
+
794
+ if (isDefaultWitness)
795
+ return origSubMap;
798
796
799
797
assert (!conformanceRef.isAbstract ());
800
798
auto conformance = conformanceRef.getConcrete ();
@@ -809,24 +807,19 @@ static void getWitnessMethodSubstitutions(
809
807
baseDepth = witnessSig->getGenericParams ().back ()->getDepth () + 1 ;
810
808
811
809
auto origDepth = 1 ;
812
- auto origSubMap = requirementSig->getSubstitutionMap (origSubs);
813
810
814
- auto subMap =
815
- SubstitutionMap::combineSubstitutionMaps (baseSubMap,
816
- origSubMap,
817
- CombineSubstitutionMaps::AtDepth,
818
- baseDepth,
819
- origDepth,
820
- witnessThunkSig);
821
-
822
- witnessThunkSig->getSubstitutions (subMap, newSubs);
811
+ return SubstitutionMap::combineSubstitutionMaps (
812
+ baseSubMap,
813
+ origSubMap,
814
+ CombineSubstitutionMaps::AtDepth,
815
+ baseDepth,
816
+ origDepth,
817
+ witnessThunkSig);
823
818
}
824
819
825
- static void getWitnessMethodSubstitutions (ApplySite AI, SILFunction *F,
826
- ProtocolConformanceRef CRef,
827
- SmallVectorImpl<Substitution> &NewSubs) {
828
- auto &Module = AI.getModule ();
829
-
820
+ static SubstitutionMap
821
+ getWitnessMethodSubstitutions (SILModule &Module, ApplySite AI, SILFunction *F,
822
+ ProtocolConformanceRef CRef) {
830
823
auto requirementSig = AI.getOrigCalleeType ()->getGenericSignature ();
831
824
auto witnessThunkSig = F->getLoweredFunctionType ()->getGenericSignature ();
832
825
@@ -839,8 +832,9 @@ static void getWitnessMethodSubstitutions(ApplySite AI, SILFunction *F,
839
832
*Module.getSwiftModule ())
840
833
== CRef.getRequirement ();
841
834
842
- getWitnessMethodSubstitutions (Module, CRef, requirementSig, witnessThunkSig,
843
- origSubs, isDefaultWitness, NewSubs);
835
+ return getWitnessMethodSubstitutions (
836
+ CRef, requirementSig, witnessThunkSig,
837
+ origSubs, isDefaultWitness);
844
838
}
845
839
846
840
// / Generate a new apply of a function_ref to replace an apply of a
@@ -858,14 +852,12 @@ devirtualizeWitnessMethod(ApplySite AI, SILFunction *F,
858
852
// The complete set of substitutions may be different, e.g. because the found
859
853
// witness thunk F may have been created by a specialization pass and have
860
854
// additional generic parameters.
861
- SmallVector<Substitution, 4 > NewSubs;
862
-
863
- getWitnessMethodSubstitutions (AI, F, C, NewSubs);
855
+ auto SubMap = getWitnessMethodSubstitutions (Module, AI, F, C);
864
856
865
857
// Figure out the exact bound type of the function to be called by
866
858
// applying all substitutions.
867
859
auto CalleeCanType = F->getLoweredFunctionType ();
868
- auto SubstCalleeCanType = CalleeCanType->substGenericArgs (Module, NewSubs );
860
+ auto SubstCalleeCanType = CalleeCanType->substGenericArgs (Module, SubMap );
869
861
870
862
// Collect arguments from the apply instruction.
871
863
auto Arguments = SmallVector<SILValue, 4 >();
@@ -894,6 +886,10 @@ devirtualizeWitnessMethod(ApplySite AI, SILFunction *F,
894
886
auto ResultSILType = substConv.getSILResultType ();
895
887
ApplySite SAI;
896
888
889
+ SmallVector<Substitution, 4 > NewSubs;
890
+ if (auto GenericSig = CalleeCanType->getGenericSignature ())
891
+ GenericSig->getSubstitutions (SubMap, NewSubs);
892
+
897
893
SILValue ResultValue;
898
894
if (auto *A = dyn_cast<ApplyInst>(AI)) {
899
895
auto *NewAI =
0 commit comments