Skip to content

Commit 47eda91

Browse files
authored
Merge pull request #85916 from augusto2112/speedup-protocols-main
[NFC][RemoteInspection] Use existing cache to build conformance table
2 parents 20bee09 + 52c8b79 commit 47eda91

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ class TypeRefBuilder {
597597
/// an external file.
598598
remote::ExternalTypeRefCache *ExternalTypeRefCache = nullptr;
599599

600+
/// Ensure all field descriptors are in the FieldTypeInfoCache.
601+
void ensureAllFieldDescriptorsCached();
602+
600603
public:
601604
///
602605
/// Dumping typerefs, field declarations, builtin types, captures,
@@ -746,20 +749,18 @@ class TypeRefBuilder {
746749
ConformanceCollectionResult collectAllConformances() {
747750
ConformanceCollectionResult result;
748751

749-
// The Fields section has gathered info on types that includes their
750-
// mangled names. Use that to build a dictionary from a type's demangled
751-
// name to its mangled name
752+
ensureAllFieldDescriptorsCached();
753+
754+
Demangler dem;
755+
// Build the demangled to mangled name map from the FieldTypeInfoCache.
752756
std::unordered_map<std::string, std::string> typeNameToManglingMap;
753-
for (const auto &section : ReflectionInfos) {
754-
for (auto descriptor : section.Field) {
755-
TypeRefBuilder::ScopedNodeFactoryCheckpoint checkpoint(&Builder);
756-
auto TypeRef = readTypeRef(descriptor, descriptor->MangledTypeName);
757-
auto OptionalMangledTypeName = normalizeReflectionName(TypeRef);
758-
auto TypeName = nodeToString(Builder.demangleTypeRef(TypeRef));
759-
if (OptionalMangledTypeName.has_value()) {
760-
typeNameToManglingMap[TypeName] = OptionalMangledTypeName.value();
761-
}
762-
}
757+
for (const auto &entry : FieldTypeInfoCache) {
758+
const std::string &mangledName = entry.first;
759+
RemoteRef<FieldDescriptor> descriptor = entry.second;
760+
761+
auto node = dem.demangleType(mangledName);
762+
auto demangledName = nodeToString(node);
763+
typeNameToManglingMap[demangledName] = mangledName;
763764
}
764765

765766
// Collect all conformances and aggregate them per-conforming-type.

stdlib/public/RemoteInspection/TypeRefBuilder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ void TypeRefBuilder::ReflectionTypeDescriptorFinder::
335335
ProcessedReflectionInfoIndexes.insert(Index);
336336
}
337337

338+
void TypeRefBuilder::ReflectionTypeDescriptorFinder::
339+
ensureAllFieldDescriptorsCached() {
340+
for (size_t i = 0; i < ReflectionInfos.size(); ++i) {
341+
populateFieldTypeInfoCacheWithReflectionAtIndex(i);
342+
}
343+
}
344+
338345
std::optional<RemoteRef<FieldDescriptor>>
339346
TypeRefBuilder::ReflectionTypeDescriptorFinder::findFieldDescriptorAtIndex(
340347
size_t Index, const std::string &MangledName) {

0 commit comments

Comments
 (0)