mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Improve DML attribute caching, as recommended by Doug. (#14697)
This commit is contained in:
@@ -2869,8 +2869,8 @@ getArgumentLabels(ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
|
|||||||
/// particularly fast in the face of deep class hierarchies or lots of protocol
|
/// particularly fast in the face of deep class hierarchies or lots of protocol
|
||||||
/// conformances, but this is fine because it doesn't get invoked in the normal
|
/// conformances, but this is fine because it doesn't get invoked in the normal
|
||||||
/// name lookup path (only when lookup is about to fail).
|
/// name lookup path (only when lookup is about to fail).
|
||||||
static bool hasDynamicMemberLookupAttribute(Type ty,
|
static bool hasDynamicMemberLookupAttribute(CanType ty,
|
||||||
llvm::DenseMap<Type, bool> &IsDynamicMemberLookupCache) {
|
llvm::DenseMap<CanType, bool> &IsDynamicMemberLookupCache) {
|
||||||
auto it = IsDynamicMemberLookupCache.find(ty);
|
auto it = IsDynamicMemberLookupCache.find(ty);
|
||||||
if (it != IsDynamicMemberLookupCache.end()) return it->second;
|
if (it != IsDynamicMemberLookupCache.end()) return it->second;
|
||||||
|
|
||||||
@@ -2879,7 +2879,8 @@ static bool hasDynamicMemberLookupAttribute(Type ty,
|
|||||||
// have the attribute on them.
|
// have the attribute on them.
|
||||||
if (auto protocolComp = ty->getAs<ProtocolCompositionType>()) {
|
if (auto protocolComp = ty->getAs<ProtocolCompositionType>()) {
|
||||||
for (auto p : protocolComp->getMembers())
|
for (auto p : protocolComp->getMembers())
|
||||||
if (hasDynamicMemberLookupAttribute(p, IsDynamicMemberLookupCache))
|
if (hasDynamicMemberLookupAttribute(p->getCanonicalType(),
|
||||||
|
IsDynamicMemberLookupCache))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2917,7 +2918,13 @@ static bool hasDynamicMemberLookupAttribute(Type ty,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return IsDynamicMemberLookupCache[ty] = calculate();
|
auto result = calculate();
|
||||||
|
|
||||||
|
// Cache this if we can.
|
||||||
|
if (!ty->hasTypeVariable())
|
||||||
|
IsDynamicMemberLookupCache[ty] = result;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3307,7 +3314,7 @@ retry_after_fail:
|
|||||||
constraintKind == ConstraintKind::ValueMember &&
|
constraintKind == ConstraintKind::ValueMember &&
|
||||||
memberName.isSimpleName() && !memberName.isSpecial()) {
|
memberName.isSimpleName() && !memberName.isSpecial()) {
|
||||||
auto name = memberName.getBaseIdentifier();
|
auto name = memberName.getBaseIdentifier();
|
||||||
if (hasDynamicMemberLookupAttribute(instanceTy,
|
if (hasDynamicMemberLookupAttribute(instanceTy->getCanonicalType(),
|
||||||
IsDynamicMemberLookupCache)) {
|
IsDynamicMemberLookupCache)) {
|
||||||
auto &ctx = getASTContext();
|
auto &ctx = getASTContext();
|
||||||
// Recursively look up the subscript(dynamicMember:)'s in this type.
|
// Recursively look up the subscript(dynamicMember:)'s in this type.
|
||||||
|
|||||||
@@ -1036,7 +1036,7 @@ public:
|
|||||||
/// This is a cache that keeps track of whether a given type is known (or not)
|
/// This is a cache that keeps track of whether a given type is known (or not)
|
||||||
/// to be a @dynamicMemberLookup type.
|
/// to be a @dynamicMemberLookup type.
|
||||||
///
|
///
|
||||||
llvm::DenseMap<Type, bool> IsDynamicMemberLookupCache;
|
llvm::DenseMap<CanType, bool> IsDynamicMemberLookupCache;
|
||||||
private:
|
private:
|
||||||
/// \brief Describe the candidate expression for partial solving.
|
/// \brief Describe the candidate expression for partial solving.
|
||||||
/// This class used by shrink & solve methods which apply
|
/// This class used by shrink & solve methods which apply
|
||||||
|
|||||||
Reference in New Issue
Block a user