@@ -918,63 +918,69 @@ bool ProtocolConformance::isVisibleFrom(const DeclContext *dc) const {
918
918
return true ;
919
919
}
920
920
921
- ProtocolConformance *
921
+ ProtocolConformanceRef
922
922
ProtocolConformance::subst (SubstitutionMap subMap,
923
923
SubstOptions options) const {
924
924
InFlightSubstitutionViaSubMap IFS (subMap, options);
925
925
return subst (IFS);
926
926
}
927
927
928
- ProtocolConformance *
928
+ ProtocolConformanceRef
929
929
ProtocolConformance::subst (TypeSubstitutionFn subs,
930
930
LookupConformanceFn conformances,
931
931
SubstOptions options) const {
932
932
InFlightSubstitution IFS (subs, conformances, options);
933
933
return subst (IFS);
934
934
}
935
935
936
- ProtocolConformance *
936
+ ProtocolConformanceRef
937
937
ProtocolConformance::subst (InFlightSubstitution &IFS) const {
938
+ auto *mutableThis = const_cast <ProtocolConformance *>(this );
939
+
938
940
switch (getKind ()) {
939
941
case ProtocolConformanceKind::Normal: {
940
942
auto origType = getType ();
941
943
if (!origType->hasTypeParameter () &&
942
944
!origType->hasArchetype ())
943
- return const_cast <ProtocolConformance *>( this );
945
+ return ProtocolConformanceRef (mutableThis );
944
946
945
947
auto substType = origType.subst (IFS);
946
948
if (substType->isEqual (origType))
947
- return const_cast <ProtocolConformance *>( this );
949
+ return ProtocolConformanceRef (mutableThis );
948
950
951
+ auto *generic = cast<NormalProtocolConformance>(mutableThis);
949
952
auto subMap = SubstitutionMap::get (getGenericSignature (), IFS);
950
953
951
- auto *mutableThis = const_cast <ProtocolConformance *>(this );
952
- return substType->getASTContext ()
953
- .getSpecializedConformance (substType,
954
- cast<NormalProtocolConformance>(mutableThis),
955
- subMap);
954
+ auto &ctx = substType->getASTContext ();
955
+ auto *concrete = ctx.getSpecializedConformance (substType, generic, subMap);
956
+
957
+ return ProtocolConformanceRef (concrete);
956
958
}
959
+
957
960
case ProtocolConformanceKind::Builtin: {
958
961
auto origType = getType ();
959
962
if (!origType->hasTypeParameter () &&
960
963
!origType->hasArchetype ())
961
- return const_cast <ProtocolConformance *>( this );
964
+ return ProtocolConformanceRef (mutableThis );
962
965
963
966
auto substType = origType.subst (IFS);
964
967
965
968
// We do an exact pointer equality check because subst() can
966
969
// change sugar.
967
970
if (substType.getPointer () == origType.getPointer ())
968
- return const_cast <ProtocolConformance *>( this );
971
+ return ProtocolConformanceRef (mutableThis );
969
972
970
973
auto kind = cast<BuiltinProtocolConformance>(this )
971
974
->getBuiltinConformanceKind ();
972
975
973
- return substType->getASTContext ()
976
+ auto *concrete = substType->getASTContext ()
974
977
.getBuiltinConformance (substType, getProtocol (), kind);
978
+ return ProtocolConformanceRef (concrete);
975
979
}
980
+
976
981
case ProtocolConformanceKind::Self:
977
- return const_cast <ProtocolConformance*>(this );
982
+ return ProtocolConformanceRef (mutableThis);
983
+
978
984
case ProtocolConformanceKind::Inherited: {
979
985
// Substitute the base.
980
986
auto inheritedConformance
@@ -983,31 +989,39 @@ ProtocolConformance::subst(InFlightSubstitution &IFS) const {
983
989
auto origType = getType ();
984
990
if (!origType->hasTypeParameter () &&
985
991
!origType->hasArchetype ()) {
986
- return const_cast <ProtocolConformance *>( this );
992
+ return ProtocolConformanceRef (mutableThis );
987
993
}
988
994
989
995
auto origBaseType = inheritedConformance->getType ();
990
996
if (origBaseType->hasTypeParameter () ||
991
997
origBaseType->hasArchetype ()) {
992
998
// Substitute into the superclass.
993
- inheritedConformance = inheritedConformance->subst (IFS);
999
+ auto substConformance = inheritedConformance->subst (IFS);
1000
+ if (!substConformance.isConcrete ())
1001
+ return substConformance;
1002
+
1003
+ inheritedConformance = substConformance.getConcrete ();
994
1004
}
995
1005
996
1006
auto substType = origType.subst (IFS);
997
- return substType->getASTContext ()
1007
+ auto *concrete = substType->getASTContext ()
998
1008
.getInheritedConformance (substType, inheritedConformance);
1009
+ return ProtocolConformanceRef (concrete);
999
1010
}
1011
+
1000
1012
case ProtocolConformanceKind::Specialized: {
1001
1013
// Substitute the substitutions in the specialized conformance.
1002
1014
auto spec = cast<SpecializedProtocolConformance>(this );
1003
- auto genericConformance = spec->getGenericConformance ();
1004
- auto subMap = spec->getSubstitutionMap ();
1005
1015
1006
- auto origType = getType ();
1007
- auto substType = origType.subst (IFS);
1008
- return substType->getASTContext ()
1009
- .getSpecializedConformance (substType, genericConformance,
1010
- subMap.subst (IFS));
1016
+ auto *generic = spec->getGenericConformance ();
1017
+ auto subMap = spec->getSubstitutionMap ().subst (IFS);
1018
+
1019
+ auto substType = spec->getType ().subst (IFS);
1020
+
1021
+ auto &ctx = substType->getASTContext ();
1022
+ auto *concrete = ctx.getSpecializedConformance (substType, generic, subMap);
1023
+
1024
+ return ProtocolConformanceRef (concrete);
1011
1025
}
1012
1026
}
1013
1027
llvm_unreachable (" bad ProtocolConformanceKind" );
0 commit comments