Skip to content

Commit e7cedae

Browse files
committed
[Runtime] Fail in +Asserts builds if the context descriptor cache is wrong.
1 parent 4bc794f commit e7cedae

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,24 +738,40 @@ _findContextDescriptor(Demangle::NodePointer node,
738738
cachedContexts = _findContextDescriptorInCache(T, node);
739739
}
740740

741+
bool foundInCache = false;
741742
for (auto cachedContext : cachedContexts) {
742743
if (_contextDescriptorMatchesMangling(cachedContext, node)) {
743744
foundContext = cachedContext;
745+
foundInCache = true;
744746
break;
745747
}
746748
}
747749

748-
// Check type metadata records
749-
if (!foundContext)
750+
if (!foundContext) {
751+
// Slow path, as a fallback if the cache itself isn't capturing everything.
752+
(void)foundInCache;
753+
754+
// Check type metadata records
750755
foundContext = _searchTypeMetadataRecords(T, node);
751756

752-
// Check protocol conformances table. Note that this has no support for
753-
// resolving generic types yet.
754-
if (!foundContext)
755-
foundContext = _searchConformancesByMangledTypeName(node);
757+
// Check protocol conformances table. Note that this has no support for
758+
// resolving generic types yet.
759+
if (!foundContext)
760+
foundContext = _searchConformancesByMangledTypeName(node);
761+
}
756762

757763
if (foundContext) {
758764
T.NominalCache.getOrInsert(mangledName, foundContext);
765+
766+
#ifndef NDEBUG
767+
// If we found something in the slow path but not in the cache, it is a
768+
// bug in the cache. Fail in assertions builds.
769+
if (!foundInCache) {
770+
fatalError(0,
771+
"_findContextDescriptor cache miss for demangled tree:\n%s\n",
772+
getNodeTreeAsString(node).c_str());
773+
}
774+
#endif
759775
}
760776

761777
return foundContext;

0 commit comments

Comments
 (0)