Skip to content

[Runtime] Support type descriptor map in LibPrespecialized. #75376

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
Aug 2, 2024

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Jul 19, 2024

The descriptor map is keyed by a simplified mangling that canonicalizes the differences that we accept in _contextDescriptorMatchesMangling, such as the ability to specify any kind of type with an OtherNominalType node.

This simplified mangling is not necessarily unique, but we use _contextDescriptorMatchesMangling for the final equality checking when looking up entries in the map, so occasional collisions are acceptable and get resolved when probing the table.

The table is meant to be comprehensive, so it includes all descriptors that can be looked up by name, and a negative result means the descriptor does not exist in the shared cache. We add a flag to the options that can mark it as non-definitive in case we ever need to degrade this, and fall back to a full search after a negative result.

The map encompasses the entire shared cache but we need to reject lookups for types in images that aren't loaded. The map includes an image index which allows us to cheaply query whether a given descriptor is in a loaded image or not, so we can ignore ones which are not.

TypeMetadataPrivateState now has a separate sections array for sections within the shared cache. _searchTypeMetadataRecords consults the map first. If no result is found in the map and the map is marked as comprehensive, then only the sections outside the shared cache need to be scanned.

Replace the SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED environment variable with one specifically for metadata and one for descriptor lookup so they can be controlled independently. Also add SWIFT_DEBUG_VALIDATE_LIB_PRESPECIALIZED_DESCRIPTOR_LOOKUP which consults the map and does the full scan, and ensures they produce the same result, for debugging purposes.

Remove the disablePrespecializedMetadata global and instead modify the mapConfiguration to disable prespecialized metadata when an image is loaded that overrides one in the shared cache.

rdar://113059233

@mikeash mikeash force-pushed the libprespecialize-descriptor-map branch from b5d5421 to bd2cf3a Compare July 23, 2024 18:39
@mikeash mikeash force-pushed the libprespecialize-descriptor-map branch 2 times, most recently from c427840 to a0e641c Compare July 25, 2024 17:41
@mikeash
Copy link
Contributor Author

mikeash commented Jul 25, 2024

Pushed a fix for a spot where we were accessing data->getOptionFlags() where data could be NULL.

The descriptor map is keyed by a simplified mangling that canonicalizes the differences that we accept in _contextDescriptorMatchesMangling, such as the ability to specify any kind of type with an OtherNominalType node.

This simplified mangling is not necessarily unique, but we use _contextDescriptorMatchesMangling for the final equality checking when looking up entries in the map, so occasional collisions are acceptable and get resolved when probing the table.

The table is meant to be comprehensive, so it includes all descriptors that can be looked up by name, and a negative result means the descriptor does not exist in the shared cache. We add a flag to the options that can mark it as non-definitive in case we ever need to degrade this, and fall back to a full search after a negative result.

The map encompasses the entire shared cache but we need to reject lookups for types in images that aren't loaded. The map includes an image index which allows us to cheaply query whether a given descriptor is in a loaded image or not, so we can ignore ones which are not.

TypeMetadataPrivateState now has a separate sections array for sections within the shared cache. _searchTypeMetadataRecords consults the map first. If no result is found in the map and the map is marked as comprehensive, then only the sections outside the shared cache need to be scanned.

Replace the SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED environment variable with one specifically for metadata and one for descriptor lookup so they can be controlled independently. Also add SWIFT_DEBUG_VALIDATE_LIB_PRESPECIALIZED_DESCRIPTOR_LOOKUP which consults the map and does the full scan, and ensures they produce the same result, for debugging purposes.

Enhance the environment variable code to track whether a variable was set at all. This allows SWIFT_DEBUG_ENABLE_LIB_PRESPECIALIZED to override the default in either direction.

Remove the disablePrespecializedMetadata global and instead modify the mapConfiguration to disable prespecialized metadata when an image is loaded that overrides one in the shared cache.

rdar://113059233
@mikeash mikeash force-pushed the libprespecialize-descriptor-map branch from a0e641c to 4b3a197 Compare August 1, 2024 22:43
@mikeash
Copy link
Contributor Author

mikeash commented Aug 1, 2024

Updated with a smallish change to consult the map when searching for protocol descriptors.

@mikeash
Copy link
Contributor Author

mikeash commented Aug 1, 2024

@swift-ci please test

@mikeash
Copy link
Contributor Author

mikeash commented Aug 2, 2024

Linux failed due to issue addressed by swiftlang/swift-foundation#802.

@mikeash
Copy link
Contributor Author

mikeash commented Aug 2, 2024

@swift-ci please smoke test linux platform

@mikeash mikeash merged commit 5e15d8a into swiftlang:main Aug 2, 2024
4 of 5 checks passed
@ADKaster
Copy link
Contributor

ADKaster commented Aug 19, 2024

@mikeash this PR causes a build failure for me on linux on main due to a missing #include <utility> in PrebuiltStringMap.h for the use of std::pair.

Presumably due to recent libc++ granularized header work?

@mikeash
Copy link
Contributor Author

mikeash commented Aug 19, 2024

@ADKaster Presumably, in any case we should be including the headers for what we use. PR to #include <utility> here: #75953

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