[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
This commit is contained in:
Augusto Noronha
2025-12-08 16:30:36 -08:00
parent df3aa1e011
commit 52c8b7975a
2 changed files with 21 additions and 13 deletions

View File

@@ -597,6 +597,9 @@ public:
/// an external file. /// an external file.
remote::ExternalTypeRefCache *ExternalTypeRefCache = nullptr; remote::ExternalTypeRefCache *ExternalTypeRefCache = nullptr;
/// Ensure all field descriptors are in the FieldTypeInfoCache.
void ensureAllFieldDescriptorsCached();
public: public:
/// ///
/// Dumping typerefs, field declarations, builtin types, captures, /// Dumping typerefs, field declarations, builtin types, captures,
@@ -746,20 +749,18 @@ public:
ConformanceCollectionResult collectAllConformances() { ConformanceCollectionResult collectAllConformances() {
ConformanceCollectionResult result; ConformanceCollectionResult result;
// The Fields section has gathered info on types that includes their ensureAllFieldDescriptorsCached();
// mangled names. Use that to build a dictionary from a type's demangled
// name to its mangled name Demangler dem;
// Build the demangled to mangled name map from the FieldTypeInfoCache.
std::unordered_map<std::string, std::string> typeNameToManglingMap; std::unordered_map<std::string, std::string> typeNameToManglingMap;
for (const auto &section : ReflectionInfos) { for (const auto &entry : FieldTypeInfoCache) {
for (auto descriptor : section.Field) { const std::string &mangledName = entry.first;
TypeRefBuilder::ScopedNodeFactoryCheckpoint checkpoint(&Builder); RemoteRef<FieldDescriptor> descriptor = entry.second;
auto TypeRef = readTypeRef(descriptor, descriptor->MangledTypeName);
auto OptionalMangledTypeName = normalizeReflectionName(TypeRef); auto node = dem.demangleType(mangledName);
auto TypeName = nodeToString(Builder.demangleTypeRef(TypeRef)); auto demangledName = nodeToString(node);
if (OptionalMangledTypeName.has_value()) { typeNameToManglingMap[demangledName] = mangledName;
typeNameToManglingMap[TypeName] = OptionalMangledTypeName.value();
}
}
} }
// Collect all conformances and aggregate them per-conforming-type. // Collect all conformances and aggregate them per-conforming-type.

View File

@@ -335,6 +335,13 @@ void TypeRefBuilder::ReflectionTypeDescriptorFinder::
ProcessedReflectionInfoIndexes.insert(Index); ProcessedReflectionInfoIndexes.insert(Index);
} }
void TypeRefBuilder::ReflectionTypeDescriptorFinder::
ensureAllFieldDescriptorsCached() {
for (size_t i = 0; i < ReflectionInfos.size(); ++i) {
populateFieldTypeInfoCacheWithReflectionAtIndex(i);
}
}
std::optional<RemoteRef<FieldDescriptor>> std::optional<RemoteRef<FieldDescriptor>>
TypeRefBuilder::ReflectionTypeDescriptorFinder::findFieldDescriptorAtIndex( TypeRefBuilder::ReflectionTypeDescriptorFinder::findFieldDescriptorAtIndex(
size_t Index, const std::string &MangledName) { size_t Index, const std::string &MangledName) {