Skip to content

Commit 3802c98

Browse files
authored
Improve DML attribute caching, as recommended by Doug. (swiftlang#14697)
1 parent 581c3ac commit 3802c98

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,8 +2869,8 @@ getArgumentLabels(ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
28692869
/// particularly fast in the face of deep class hierarchies or lots of protocol
28702870
/// conformances, but this is fine because it doesn't get invoked in the normal
28712871
/// name lookup path (only when lookup is about to fail).
2872-
static bool hasDynamicMemberLookupAttribute(Type ty,
2873-
llvm::DenseMap<Type, bool> &IsDynamicMemberLookupCache) {
2872+
static bool hasDynamicMemberLookupAttribute(CanType ty,
2873+
llvm::DenseMap<CanType, bool> &IsDynamicMemberLookupCache) {
28742874
auto it = IsDynamicMemberLookupCache.find(ty);
28752875
if (it != IsDynamicMemberLookupCache.end()) return it->second;
28762876

@@ -2879,7 +2879,8 @@ static bool hasDynamicMemberLookupAttribute(Type ty,
28792879
// have the attribute on them.
28802880
if (auto protocolComp = ty->getAs<ProtocolCompositionType>()) {
28812881
for (auto p : protocolComp->getMembers())
2882-
if (hasDynamicMemberLookupAttribute(p, IsDynamicMemberLookupCache))
2882+
if (hasDynamicMemberLookupAttribute(p->getCanonicalType(),
2883+
IsDynamicMemberLookupCache))
28832884
return true;
28842885
return false;
28852886
}
@@ -2917,7 +2918,13 @@ static bool hasDynamicMemberLookupAttribute(Type ty,
29172918
}
29182919
};
29192920

2920-
return IsDynamicMemberLookupCache[ty] = calculate();
2921+
auto result = calculate();
2922+
2923+
// Cache this if we can.
2924+
if (!ty->hasTypeVariable())
2925+
IsDynamicMemberLookupCache[ty] = result;
2926+
2927+
return result;
29212928
}
29222929

29232930

@@ -3307,7 +3314,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
33073314
constraintKind == ConstraintKind::ValueMember &&
33083315
memberName.isSimpleName() && !memberName.isSpecial()) {
33093316
auto name = memberName.getBaseIdentifier();
3310-
if (hasDynamicMemberLookupAttribute(instanceTy,
3317+
if (hasDynamicMemberLookupAttribute(instanceTy->getCanonicalType(),
33113318
IsDynamicMemberLookupCache)) {
33123319
auto &ctx = getASTContext();
33133320
// Recursively look up the subscript(dynamicMember:)'s in this type.

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ class ConstraintSystem {
10361036
/// This is a cache that keeps track of whether a given type is known (or not)
10371037
/// to be a @dynamicMemberLookup type.
10381038
///
1039-
llvm::DenseMap<Type, bool> IsDynamicMemberLookupCache;
1039+
llvm::DenseMap<CanType, bool> IsDynamicMemberLookupCache;
10401040
private:
10411041
/// \brief Describe the candidate expression for partial solving.
10421042
/// This class used by shrink & solve methods which apply

0 commit comments

Comments
 (0)