Skip to content

Commit de18384

Browse files
committed
[AST] Don’t deserialize members of @objc protocol looking for associated types
Thanks to @slavapestov for pointing this out! The optimization to avoid looking through the members of a protocol that can’t possibly have any associated types was for both deserialized protocols and imported protocols, but I only supported the former in my previous change. Check both cases and make the reasons much more obvious. Also, that change resolved an existing compiler crasher as well.
1 parent 83e41da commit de18384

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/AST/Decl.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3651,13 +3651,22 @@ ProtocolDecl::getInheritedProtocols() const {
36513651
llvm::TinyPtrVector<AssociatedTypeDecl *>
36523652
ProtocolDecl::getAssociatedTypeMembers() const {
36533653
llvm::TinyPtrVector<AssociatedTypeDecl *> result;
3654-
if (!hasClangNode()) {
3655-
for (auto member : getMembers()) {
3656-
if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
3657-
result.push_back(ATD);
3658-
}
3654+
3655+
// Clang-imported protocols never have associated types.
3656+
if (hasClangNode())
3657+
return result;
3658+
3659+
// Deserialized @objc protocols never have associated types.
3660+
if (!getParentSourceFile() && isObjC())
3661+
return result;
3662+
3663+
// Find the associated type declarations.
3664+
for (auto member : getMembers()) {
3665+
if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
3666+
result.push_back(ATD);
36593667
}
36603668
}
3669+
36613670
return result;
36623671
}
36633672

validation-test/compiler_crashers/28859-resolver-unable-to-resolve-type-witness.swift renamed to validation-test/compiler_crashers_fixed/28859-resolver-unable-to-resolve-type-witness.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
class a:P@objc protocol P{{}func a:a{}{}typealias a

0 commit comments

Comments
 (0)