@@ -738,24 +738,40 @@ _findContextDescriptor(Demangle::NodePointer node,
738
738
cachedContexts = _findContextDescriptorInCache (T, node);
739
739
}
740
740
741
+ bool foundInCache = false ;
741
742
for (auto cachedContext : cachedContexts) {
742
743
if (_contextDescriptorMatchesMangling (cachedContext, node)) {
743
744
foundContext = cachedContext;
745
+ foundInCache = true ;
744
746
break ;
745
747
}
746
748
}
747
749
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
750
755
foundContext = _searchTypeMetadataRecords (T, node);
751
756
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
+ }
756
762
757
763
if (foundContext) {
758
764
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
759
775
}
760
776
761
777
return foundContext;
0 commit comments