Skip to content

[IRGen] Emit a pointer from nominal type descriptor to concrete metadata. #79302

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 28, 2025

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Feb 11, 2025

This allows external tools to locate the metadata pointer without needing to call the accessor function.

This is only useful for non-generic types, so we borrow the HasCanonicalMetadataPrespecializations flag to indicate the presence of this pointer on non-generic types, and it continues to indicate the presence of prespecializations for generic types.

Only emit this pointer for internal/private types with no runtime initialization. Public type metadata can be found with the symbol, and it's not useful for types that require runtime initialization.

rdar://144640722

@Azoy
Copy link
Contributor

Azoy commented Feb 11, 2025

Could another way of implementing this just be to stuff this as an entry to the canonical specialized metadata entries?

@mikeash
Copy link
Contributor Author

mikeash commented Feb 11, 2025

That's pretty much what this is doing, but we're taking advantage of the fact that we know there can only be one when the type is not generic, so we don't have to emit the count, and save four bytes.

@Azoy
Copy link
Contributor

Azoy commented Feb 11, 2025

Ha, we are indeed saving 4 bytes (I'm just playing devil's advocate, I don't mind how you implement this).

@rjmccall
Copy link
Contributor

Under what situations exactly do we want to emit this link? When the metadata is preallocated but not necessarily statically initialized?

@mikeash
Copy link
Contributor Author

mikeash commented Feb 12, 2025

We want it to be when the metadata is emitted by the compiler and can be used as-is, with no runtime initialization. Basically, if someone writes Array<NonPublicType>, can we build that specialization ahead of time? If we can, this allows us to find NonPublicType.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 25, 2025

Any further comments, or is this OK to get in?

@rjmccall
Copy link
Contributor

It seems fine to me.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 26, 2025

@swift-ci please test

@mikeash mikeash force-pushed the singleton-metadata-pointer branch from 121a292 to ae406bd Compare February 27, 2025 02:06
@mikeash
Copy link
Contributor Author

mikeash commented Feb 27, 2025

Linux tests failed because wasm didn't like the new test. I switched from %swift to %target-swift-frontend to match other IRGen tests, that should take care of it.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 27, 2025

@swift-ci please test

@mikeash mikeash force-pushed the singleton-metadata-pointer branch from ae406bd to b35f167 Compare February 27, 2025 17:28
@mikeash
Copy link
Contributor Author

mikeash commented Feb 27, 2025

And a test tweak for 32-bit.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 27, 2025

@swift-ci please test

@mikeash mikeash enabled auto-merge February 27, 2025 17:29
…ata.

This allows external tools to locate the metadata pointer without needing to call the accessor function.

This is only useful for non-generic types, so we borrow the HasCanonicalMetadataPrespecializations flag to indicate the presence of this pointer on non-generic types, and it continues to indicate the presence of prespecializations for generic types.

Only emit this pointer for internal/private types with no runtime initialization. Public type metadata can be found with the symbol, and it's not useful for types that require runtime initialization.
@mikeash mikeash force-pushed the singleton-metadata-pointer branch from b35f167 to 270ddf6 Compare February 27, 2025 22:48
@mikeash
Copy link
Contributor Author

mikeash commented Feb 27, 2025

@swift-ci please test

@mikeash
Copy link
Contributor Author

mikeash commented Feb 28, 2025

Windows timed out for what appears to be unrelated reasons.

@mikeash
Copy link
Contributor Author

mikeash commented Feb 28, 2025

@swift-ci please test Windows platform

@mikeash mikeash merged commit beba678 into swiftlang:main Feb 28, 2025
5 checks passed
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