From cfc24691dc03a299b3f49cc571d3dfb39f278486 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Fri, 15 Sep 2023 13:14:58 -0700 Subject: [PATCH] Don't trust the external cache when looking for field descriptors When looking for field descriptors for a typeref, we should iterate over every image info available, even those that the cache claimed to have processed, as a last ditch effort. rdar://114567246 (cherry picked from commit a6be181ae5fe1d388624338ff1a591b615052a66) --- stdlib/public/RemoteInspection/TypeRefBuilder.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/public/RemoteInspection/TypeRefBuilder.cpp b/stdlib/public/RemoteInspection/TypeRefBuilder.cpp index 77486c36bd9fe..685b57c1281e6 100644 --- a/stdlib/public/RemoteInspection/TypeRefBuilder.cpp +++ b/stdlib/public/RemoteInspection/TypeRefBuilder.cpp @@ -331,8 +331,8 @@ RemoteRef TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) { } } - // On failure, fill out the cache, ReflectionInfo by ReflectionInfo, - // until we find the field descriptor we're looking for. + // If the heuristic didn't work, iterate over every reflection info + // that the external cache hasn't processed. for (size_t i = 0; i < ReflectionInfos.size(); ++i) { if (ExternalTypeRefCache && ExternalTypeRefCache->isReflectionInfoCached(i)) continue; @@ -340,6 +340,14 @@ RemoteRef TypeRefBuilder::getFieldTypeInfo(const TypeRef *TR) { return *FD; } + // If we still haven't found the field descriptor go over every reflection + // info, even the ones the external cache supposedly processed. + // TODO: if we find the field descriptor here there is a bug somewhere (most + // likely on the external cache). Log this somehow. + for (size_t i = 0; i < ReflectionInfos.size(); ++i) + if (auto FD = findFieldDescriptorAtIndex(i, *MangledName)) + return *FD; + return nullptr; }