Skip to content

[Name lookup] Use decl-based name lookup more regularly #18539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class alignas(1 << DeclAlignInBits) Decl {
HasLazyConformances : 1
);

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

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

/// Whether we are currently computing inherited protocols.
ComputingInheritedProtocols : 1,

/// The stage of the circularity check for this protocol.
Circularity : 2,

Expand Down
10 changes: 0 additions & 10 deletions include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ class LazyResolver {
/// considered to be members of the extended type.
virtual void resolveExtension(ExtensionDecl *ext) = 0;

using ConformanceConstructionInfo = std::pair<SourceLoc, ProtocolDecl *>;
/// Resolve enough of an extension to find which protocols it is declaring
/// conformance to.
///
/// This can be called to ensure that the "extension Foo: Bar, Baz" part of
/// the extension is understood.
virtual void resolveExtensionForConformanceConstruction(
ExtensionDecl *ext,
SmallVectorImpl<ConformanceConstructionInfo> &protocols) = 0;

/// Resolve any implicitly-declared constructors within the given nominal.
virtual void resolveImplicitConstructors(NominalTypeDecl *nominal) = 0;

Expand Down
24 changes: 24 additions & 0 deletions include/swift/AST/NameLookupRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ class ExtendedNominalRequest :
void noteCycleStep(DiagnosticEngine &diags) const;
};

/// Request the nominal types that occur as the right-hand side of "Self: Foo"
/// constraints in the "where" clause of a protocol extension.
class SelfBoundsFromWhereClauseRequest :
public SimpleRequest<SelfBoundsFromWhereClauseRequest,
CacheKind::Uncached,
llvm::TinyPtrVector<NominalTypeDecl *>,
ExtensionDecl *> {
public:
using SimpleRequest::SimpleRequest;

private:
friend class SimpleRequest;

// Evaluation.
llvm::TinyPtrVector<NominalTypeDecl *> evaluate(Evaluator &evaluator,
ExtensionDecl *ext) const;

public:
// Cycle handling
llvm::TinyPtrVector<NominalTypeDecl *> breakCycle() const { return { }; }
void diagnoseCycle(DiagnosticEngine &diags) const;
void noteCycleStep(DiagnosticEngine &diags) const;
};

/// The zone number for name-lookup requests.
#define SWIFT_NAME_LOOKUP_REQUESTS_TYPEID_ZONE 9

Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/NameLookupTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ SWIFT_TYPEID(InheritedDeclsReferencedRequest)
SWIFT_TYPEID(UnderlyingTypeDeclsReferencedRequest)
SWIFT_TYPEID(SuperclassDeclRequest)
SWIFT_TYPEID(ExtendedNominalRequest)
SWIFT_TYPEID(SelfBoundsFromWhereClauseRequest)
31 changes: 0 additions & 31 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,31 +2490,6 @@ class Verifier : public ASTWalker {
}
}

/// Check the given list of protocols.
void verifyProtocolList(Decl *decl, ArrayRef<ProtocolDecl *> protocols) {
PrettyStackTraceDecl debugStack("verifying ProtocolList", decl);

// Make sure that the protocol list is fully expanded.
SmallVector<ProtocolDecl *, 4> nominalProtocols(protocols.begin(),
protocols.end());
ProtocolType::canonicalizeProtocols(nominalProtocols);

SmallVector<Type, 4> protocolTypes;
for (auto proto : protocols)
protocolTypes.push_back(proto->getDeclaredType());
auto type = ProtocolCompositionType::get(Ctx, protocolTypes,
/*HasExplicitAnyObject=*/false);
auto layout = type->getExistentialLayout();
SmallVector<ProtocolDecl *, 4> canonicalProtocols;
for (auto *protoTy : layout.getProtocols())
canonicalProtocols.push_back(protoTy->getDecl());
if (nominalProtocols != canonicalProtocols) {
dumpRef(decl);
Out << " doesn't have a complete set of protocols\n";
abort();
}
}

/// Verify that the given conformance makes sense for the given
/// type.
void verifyConformance(Type type, ProtocolConformanceRef conformance) {
Expand Down Expand Up @@ -2731,9 +2706,6 @@ class Verifier : public ASTWalker {
}

void verifyChecked(NominalTypeDecl *nominal) {
// Make sure that the protocol list is fully expanded.
verifyProtocolList(nominal, nominal->getLocalProtocols());

// Make sure that the protocol conformances are complete.
// Only do so within the source file of the nominal type,
// because anywhere else this can trigger new type-check requests.
Expand All @@ -2749,9 +2721,6 @@ class Verifier : public ASTWalker {
}

void verifyChecked(ExtensionDecl *ext) {
// Make sure that the protocol list is fully expanded.
verifyProtocolList(ext, ext->getLocalProtocols());

// Make sure that the protocol conformances are complete.
for (auto conformance : ext->getLocalConformances()) {
verifyConformance(ext, conformance);
Expand Down
Loading