Skip to content

Commit 61ecdea

Browse files
committed
Sema: Replace sole usage of TypeDecl::hasMarking() with getDirectlyInheritedNominalTypeDecls()
1 parent 816f3e6 commit 61ecdea

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,10 +4373,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
43734373
/// Type if it `isEscapable` instead of using this.
43744374
CanBeInvertible::Result canBeEscapable() const;
43754375

4376-
/// Determine whether this type has `: <target>` stated explicitly in
4377-
/// its inheritance clause.
4378-
bool hasMarking(InvertibleProtocolKind target) const;
4379-
43804376
/// Determine whether this type has ~<target>` stated on
43814377
/// itself, one of its inherited types or `Self` requirements.
43824378
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;

lib/AST/Decl.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6652,33 +6652,6 @@ findInverseInInheritance(InheritedTypes inherited,
66526652
return inverse;
66536653
}
66546654

6655-
bool NominalTypeDecl::hasMarking(InvertibleProtocolKind target) const {
6656-
InverseMarking::Mark mark;
6657-
6658-
std::function<bool(Type)> isTarget = [&](Type t) -> bool {
6659-
if (auto kp = t->getKnownProtocol()) {
6660-
if (auto ip = getInvertibleProtocolKind(*kp))
6661-
return *ip == target;
6662-
} else if (auto pct = t->getAs<ProtocolCompositionType>()) {
6663-
return llvm::any_of(pct->getMembers(), isTarget);
6664-
}
6665-
6666-
return false;
6667-
};
6668-
6669-
findInheritedType(getInherited(),
6670-
[&](Type inheritedTy, NullablePtr<TypeRepr> repr) {
6671-
if (!isTarget(inheritedTy))
6672-
return false;
6673-
6674-
mark = InverseMarking::Mark(
6675-
InverseMarking::Kind::Explicit,
6676-
repr.isNull() ? SourceLoc() : repr.get()->getLoc());
6677-
return true;
6678-
});
6679-
return mark;
6680-
}
6681-
66826655
InverseMarking::Mark
66836656
AssociatedTypeDecl::hasInverseMarking(InvertibleProtocolKind target) const {
66846657
auto &ctx = getASTContext();

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ static void emitAdviceToApplyInverseAfter(InFlightDiagnostic &&diag,
6060
diag.flush();
6161

6262
// Have no advice for situations where the KP conformance is explicit.
63-
if (nominal->hasMarking(ip))
64-
return;
63+
InvertibleProtocolSet inverses;
64+
bool anyObject = false;
65+
auto inheritedNominals = getDirectlyInheritedNominalTypeDecls(
66+
nominal, inverses, anyObject);
67+
for (auto entry : inheritedNominals) {
68+
if (auto *otherProto = dyn_cast<ProtocolDecl>(entry.Item)) {
69+
if (otherProto->isSpecificProtocol(kp))
70+
return;
71+
}
72+
}
6573

6674
auto &ctx = nominal->getASTContext();
6775

0 commit comments

Comments
 (0)