Skip to content

Commit c5a9575

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 bf7eea0 commit c5a9575

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

include/swift/AST/ASTTypeIDZone.def

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

include/swift/AST/ASTTypeIDs.h

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

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ class ClosureHasExplicitResultRequest
22392239
bool isCached() const { return true; }
22402240
};
22412241

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

22452245
/// Lookup and expand all conformances in the given context.
@@ -2261,7 +2261,7 @@ class LookupAllConformancesInContextRequest
22612261
: public SimpleRequest<LookupAllConformancesInContextRequest,
22622262
ProtocolConformanceLookupResult(
22632263
const IterableDeclContext *),
2264-
RequestFlags::Uncached |
2264+
RequestFlags::Cached |
22652265
RequestFlags::DependencySink |
22662266
RequestFlags::DependencySource> {
22672267
public:
@@ -2275,6 +2275,8 @@ class LookupAllConformancesInContextRequest
22752275
evaluate(Evaluator &evaluator, const IterableDeclContext *IDC) const;
22762276

22772277
public:
2278+
bool isCached() const { return true; }
2279+
22782280
// Incremental dependencies
22792281
evaluator::DependencySource
22802282
readDependencySource(const evaluator::DependencyRecorder &eval) const;

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,10 +5038,11 @@ diagnoseMissingAppendInterpolationMethod(NominalTypeDecl *typeDecl) {
50385038
}
50395039
}
50405040

5041-
SmallVector<ProtocolConformance *, 2>
5041+
std::vector<ProtocolConformance *>
50425042
LookupAllConformancesInContextRequest::evaluate(
50435043
Evaluator &eval, const IterableDeclContext *IDC) const {
5044-
return IDC->getLocalConformances(ConformanceLookupKind::All);
5044+
auto result = IDC->getLocalConformances(ConformanceLookupKind::All);
5045+
return std::vector<ProtocolConformance *>(result.begin(), result.end());
50455046
}
50465047

50475048
void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {

0 commit comments

Comments
 (0)