Skip to content

Availability and backward deployment for variadic generics [5.9] #65926

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented May 15, 2023

@slavapestov
Copy link
Contributor Author

swiftlang/swift-syntax#1664
@swift-ci Please test

@slavapestov slavapestov force-pushed the availability-and-backdeploy-variadics-5.9 branch from 430f84c to 91a3971 Compare May 16, 2023 16:17
@slavapestov
Copy link
Contributor Author

swiftlang/swift-syntax#1664
@swift-ci Please test


SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
const Metadata * const *
swift_allocateMetadataPack(const Metadata * const *ptr, size_t count) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the uniquing here will work correctly when the Swift runtime in use has swift_allocateMetadataPack (which uses a runtime-internal MetadataPacks cache) and the program was compiled for an earlier deployment target (so this version of swift_allocateMetadataPack will be linked in), because some callers will go through the runtime version and some will go through the compatibility version.

With back-deployed concurrency, I ended up creating swift_getFunctionTypeMetadataGlobalActorBackDeploy in the back-deployment shim. IRGen generates a call to that when building for a back-deployment target, and that function does a dlsym to determine whether swift_getFunctionTypeMetadataGlobalActor is available in the active Swift runtime... if it is, we use it so everyone agrees on the underlying cache. I think you'll need to take a similar approach here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doug and I discussed this offline. Doug is 100% correct in that a binary built against an older deployment target will link against the stub and call the entry points in the stub even on a newer runtime, so we cannot guarantee uniqueness of packs in this scenario. However, pack uniqueness is only a space optimization and not required for correctness; when comparing metadata keys in generic type instantiation we already do a deep equality of pack elements, because we have to deal with on-stack packs. It would still be nice to eek out a tiny bit of memory savings though, so I will address this issue in a follow-up PR. Thanks Doug!

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've determined that my concern not a correctness problem, but that we might lose out on some uniquing in a back-deployed confirmation and therefore allocate more memory than needed. I'm okay with landing this pull request as-is and we can improve the memory footprint for this configuration as a follow-up.

@slavapestov
Copy link
Contributor Author

@slavapestov
Copy link
Contributor Author

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 919cf8e into swiftlang:release/5.9 May 20, 2023
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.

2 participants