Skip to content

Commit 049ba39

Browse files
committed
Address review comments
1 parent 7933b4f commit 049ba39

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

include/swift/AST/Substitution.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class Substitution {
4848

4949
Substitution(Type Replacement, ArrayRef<ProtocolConformanceRef> Conformance);
5050

51+
/// Checks whether the current substituion is canonical.
52+
bool isCanonical() const;
53+
5154
/// Get the canonicalized substitution. If wasCanonical is not nullptr,
5255
/// store there whether the current substitution was canonical already.
5356
Substitution getCanonicalSubstitution(bool *wasCanonical = nullptr) const;

lib/AST/ProtocolConformance.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,11 +1073,8 @@ bool ProtocolConformance::isCanonical() const {
10731073

10741074
switch (getKind()) {
10751075
case ProtocolConformanceKind::Normal: {
1076-
auto normalConformance = cast<NormalProtocolConformance>(this);
1077-
auto sigConformances = normalConformance->getSignatureConformances();
1078-
for (auto conf : sigConformances)
1079-
if (!conf.isCanonical())
1080-
return false;
1076+
// Normal conformances are considered canonical by
1077+
// construction.
10811078
return true;
10821079
}
10831080
case ProtocolConformanceKind::Inherited: {
@@ -1093,13 +1090,9 @@ bool ProtocolConformance::isCanonical() const {
10931090
if (!genericConformance->isCanonical())
10941091
return false;
10951092
auto specSubs = spec->getGenericSubstitutions();
1096-
for (auto sub : specSubs) {
1097-
if (!sub.getReplacement()->isCanonical())
1093+
for (const auto &sub : specSubs) {
1094+
if (!sub.isCanonical())
10981095
return false;
1099-
for (auto conf : sub.getConformances()) {
1100-
if (!conf.isCanonical())
1101-
return false;
1102-
}
11031096
}
11041097
return true;
11051098
}

lib/AST/Substitution.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ Substitution::Substitution(Type Replacement,
4242
assert(Replacement->isMaterializable()
4343
&& "cannot substitute with a non-materializable type");
4444
}
45+
46+
bool Substitution::isCanonical() const {
47+
if (!getReplacement()->isCanonical())
48+
return false;
49+
for (auto conf : getConformances()) {
50+
if (!conf.isCanonical())
51+
return false;
52+
}
53+
return true;
54+
}

0 commit comments

Comments
 (0)