Skip to content

Commit 5af04d3

Browse files
authored
Move operator lookup tables onto SourceLookupCache (#30587)
Move operator lookup tables onto SourceLookupCache
2 parents c1fe0e3 + 4e42f03 commit 5af04d3

19 files changed

+275
-221
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
4949
PropertyWrapperMutability)
5050
SWIFT_TYPEID_NAMED(ParamDecl *, ParamDecl)
5151
SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)
52+
SWIFT_TYPEID_NAMED(PostfixOperatorDecl *, PostfixOperatorDecl)
5253
SWIFT_TYPEID_NAMED(PrecedenceGroupDecl *, PrecedenceGroupDecl)
54+
SWIFT_TYPEID_NAMED(PrefixOperatorDecl *, PrefixOperatorDecl)
5355
SWIFT_TYPEID_NAMED(ProtocolDecl *, ProtocolDecl)
5456
SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
5557
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class OpaqueTypeDecl;
4343
class PatternBindingEntry;
4444
class ParamDecl;
4545
enum class ParamSpecifier : uint8_t;
46+
class PostfixOperatorDecl;
4647
class PrecedenceGroupDecl;
48+
class PrefixOperatorDecl;
4749
struct PropertyWrapperBackingPropertyInfo;
4850
struct PropertyWrapperTypeInfo;
4951
enum class CtorInitializerKind;

include/swift/AST/FileUnit.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ class FileUnit : public DeclContext {
196196
SmallVectorImpl<Decl*> &Results,
197197
llvm::function_ref<bool(DeclAttributes)> matchAttributes) const;
198198

199+
/// Finds all operator decls in this file.
200+
///
201+
/// This does a simple local lookup, not recursively looking through imports.
202+
/// The order of the results is not guaranteed to be meaningful.
203+
virtual void
204+
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const {}
205+
199206
/// Finds all precedence group decls in this file.
200207
///
201208
/// This does a simple local lookup, not recursively looking through imports.

include/swift/AST/Module.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class OverlayFile;
165165
///
166166
/// \sa FileUnit
167167
class ModuleDecl : public DeclContext, public TypeDecl {
168+
friend class DirectOperatorLookupRequest;
169+
friend class DirectPrecedenceGroupLookupRequest;
170+
168171
public:
169172
typedef ArrayRef<Located<Identifier>> AccessPathTy;
170173
typedef std::pair<ModuleDecl::AccessPathTy, ModuleDecl*> ImportedModule;
@@ -620,6 +623,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
620623
/// The order of the results is not guaranteed to be meaningful.
621624
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const;
622625

626+
/// Finds all operator decls of this module.
627+
///
628+
/// This does a simple local lookup, not recursively looking through imports.
629+
/// The order of the results is not guaranteed to be meaningful.
630+
void getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const;
631+
623632
/// Finds all precedence group decls of this module.
624633
///
625634
/// This does a simple local lookup, not recursively looking through imports.

include/swift/AST/NameLookupRequests.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,19 +598,23 @@ template <typename OperatorType>
598598
class LookupOperatorRequest
599599
: public SimpleRequest<LookupOperatorRequest<OperatorType>,
600600
OperatorType *(OperatorLookupDescriptor),
601-
CacheKind::Uncached> {
601+
CacheKind::Cached> {
602602
using SimpleRequest<LookupOperatorRequest<OperatorType>,
603603
OperatorType *(OperatorLookupDescriptor),
604-
CacheKind::Uncached>::SimpleRequest;
604+
CacheKind::Cached>::SimpleRequest;
605605

606606
private:
607607
friend SimpleRequest<LookupOperatorRequest<OperatorType>,
608608
OperatorType *(OperatorLookupDescriptor),
609-
CacheKind::Uncached>;
609+
CacheKind::Cached>;
610610

611611
// Evaluation.
612612
OperatorType *
613613
evaluate(Evaluator &evaluator, OperatorLookupDescriptor desc) const;
614+
615+
public:
616+
// Cached.
617+
bool isCached() const { return true; }
614618
};
615619

616620
using LookupPrefixOperatorRequest = LookupOperatorRequest<PrefixOperatorDecl>;

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ SWIFT_REQUEST(NameLookup, UnqualifiedLookupRequest,
8787

8888
SWIFT_REQUEST(NameLookup, LookupPrefixOperatorRequest,
8989
PrefixOperatorDecl *(OperatorLookupDescriptor),
90-
Uncached, NoLocationInfo)
90+
Cached, NoLocationInfo)
9191
SWIFT_REQUEST(NameLookup, LookupInfixOperatorRequest,
9292
InfixOperatorDecl *(OperatorLookupDescriptor),
93-
Uncached, NoLocationInfo)
93+
Cached, NoLocationInfo)
9494
SWIFT_REQUEST(NameLookup, LookupPostfixOperatorRequest,
9595
PostfixOperatorDecl *(OperatorLookupDescriptor),
96-
Uncached, NoLocationInfo)
96+
Cached, NoLocationInfo)
9797
SWIFT_REQUEST(NameLookup, LookupPrecedenceGroupRequest,
9898
PrecedenceGroupDecl *(OperatorLookupDescriptor),
99-
Uncached, NoLocationInfo)
99+
Cached, NoLocationInfo)

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,6 @@ class SourceFile final : public FileUnit {
311311
/// List of Objective-C member conflicts we have found during type checking.
312312
std::vector<ObjCMethodConflict> ObjCMethodConflicts;
313313

314-
template <typename T>
315-
using OperatorMap = llvm::DenseMap<Identifier,llvm::PointerIntPair<T,1,bool>>;
316-
317-
OperatorMap<InfixOperatorDecl*> InfixOperators;
318-
OperatorMap<PostfixOperatorDecl*> PostfixOperators;
319-
OperatorMap<PrefixOperatorDecl*> PrefixOperators;
320-
OperatorMap<PrecedenceGroupDecl*> PrecedenceGroups;
321-
322314
/// Describes what kind of file this is, which can affect some type checking
323315
/// and other behavior.
324316
const SourceFileKind Kind;
@@ -448,6 +440,9 @@ class SourceFile final : public FileUnit {
448440
public:
449441
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
450442

443+
virtual void
444+
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const override;
445+
451446
virtual void
452447
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &results) const override;
453448

include/swift/Basic/Statistics.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ FRONTEND_STATISTIC(AST, NumLocalTypeDecls)
130130
/// Number of Objective-C declarations in the AST context.
131131
FRONTEND_STATISTIC(AST, NumObjCMethods)
132132

133-
/// Number of infix, postfix, and prefix operators in the AST context.
134-
FRONTEND_STATISTIC(AST, NumInfixOperators)
135-
FRONTEND_STATISTIC(AST, NumPostfixOperators)
136-
FRONTEND_STATISTIC(AST, NumPrefixOperators)
133+
/// Number of operators in the AST context.
134+
FRONTEND_STATISTIC(AST, NumOperators)
137135

138136
/// Number of precedence groups in the AST context.
139137
FRONTEND_STATISTIC(AST, NumPrecedenceGroups)

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ class SerializedASTFile final : public LoadedFile {
384384
SmallVectorImpl<Decl*> &Results,
385385
llvm::function_ref<bool(DeclAttributes)> matchAttributes) const override;
386386

387+
virtual void
388+
getOperatorDecls(SmallVectorImpl<OperatorDecl *> &results) const override;
389+
387390
virtual void
388391
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const override;
389392

0 commit comments

Comments
 (0)