Skip to content

Commit cbdc853

Browse files
committed
[AST] Move GenericSignatureKey to ASTContext.cpp
1 parent 9a33b00 commit cbdc853

File tree

2 files changed

+52
-53
lines changed

2 files changed

+52
-53
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -870,21 +870,6 @@ class ASTContext final {
870870
/// This guarantees that resulted \p names doesn't have duplicated names.
871871
void getVisibleTopLevelModuleNames(SmallVectorImpl<Identifier> &names) const;
872872

873-
struct OverrideSignatureKey {
874-
GenericSignature *baseMethodSig;
875-
GenericSignature *derivedClassSig;
876-
Type superclassTy;
877-
878-
OverrideSignatureKey(GenericSignature *baseMethodSignature,
879-
GenericSignature *derivedClassSignature,
880-
Type superclassType)
881-
: baseMethodSig(baseMethodSignature),
882-
derivedClassSig(derivedClassSignature), superclassTy(superclassType) {
883-
}
884-
};
885-
886-
llvm::DenseMap<OverrideSignatureKey, GenericSignature *> overrideSigCache;
887-
888873
private:
889874
/// Register the given generic signature builder to be used as the canonical
890875
/// generic signature builder for the given signature, if we don't already
@@ -954,39 +939,4 @@ class ASTContext final {
954939

955940
} // end namespace swift
956941

957-
namespace llvm {
958-
template <> struct DenseMapInfo<swift::ASTContext::OverrideSignatureKey> {
959-
using OverrideSignatureKey = swift::ASTContext::OverrideSignatureKey;
960-
using Type = swift::Type;
961-
using GenericSignature = swift::GenericSignature;
962-
963-
static bool isEqual(const OverrideSignatureKey lhs,
964-
const OverrideSignatureKey rhs) {
965-
return lhs.baseMethodSig == rhs.baseMethodSig &&
966-
lhs.derivedClassSig == rhs.derivedClassSig &&
967-
lhs.superclassTy.getPointer() == rhs.superclassTy.getPointer();
968-
}
969-
970-
static inline OverrideSignatureKey getEmptyKey() {
971-
return OverrideSignatureKey(DenseMapInfo<GenericSignature *>::getEmptyKey(),
972-
DenseMapInfo<GenericSignature *>::getEmptyKey(),
973-
DenseMapInfo<Type>::getEmptyKey());
974-
}
975-
976-
static inline OverrideSignatureKey getTombstoneKey() {
977-
return OverrideSignatureKey(
978-
DenseMapInfo<GenericSignature *>::getTombstoneKey(),
979-
DenseMapInfo<GenericSignature *>::getTombstoneKey(),
980-
DenseMapInfo<Type>::getTombstoneKey());
981-
}
982-
983-
static unsigned getHashValue(const OverrideSignatureKey &Val) {
984-
return hash_combine(
985-
DenseMapInfo<GenericSignature *>::getHashValue(Val.baseMethodSig),
986-
DenseMapInfo<GenericSignature *>::getHashValue(Val.derivedClassSig),
987-
DenseMapInfo<Type>::getHashValue(Val.superclassTy));
988-
}
989-
};
990-
} // namespace llvm
991-
992942
#endif

lib/AST/ASTContext.cpp

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,52 @@ using AssociativityCacheType =
100100
MACRO(NSNumber) \
101101
MACRO(NSValue)
102102

103+
struct OverrideSignatureKey {
104+
GenericSignature *baseMethodSig;
105+
GenericSignature *derivedClassSig;
106+
Type superclassTy;
107+
108+
OverrideSignatureKey(GenericSignature *baseMethodSignature,
109+
GenericSignature *derivedClassSignature,
110+
Type superclassType)
111+
: baseMethodSig(baseMethodSignature),
112+
derivedClassSig(derivedClassSignature), superclassTy(superclassType) {}
113+
};
114+
115+
namespace llvm {
116+
template <> struct DenseMapInfo<OverrideSignatureKey> {
117+
using Type = swift::Type;
118+
using GenericSignature = swift::GenericSignature;
119+
120+
static bool isEqual(const OverrideSignatureKey lhs,
121+
const OverrideSignatureKey rhs) {
122+
return lhs.baseMethodSig == rhs.baseMethodSig &&
123+
lhs.derivedClassSig == rhs.derivedClassSig &&
124+
lhs.superclassTy.getPointer() == rhs.superclassTy.getPointer();
125+
}
126+
127+
static inline OverrideSignatureKey getEmptyKey() {
128+
return OverrideSignatureKey(DenseMapInfo<GenericSignature *>::getEmptyKey(),
129+
DenseMapInfo<GenericSignature *>::getEmptyKey(),
130+
DenseMapInfo<Type>::getEmptyKey());
131+
}
132+
133+
static inline OverrideSignatureKey getTombstoneKey() {
134+
return OverrideSignatureKey(
135+
DenseMapInfo<GenericSignature *>::getTombstoneKey(),
136+
DenseMapInfo<GenericSignature *>::getTombstoneKey(),
137+
DenseMapInfo<Type>::getTombstoneKey());
138+
}
139+
140+
static unsigned getHashValue(const OverrideSignatureKey &Val) {
141+
return hash_combine(
142+
DenseMapInfo<GenericSignature *>::getHashValue(Val.baseMethodSig),
143+
DenseMapInfo<GenericSignature *>::getHashValue(Val.derivedClassSig),
144+
DenseMapInfo<Type>::getHashValue(Val.superclassTy));
145+
}
146+
};
147+
} // namespace llvm
148+
103149
struct ASTContext::Implementation {
104150
Implementation();
105151
~Implementation();
@@ -422,6 +468,8 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
422468
llvm::FoldingSet<SILLayout> SILLayouts;
423469

424470
RC<syntax::SyntaxArena> TheSyntaxArena;
471+
472+
llvm::DenseMap<OverrideSignatureKey, GenericSignature *> overrideSigCache;
425473
};
426474

427475
ASTContext::Implementation::Implementation()
@@ -4383,8 +4431,9 @@ GenericSignature *ASTContext::getOverrideGenericSignature(ValueDecl *base,
43834431
derivedClass->getGenericSignature(),
43844432
derivedClass->getSuperclass());
43854433

4386-
if (overrideSigCache.count(key) == 1) {
4387-
return overrideSigCache.lookup(key);
4434+
if (getImpl().overrideSigCache.find(key) !=
4435+
getImpl().overrideSigCache.end()) {
4436+
return getImpl().overrideSigCache.lookup(key);
43884437
}
43894438

43904439
if (auto *derivedSig = derivedClass->getGenericSignature())
@@ -4437,7 +4486,7 @@ GenericSignature *ASTContext::getOverrideGenericSignature(ValueDecl *base,
44374486
}
44384487

44394488
auto *genericSig = std::move(builder).computeGenericSignature(SourceLoc());
4440-
overrideSigCache.insert(std::make_pair(key, genericSig));
4489+
getImpl().overrideSigCache.insert(std::make_pair(key, genericSig));
44414490
return genericSig;
44424491
}
44434492

0 commit comments

Comments
 (0)