Skip to content

Commit 6384d08

Browse files
authored
Merge pull request swiftlang#18539 from DougGregor/unqualified-lookup-via-decls
[Name lookup] Use decl-based name lookup more regularly
2 parents 0926808 + e21673d commit 6384d08

21 files changed

+230
-331
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class alignas(1 << DeclAlignInBits) Decl {
488488
HasLazyConformances : 1
489489
);
490490

491-
SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+1+2+8+16,
491+
SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+2+8+16,
492492
/// Whether the \c RequiresClass bit is valid.
493493
RequiresClassValid : 1,
494494

@@ -511,9 +511,6 @@ class alignas(1 << DeclAlignInBits) Decl {
511511
/// because they could not be imported from Objective-C).
512512
HasMissingRequirements : 1,
513513

514-
/// Whether we are currently computing inherited protocols.
515-
ComputingInheritedProtocols : 1,
516-
517514
/// The stage of the circularity check for this protocol.
518515
Circularity : 2,
519516

include/swift/AST/LazyResolver.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ class LazyResolver {
7272
/// considered to be members of the extended type.
7373
virtual void resolveExtension(ExtensionDecl *ext) = 0;
7474

75-
using ConformanceConstructionInfo = std::pair<SourceLoc, ProtocolDecl *>;
76-
/// Resolve enough of an extension to find which protocols it is declaring
77-
/// conformance to.
78-
///
79-
/// This can be called to ensure that the "extension Foo: Bar, Baz" part of
80-
/// the extension is understood.
81-
virtual void resolveExtensionForConformanceConstruction(
82-
ExtensionDecl *ext,
83-
SmallVectorImpl<ConformanceConstructionInfo> &protocols) = 0;
84-
8575
/// Resolve any implicitly-declared constructors within the given nominal.
8676
virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) = 0;
8777

include/swift/AST/NameLookupRequests.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ class ExtendedNominalRequest :
184184
void noteCycleStep(DiagnosticEngine &diags) const;
185185
};
186186

187+
/// Request the nominal types that occur as the right-hand side of "Self: Foo"
188+
/// constraints in the "where" clause of a protocol extension.
189+
class SelfBoundsFromWhereClauseRequest :
190+
public SimpleRequest<SelfBoundsFromWhereClauseRequest,
191+
CacheKind::Uncached,
192+
llvm::TinyPtrVector<NominalTypeDecl *>,
193+
ExtensionDecl *> {
194+
public:
195+
using SimpleRequest::SimpleRequest;
196+
197+
private:
198+
friend class SimpleRequest;
199+
200+
// Evaluation.
201+
llvm::TinyPtrVector<NominalTypeDecl *> evaluate(Evaluator &evaluator,
202+
ExtensionDecl *ext) const;
203+
204+
public:
205+
// Cycle handling
206+
llvm::TinyPtrVector<NominalTypeDecl *> breakCycle() const { return { }; }
207+
void diagnoseCycle(DiagnosticEngine &diags) const;
208+
void noteCycleStep(DiagnosticEngine &diags) const;
209+
};
210+
187211
/// The zone number for name-lookup requests.
188212
#define SWIFT_NAME_LOOKUP_REQUESTS_TYPEID_ZONE 9
189213

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ SWIFT_TYPEID(InheritedDeclsReferencedRequest)
1818
SWIFT_TYPEID(UnderlyingTypeDeclsReferencedRequest)
1919
SWIFT_TYPEID(SuperclassDeclRequest)
2020
SWIFT_TYPEID(ExtendedNominalRequest)
21+
SWIFT_TYPEID(SelfBoundsFromWhereClauseRequest)

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,31 +2490,6 @@ class Verifier : public ASTWalker {
24902490
}
24912491
}
24922492

2493-
/// Check the given list of protocols.
2494-
void verifyProtocolList(Decl *decl, ArrayRef<ProtocolDecl *> protocols) {
2495-
PrettyStackTraceDecl debugStack("verifying ProtocolList", decl);
2496-
2497-
// Make sure that the protocol list is fully expanded.
2498-
SmallVector<ProtocolDecl *, 4> nominalProtocols(protocols.begin(),
2499-
protocols.end());
2500-
ProtocolType::canonicalizeProtocols(nominalProtocols);
2501-
2502-
SmallVector<Type, 4> protocolTypes;
2503-
for (auto proto : protocols)
2504-
protocolTypes.push_back(proto->getDeclaredType());
2505-
auto type = ProtocolCompositionType::get(Ctx, protocolTypes,
2506-
/*HasExplicitAnyObject=*/false);
2507-
auto layout = type->getExistentialLayout();
2508-
SmallVector<ProtocolDecl *, 4> canonicalProtocols;
2509-
for (auto *protoTy : layout.getProtocols())
2510-
canonicalProtocols.push_back(protoTy->getDecl());
2511-
if (nominalProtocols != canonicalProtocols) {
2512-
dumpRef(decl);
2513-
Out << " doesn't have a complete set of protocols\n";
2514-
abort();
2515-
}
2516-
}
2517-
25182493
/// Verify that the given conformance makes sense for the given
25192494
/// type.
25202495
void verifyConformance(Type type, ProtocolConformanceRef conformance) {
@@ -2731,9 +2706,6 @@ class Verifier : public ASTWalker {
27312706
}
27322707

27332708
void verifyChecked(NominalTypeDecl *nominal) {
2734-
// Make sure that the protocol list is fully expanded.
2735-
verifyProtocolList(nominal, nominal->getLocalProtocols());
2736-
27372709
// Make sure that the protocol conformances are complete.
27382710
// Only do so within the source file of the nominal type,
27392711
// because anywhere else this can trigger new type-check requests.
@@ -2749,9 +2721,6 @@ class Verifier : public ASTWalker {
27492721
}
27502722

27512723
void verifyChecked(ExtensionDecl *ext) {
2752-
// Make sure that the protocol list is fully expanded.
2753-
verifyProtocolList(ext, ext->getLocalProtocols());
2754-
27552724
// Make sure that the protocol conformances are complete.
27562725
for (auto conformance : ext->getLocalConformances()) {
27572726
verifyConformance(ext, conformance);

0 commit comments

Comments
 (0)