From dd85f5c732d32723d1b3521f576b1c9980e319f1 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Mon, 8 Dec 2025 16:30:36 -0800 Subject: [PATCH] [NFC][RemoteInspection] Use existing cache to build conformance table There is an existing cache which is built when looking up FieldDescriptors. collectAllConformances ignored this cache and would parse every FieldDescriptor again. Use the existing cache mechanism. rdar://166098516 (cherry picked from commit 52c8b7975ae4e88365770cfb7cb03c7e89e40d31) --- .../swift/RemoteInspection/TypeRefBuilder.h | 27 ++++++++++--------- .../RemoteInspection/TypeRefBuilder.cpp | 7 +++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/swift/RemoteInspection/TypeRefBuilder.h b/include/swift/RemoteInspection/TypeRefBuilder.h index 2b07d09469042..16c42bad0f9e4 100644 --- a/include/swift/RemoteInspection/TypeRefBuilder.h +++ b/include/swift/RemoteInspection/TypeRefBuilder.h @@ -597,6 +597,9 @@ class TypeRefBuilder { /// an external file. remote::ExternalTypeRefCache *ExternalTypeRefCache = nullptr; + /// Ensure all field descriptors are in the FieldTypeInfoCache. + void ensureAllFieldDescriptorsCached(); + public: /// /// Dumping typerefs, field declarations, builtin types, captures, @@ -746,20 +749,18 @@ class TypeRefBuilder { ConformanceCollectionResult collectAllConformances() { ConformanceCollectionResult result; - // The Fields section has gathered info on types that includes their - // mangled names. Use that to build a dictionary from a type's demangled - // name to its mangled name + ensureAllFieldDescriptorsCached(); + + Demangler dem; + // Build the demangled to mangled name map from the FieldTypeInfoCache. std::unordered_map typeNameToManglingMap; - for (const auto §ion : ReflectionInfos) { - for (auto descriptor : section.Field) { - TypeRefBuilder::ScopedNodeFactoryCheckpoint checkpoint(&Builder); - auto TypeRef = readTypeRef(descriptor, descriptor->MangledTypeName); - auto OptionalMangledTypeName = normalizeReflectionName(TypeRef); - auto TypeName = nodeToString(Builder.demangleTypeRef(TypeRef)); - if (OptionalMangledTypeName.has_value()) { - typeNameToManglingMap[TypeName] = OptionalMangledTypeName.value(); - } - } + for (const auto &entry : FieldTypeInfoCache) { + const std::string &mangledName = entry.first; + RemoteRef descriptor = entry.second; + + auto node = dem.demangleType(mangledName); + auto demangledName = nodeToString(node); + typeNameToManglingMap[demangledName] = mangledName; } // Collect all conformances and aggregate them per-conforming-type. diff --git a/stdlib/public/RemoteInspection/TypeRefBuilder.cpp b/stdlib/public/RemoteInspection/TypeRefBuilder.cpp index fb214d05f5025..c4ece01eb82ed 100644 --- a/stdlib/public/RemoteInspection/TypeRefBuilder.cpp +++ b/stdlib/public/RemoteInspection/TypeRefBuilder.cpp @@ -335,6 +335,13 @@ void TypeRefBuilder::ReflectionTypeDescriptorFinder:: ProcessedReflectionInfoIndexes.insert(Index); } +void TypeRefBuilder::ReflectionTypeDescriptorFinder:: + ensureAllFieldDescriptorsCached() { + for (size_t i = 0; i < ReflectionInfos.size(); ++i) { + populateFieldTypeInfoCacheWithReflectionAtIndex(i); + } +} + std::optional> TypeRefBuilder::ReflectionTypeDescriptorFinder::findFieldDescriptorAtIndex( size_t Index, const std::string &MangledName) {