Skip to content

Commit ff7ba2a

Browse files
authored
Reflection: correct conformance table iteration
Adjust the iteration of the conformance table to match the current data structure layout. `MapData` is a view into the `ConformanceState`: ~~~ [+0x00] Cache [Type: swift::ConcurrentReadableHashMap<ConformaanceCacheEntry, swift::StaticMutex>] [+0x28] SectionsToScan [Type: swift::ConcurrentReadableArray<ConformanceSection>] [+0x50] scanSectionsBackwards [Type: bool] ~~~ `Cache` itself is a structure: ~~~ [+0x00] ReaderCount [Type: std::atomic<uint32_t>] [+0x04] ElementCount [Type: std::atomic<uint32_t>] [+0x08] Elements [Type: std::atomic<swift::ConcurrentReadableHashMap<ConformanceCacheEntry, swift::staticMutex>::ElementStorage *>] ~~~ The `ElementStorage` backing `Elements` actually looks like: ~~~ [+0x00] Capacity [Type: uint32_t] [+0x08] Elem [Typwe: ConformanceCacheEntry] ~~~ The `Capacity` field will be pointer aligned (a previous change has changed this to be explicitly pointer sized bit-sliced). However, we would previously fail to accomodate the `Capacity` field, and read the contents shifted by the size of `Capacity`. This repairs the iteration off the `ConformanceCache`.
1 parent dde3291 commit ff7ba2a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,15 +1157,15 @@ class ReflectionContext
11571157
reinterpret_cast<const ConcurrentHashMap<Runtime> *>(MapBytes.get());
11581158

11591159
auto Count = MapData->ElementCount;
1160-
auto Size = Count * sizeof(ConformanceCacheEntry<Runtime>);
1160+
auto Size = Count * sizeof(ConformanceCacheEntry<Runtime>) + sizeof(StoredPointer);
11611161

11621162
auto ElementsBytes =
11631163
getReader().readBytes(RemoteAddress(MapData->Elements), Size);
11641164
if (!ElementsBytes)
11651165
return;
11661166
auto ElementsData =
11671167
reinterpret_cast<const ConformanceCacheEntry<Runtime> *>(
1168-
ElementsBytes.get());
1168+
reinterpret_cast<const char *>(ElementsBytes.get()) + sizeof(StoredPointer));
11691169

11701170
for (StoredSize i = 0; i < Count; i++) {
11711171
auto &Element = ElementsData[i];

0 commit comments

Comments
 (0)