Skip to content

Reflection: correct conformance table iteration #41221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2022
Merged

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Feb 5, 2022

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.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

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`.
@compnerd compnerd requested a review from mikeash February 5, 2022 01:11
@compnerd
Copy link
Member Author

compnerd commented Feb 5, 2022

CC: @tbkka

@compnerd
Copy link
Member Author

compnerd commented Feb 5, 2022

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Feb 5, 2022

Build failed
Swift Test Linux Platform
Git Sha - ff7ba2a

@compnerd
Copy link
Member Author

compnerd commented Feb 6, 2022

@swift-ci please test Linux platform

@compnerd compnerd merged commit 7c80051 into main Feb 6, 2022
@compnerd compnerd deleted the compnerd/padding branch February 6, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants