Skip to content

Commit

Permalink
Move operator lookup tables onto SourceLookupCache (#30587)
Browse files Browse the repository at this point in the history
Move operator lookup tables onto SourceLookupCache
  • Loading branch information
hamishknight committed Mar 27, 2020
2 parents c1fe0e3 + 4e42f03 commit 5af04d3
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 221 deletions.
2 changes: 2 additions & 0 deletions include/swift/AST/ASTTypeIDZone.def
Expand Up @@ -49,7 +49,9 @@ SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
PropertyWrapperMutability)
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)
SWIFT_TYPEID_NAMED(PostfixOperatorDecl *, PostfixOperatorDecl)
SWIFT_TYPEID_NAMED(PrecedenceGroupDecl *, PrecedenceGroupDecl)
SWIFT_TYPEID_NAMED(PrefixOperatorDecl *, PrefixOperatorDecl)
SWIFT_TYPEID_NAMED(ProtocolDecl *, ProtocolDecl)
SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/ASTTypeIDs.h
Expand Up @@ -43,7 +43,9 @@ class OpaqueTypeDecl;
class PatternBindingEntry;
class ParamDecl;
enum class ParamSpecifier : uint8_t;
class PostfixOperatorDecl;
class PrecedenceGroupDecl;
class PrefixOperatorDecl;
struct PropertyWrapperBackingPropertyInfo;
struct PropertyWrapperTypeInfo;
enum class CtorInitializerKind;
Expand Down
7 changes: 7 additions & 0 deletions include/swift/AST/FileUnit.h
Expand Up @@ -196,6 +196,13 @@ class FileUnit : public DeclContext {
SmallVectorImpl<Decl*> &Results,
llvm::function_ref<bool(DeclAttributes)> matchAttributes) const;

/// Finds all operator decls in this file.
///
/// This does a simple local lookup, not recursively looking through imports.
/// The order of the results is not guaranteed to be meaningful.
virtual void
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const {}

/// Finds all precedence group decls in this file.
///
/// This does a simple local lookup, not recursively looking through imports.
Expand Down
9 changes: 9 additions & 0 deletions include/swift/AST/Module.h
Expand Up @@ -165,6 +165,9 @@ class OverlayFile;
///
/// \sa FileUnit
class ModuleDecl : public DeclContext, public TypeDecl {
friend class DirectOperatorLookupRequest;
friend class DirectPrecedenceGroupLookupRequest;

public:
typedef ArrayRef<Located<Identifier>> AccessPathTy;
typedef std::pair<ModuleDecl::AccessPathTy, ModuleDecl*> ImportedModule;
Expand Down Expand Up @@ -620,6 +623,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
/// The order of the results is not guaranteed to be meaningful.
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const;

/// Finds all operator decls of this module.
///
/// This does a simple local lookup, not recursively looking through imports.
/// The order of the results is not guaranteed to be meaningful.
void getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const;

/// Finds all precedence group decls of this module.
///
/// This does a simple local lookup, not recursively looking through imports.
Expand Down
10 changes: 7 additions & 3 deletions include/swift/AST/NameLookupRequests.h
Expand Up @@ -598,19 +598,23 @@ template <typename OperatorType>
class LookupOperatorRequest
: public SimpleRequest<LookupOperatorRequest<OperatorType>,
OperatorType *(OperatorLookupDescriptor),
CacheKind::Uncached> {
CacheKind::Cached> {
using SimpleRequest<LookupOperatorRequest<OperatorType>,
OperatorType *(OperatorLookupDescriptor),
CacheKind::Uncached>::SimpleRequest;
CacheKind::Cached>::SimpleRequest;

private:
friend SimpleRequest<LookupOperatorRequest<OperatorType>,
OperatorType *(OperatorLookupDescriptor),
CacheKind::Uncached>;
CacheKind::Cached>;

// Evaluation.
OperatorType *
evaluate(Evaluator &evaluator, OperatorLookupDescriptor desc) const;

public:
// Cached.
bool isCached() const { return true; }
};

using LookupPrefixOperatorRequest = LookupOperatorRequest<PrefixOperatorDecl>;
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/NameLookupTypeIDZone.def
Expand Up @@ -87,13 +87,13 @@ SWIFT_REQUEST(NameLookup, UnqualifiedLookupRequest,

SWIFT_REQUEST(NameLookup, LookupPrefixOperatorRequest,
PrefixOperatorDecl *(OperatorLookupDescriptor),
Uncached, NoLocationInfo)
Cached, NoLocationInfo)
SWIFT_REQUEST(NameLookup, LookupInfixOperatorRequest,
InfixOperatorDecl *(OperatorLookupDescriptor),
Uncached, NoLocationInfo)
Cached, NoLocationInfo)
SWIFT_REQUEST(NameLookup, LookupPostfixOperatorRequest,
PostfixOperatorDecl *(OperatorLookupDescriptor),
Uncached, NoLocationInfo)
Cached, NoLocationInfo)
SWIFT_REQUEST(NameLookup, LookupPrecedenceGroupRequest,
PrecedenceGroupDecl *(OperatorLookupDescriptor),
Uncached, NoLocationInfo)
Cached, NoLocationInfo)
11 changes: 3 additions & 8 deletions include/swift/AST/SourceFile.h
Expand Up @@ -311,14 +311,6 @@ class SourceFile final : public FileUnit {
/// List of Objective-C member conflicts we have found during type checking.
std::vector<ObjCMethodConflict> ObjCMethodConflicts;

template <typename T>
using OperatorMap = llvm::DenseMap<Identifier,llvm::PointerIntPair<T,1,bool>>;

OperatorMap<InfixOperatorDecl*> InfixOperators;
OperatorMap<PostfixOperatorDecl*> PostfixOperators;
OperatorMap<PrefixOperatorDecl*> PrefixOperators;
OperatorMap<PrecedenceGroupDecl*> PrecedenceGroups;

/// Describes what kind of file this is, which can affect some type checking
/// and other behavior.
const SourceFileKind Kind;
Expand Down Expand Up @@ -448,6 +440,9 @@ class SourceFile final : public FileUnit {
public:
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;

virtual void
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const override;

virtual void
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &results) const override;

Expand Down
6 changes: 2 additions & 4 deletions include/swift/Basic/Statistics.def
Expand Up @@ -130,10 +130,8 @@ FRONTEND_STATISTIC(AST, NumLocalTypeDecls)
/// Number of Objective-C declarations in the AST context.
FRONTEND_STATISTIC(AST, NumObjCMethods)

/// Number of infix, postfix, and prefix operators in the AST context.
FRONTEND_STATISTIC(AST, NumInfixOperators)
FRONTEND_STATISTIC(AST, NumPostfixOperators)
FRONTEND_STATISTIC(AST, NumPrefixOperators)
/// Number of operators in the AST context.
FRONTEND_STATISTIC(AST, NumOperators)

/// Number of precedence groups in the AST context.
FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Serialization/SerializedModuleLoader.h
Expand Up @@ -384,6 +384,9 @@ class SerializedASTFile final : public LoadedFile {
SmallVectorImpl<Decl*> &Results,
llvm::function_ref<bool(DeclAttributes)> matchAttributes) const override;

virtual void
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const override;

virtual void
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const override;

Expand Down

0 comments on commit 5af04d3

Please sign in to comment.