-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Add a version number for the stdlib itself; use it in unit tests #24254
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
This is primarily useful to check for the presence/absence of specific modifications while testing the Standard Library itself. There are two version numbers — _stdlibStaticVersion is the version number the code was compiled with, while _stdlibDynamicVersion is the version that’s currently running.
fa14e3b
to
3adb5a0
Compare
3adb5a0
to
309e564
Compare
@swift-ci please test |
These version numbers would form a progression like this:
We would need to bump the version whenever we introduce a behavioral change that we want to be able to reliably test. In this setup, versions corresponding to actual toolchain releases would be whatever the version was on the tag the toolchain was built from: say, These values would explicitly not correspond to major/minor/patch version numbers in some semantic versioning scheme. Points to ponder:
|
@swift-ci please test |
Build failed |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't see why we need to back-deploy or bake any implementation details into our ABI.
/// The two integer components are not intended to correspond to major or minor | ||
/// versions in a semantic versioning scheme. Neither do they correlate with | ||
/// toolchain or OS version numbers. | ||
@_alwaysEmitIntoClient // Introduced in 5.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want back-deployment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we shouldn't? I expect to always be able to retrieve a version number; tying it to an explicit availability check would reduce its usefulness.
} | ||
|
||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) | ||
@usableFromInline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed if not back deploying
/// The two integer components are not intended to correspond to major or minor | ||
/// versions in a semantic versioning scheme. Neither do they correlate with | ||
/// toolchain or OS version numbers. | ||
public var _stdlibStaticVersion: (Int, Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a little confused. Why is this public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It allows tests to easily determine if they are back/forward deployed. Binaries that are intimately tied to a particular revision of the stdlib and should not be separately back/forward deployed (e.g. libswiftFoundation) could use it for sanity checks.
if _stdlibDynamicVersion < _stdlibStaticVersion {
print("I'm back-deployed")
}
This is not strictly necessary, but it seems like a cheap addition. If it's available, the "current" version need not be duplicated (and updated) in more than one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, dyld provides two similar version numbers through NSVersionOfRunTimeLibrary
and NSVersionOfLinkTimeLibrary
.
(The link-time version queries the linkage of the main executable, not the current object, so it's different(ly useful) than the static version number implemented here.)
@lorentey and I discussed this. If this is just used for our own testing, we can keep it internal so long as StdlibUnittest is built with disable access control. Karoy, what do you think about making this proper API at some point? |
Closing; adding 9999 availability guards to such behavioral tests already covers the most important deployment scenarios. (#24496) A version number like this would be helpful, but its maintenance cost would exceed its usefulness in its current form. (E.g., this variant does not plug into |
@milseman I think all resilient Swift modules should have their own separate version number, and there should be a standard way to access it (both at compile-time and at runtime). The version number should be usable in compile-time |
The usual OS-based availability checks aren't always appropriate -- the stdlib we're actually using may not correspond to the version that shipped with the OS we're running on. This makes it tricky to decide whether a particular fix is supposed to be present in the current stdlib, which is a problem for unit tests that are supposed to test these changes.
Add an (arbitrary) version number for the stdlib itself, and use it to skip certain tests that are checking for behavioral changes introduced in 5.1.
rdar://problem/50150948