Skip to content

Commit b6f1f06

Browse files
authored
Merge pull request #26437 from nkcsgexi/HasDynamicMemberLookupAttributeRequest
IDE+Evaluator: refactor the sema implementation of hasDynamicMemberLookupAttribute to a request and move the function wrapper to libIDE. NFC
2 parents b0a3961 + 9065ae9 commit b6f1f06

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

include/swift/Sema/IDETypeCheckingRequestIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ SWIFT_TYPEID(IsDeclApplicableRequest)
1818
SWIFT_TYPEID(TypeRelationCheckRequest)
1919
SWIFT_TYPEID(RootAndResultTypeOfKeypathDynamicMemberRequest)
2020
SWIFT_TYPEID(RootTypeOfKeypathDynamicMemberRequest)
21+
SWIFT_TYPEID(HasDynamicMemberLookupAttributeRequest)

include/swift/Sema/IDETypeCheckingRequests.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,29 @@ class RootTypeOfKeypathDynamicMemberRequest:
234234
SourceLoc getNearestLoc() const { return SourceLoc(); };
235235
};
236236

237+
//----------------------------------------------------------------------------//
238+
// HasDynamicMemberLookupAttributeRequest
239+
//----------------------------------------------------------------------------//
240+
class HasDynamicMemberLookupAttributeRequest:
241+
public SimpleRequest<HasDynamicMemberLookupAttributeRequest,
242+
bool(TypeBase*),
243+
CacheKind::Cached> {
244+
public:
245+
using SimpleRequest::SimpleRequest;
246+
247+
private:
248+
friend SimpleRequest;
249+
250+
// Evaluation.
251+
llvm::Expected<bool> evaluate(Evaluator &evaluator, TypeBase *ty) const;
252+
253+
public:
254+
// Caching
255+
bool isCached() const { return true; }
256+
// Source location
257+
SourceLoc getNearestLoc() const { return SourceLoc(); };
258+
};
259+
237260
/// The zone number for the IDE.
238261
#define SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE 97
239262
#define SWIFT_TYPEID_ZONE SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE

lib/IDE/IDETypeChecking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,8 @@ Type swift::getResultTypeOfKeypathDynamicMember(SubscriptDecl *SD) {
782782
RootAndResultTypeOfKeypathDynamicMemberRequest{SD}, TypePair()).
783783
SecondTy;
784784
}
785+
786+
bool swift::hasDynamicMemberLookupAttribute(Type ty) {
787+
return evaluateOrDefault(ty->getASTContext().evaluator,
788+
HasDynamicMemberLookupAttributeRequest{ty.getPointer()}, false);
789+
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,7 +3918,7 @@ ConstraintSystem::simplifyFunctionComponentConstraint(
39183918
/// particularly fast in the face of deep class hierarchies or lots of protocol
39193919
/// conformances, but this is fine because it doesn't get invoked in the normal
39203920
/// name lookup path (only when lookup is about to fail).
3921-
static bool hasDynamicMemberLookupAttribute(Type type,
3921+
bool swift::hasDynamicMemberLookupAttribute(Type type,
39223922
llvm::DenseMap<CanType, bool> &DynamicMemberLookupCache) {
39233923
auto canType = type->getCanonicalType();
39243924
auto it = DynamicMemberLookupCache.find(canType);
@@ -3992,12 +3992,6 @@ static bool hasDynamicMemberLookupAttribute(Type type,
39923992
return result;
39933993
}
39943994

3995-
// for IDETypeChecking
3996-
bool swift::hasDynamicMemberLookupAttribute(Type type) {
3997-
llvm::DenseMap<CanType, bool> DynamicMemberLookupCache;
3998-
return ::hasDynamicMemberLookupAttribute(type, DynamicMemberLookupCache);
3999-
}
4000-
40013995
static bool isForKeyPathSubscript(ConstraintSystem &cs,
40023996
ConstraintLocator *locator) {
40033997
if (!locator || !locator->getAnchor())

lib/Sema/IDETypeCheckingRequests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,10 @@ RootAndResultTypeOfKeypathDynamicMemberRequest::evaluate(Evaluator &evaluator,
135135
"invalid keypath dynamic member");
136136
return TypePair(genericArgs[0], genericArgs[1]);
137137
}
138+
139+
llvm::Expected<bool>
140+
HasDynamicMemberLookupAttributeRequest::evaluate(Evaluator &evaluator,
141+
TypeBase *ty) const {
142+
llvm::DenseMap<CanType, bool> DynamicMemberLookupCache;
143+
return hasDynamicMemberLookupAttribute(Type(ty), DynamicMemberLookupCache);
144+
}

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,8 @@ static void lookupVisibleDynamicMemberLookupDecls(
959959
if (!seenDynamicLookup.insert(baseType.getPointer()).second)
960960
return;
961961

962-
if (!hasDynamicMemberLookupAttribute(baseType))
962+
if (!evaluateOrDefault(dc->getASTContext().evaluator,
963+
HasDynamicMemberLookupAttributeRequest{baseType.getPointer()}, false))
963964
return;
964965

965966
auto &ctx = dc->getASTContext();

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,9 @@ bool areGenericRequirementsSatisfied(const DeclContext *DC,
21762176

21772177
bool canSatisfy(Type type1, Type type2, bool openArchetypes,
21782178
constraints::ConstraintKind kind, DeclContext *dc);
2179+
2180+
bool hasDynamicMemberLookupAttribute(Type type,
2181+
llvm::DenseMap<CanType, bool> &DynamicMemberLookupCache);
21792182
} // end namespace swift
21802183

21812184
#endif

0 commit comments

Comments
 (0)