Skip to content

Commit e06012b

Browse files
committed
Cache LookupAllConformancesInContextRequest.
Now that this request will be triggered more often, due to inference of function builders, cache the result.
1 parent 877cd7a commit e06012b

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)
5656
SWIFT_TYPEID_NAMED(PostfixOperatorDecl *, PostfixOperatorDecl)
5757
SWIFT_TYPEID_NAMED(PrecedenceGroupDecl *, PrecedenceGroupDecl)
5858
SWIFT_TYPEID_NAMED(PrefixOperatorDecl *, PrefixOperatorDecl)
59+
SWIFT_TYPEID_NAMED(ProtocolConformance *, ProtocolConformance)
5960
SWIFT_TYPEID_NAMED(ProtocolDecl *, ProtocolDecl)
6061
SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
6162
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct PropertyWrapperTypeInfo;
5151
enum class CtorInitializerKind;
5252
struct PropertyWrapperLValueness;
5353
struct PropertyWrapperMutability;
54+
class ProtocolConformance;
5455
class ProtocolDecl;
5556
class Requirement;
5657
enum class ResilienceExpansion : unsigned;

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ class ClosureHasExplicitResultRequest
22342234
bool isCached() const { return true; }
22352235
};
22362236

2237-
using ProtocolConformanceLookupResult = SmallVector<ProtocolConformance *, 2>;
2237+
using ProtocolConformanceLookupResult = std::vector<ProtocolConformance *>;
22382238
void simple_display(llvm::raw_ostream &out, ConformanceLookupKind kind);
22392239

22402240
/// Lookup and expand all conformances in the given context.
@@ -2255,7 +2255,7 @@ void simple_display(llvm::raw_ostream &out, ConformanceLookupKind kind);
22552255
class LookupAllConformancesInContextRequest
22562256
: public SimpleRequest<LookupAllConformancesInContextRequest,
22572257
ProtocolConformanceLookupResult(const DeclContext *),
2258-
RequestFlags::Uncached |
2258+
RequestFlags::Cached |
22592259
RequestFlags::DependencySink |
22602260
RequestFlags::DependencySource> {
22612261
public:
@@ -2269,6 +2269,8 @@ class LookupAllConformancesInContextRequest
22692269
evaluate(Evaluator &evaluator, const DeclContext *DC) const;
22702270

22712271
public:
2272+
bool isCached() const { return true; }
2273+
22722274
// Incremental dependencies
22732275
evaluator::DependencySource readDependencySource(Evaluator &eval) const;
22742276
void writeDependencySink(Evaluator &eval, ReferencedNameTracker &tracker,

include/swift/Basic/SimpleDisplay.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ namespace swift {
136136
out << "}";
137137
}
138138

139+
template<typename T>
140+
void simple_display(llvm::raw_ostream &out,
141+
const std::vector<T> &vec) {
142+
out << "{";
143+
bool first = true;
144+
for (const T &value : vec) {
145+
if (first) first = false;
146+
else out << ", ";
147+
148+
simple_display(out, value);
149+
}
150+
out << "}";
151+
}
152+
139153
template<typename T, typename U>
140154
void simple_display(llvm::raw_ostream &out,
141155
const llvm::PointerUnion<T, U> &ptrUnion) {

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,10 +5100,11 @@ diagnoseMissingAppendInterpolationMethod(NominalTypeDecl *typeDecl) {
51005100
}
51015101
}
51025102

5103-
SmallVector<ProtocolConformance *, 2>
5103+
std::vector<ProtocolConformance *>
51045104
LookupAllConformancesInContextRequest::evaluate(
5105-
Evaluator &eval, const DeclContext *DC) const {
5106-
return DC->getLocalConformances(ConformanceLookupKind::All);
5105+
Evaluator &eval, const IterableDeclContext *IDC) const {
5106+
auto result = IDC->getLocalConformances(ConformanceLookupKind::All);
5107+
return std::vector<ProtocolConformance *>(result.begin(), result.end());
51075108
}
51085109

51095110
void TypeChecker::checkConformancesInContext(DeclContext *dc,

lib/Sema/TypeCheckRequestFunctions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ static Type inferFunctionBuilderType(ValueDecl *decl) {
207207
// this declaration. If this declaration is a witness to any
208208
// requirement within one of those protocols that has a function builder
209209
// attached, use that function builder type.
210-
auto idc = cast<IterableDeclContext>(dc->getAsDecl());
211210
auto conformances = evaluateOrDefault(
212211
dc->getASTContext().evaluator,
213-
LookupAllConformancesInContextRequest{idc}, { });
212+
LookupAllConformancesInContextRequest{dc}, { });
214213

215214
// Find all of the potentially inferred function builder types.
216215
struct Match {

0 commit comments

Comments
 (0)