Skip to content

Commit 2705eca

Browse files
committed
AST: More accurate SubstitutionMap::isIdentity()
1 parent 6b3a17b commit 2705eca

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "swift/AST/InFlightSubstitution.h"
3232
#include "swift/AST/LazyResolver.h"
3333
#include "swift/AST/Module.h"
34+
#include "swift/AST/PackConformance.h"
3435
#include "swift/AST/ProtocolConformance.h"
3536
#include "swift/AST/TypeCheckRequests.h"
3637
#include "swift/AST/Types.h"
@@ -792,13 +793,29 @@ bool SubstitutionMap::isIdentity() const {
792793
if (empty())
793794
return true;
794795

796+
for (auto conf : getConformances()) {
797+
if (conf.isAbstract())
798+
continue;
799+
800+
if (conf.isPack()) {
801+
auto patternConfs = conf.getPack()->getPatternConformances();
802+
if (patternConfs.size() == 1 && patternConfs[0].isAbstract())
803+
continue;
804+
}
805+
806+
return false;
807+
}
808+
795809
GenericSignature sig = getGenericSignature();
796810
bool hasNonIdentityReplacement = false;
797811
auto replacements = getReplacementTypesBuffer();
798812

799813
sig->forEachParam([&](GenericTypeParamType *paramTy, bool isCanonical) {
800814
if (isCanonical) {
801-
if (!paramTy->isEqual(replacements[0]))
815+
Type wrappedParamTy = paramTy;
816+
if (paramTy->isParameterPack())
817+
wrappedParamTy = PackType::getSingletonPackExpansion(paramTy);
818+
if (!wrappedParamTy->isEqual(replacements[0]))
802819
hasNonIdentityReplacement = true;
803820
}
804821

0 commit comments

Comments
 (0)