Skip to content

[stdlib] Introduce availability macros #39962

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 7 commits into from
Oct 31, 2021

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Oct 28, 2021

Define the following availability macros throughout all Swift libraries and tests in this repository:

SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2
SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0
SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4
SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0
SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5
SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0
SwiftStdlib 5.6:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999
SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999

These correspond to previous Swift Stdlib releases, in addition to the "5.6" release that we're currently working on, and the a placeholder "9999" release that we can use in place of an unknown future Swift release.

As part of this, we need to replace the pre-existing SwiftStdlib 5.5 macro defined in the _Concurrency module with the correct SwiftStdlib 5.1, so that its expansion matches our release history. (The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib. Before this PR, this was reflected in the expansion of SwiftStdlib 5.5, but not its name.)

The new module _Distributed also defines SwiftStdlib 5.5, but its declarations need to have availability corresponding to the future Swift 5.6 release -- so this PR replaces it with SwiftStdlib 5.6.

To keep this PR (relatively) small, it does not include changes necessary to adopt these macros in existing stdlib code. (Beyond cleaning up the _Concurrency vs _Distributed situation.)

The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust the definition of the SwiftStdlib availability macro accordingly.
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
@lorentey
Copy link
Member Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4795690

@lorentey
Copy link
Member Author

Fascinating:

15:10:18 
/Users/buildnode/jenkins/workspace/swift-PR-macos/branch-main/swift/stdlib/public/Distributed/DistributedActor.swift:38:25: error: 'Identifiable' is only available in iOS 13 or newer
15:10:18     AnyActor, Sendable, Identifiable, Hashable, Codable {
15:10:18                         ^

The code is:

@available(SwiftStdlib 5.1, *)
public protocol DistributedActor:
    AnyActor, Sendable, Identifiable, Hashable, Codable {
    ...
}

AFAICT the Distributed module does not define any availability macros, so both SwiftStdlib 5.5 and SwiftStdlib 5.1 currently ought to resolve to @available(*). But then why would only this PR trigger this error? 🤔

@ktoso How does SwiftStdlib 5.5 work in this module?

@ktoso
Copy link
Contributor

ktoso commented Oct 28, 2021

Discussed offline: the thing is defined in Distributed/CMakeLists.txt: -Xfrontend "SwiftStdlib 5.5:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0", so we can keep those or change those in the future -- as the "5.5" is a bit of a lie anyway, this does not ship in 5.5.

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

LGTM, Distributed should likely be really defined for 9999 so maybe you can do this? Thanks !

The _Distributed module is being introduced in Swift 5.6, so its definitions need to come with matching availability. (We don't have version numbers for the associated OS releases, so we need to use placeholder 9999 availability for these.)
@lorentey
Copy link
Member Author

Yep, I accidentally removed the SwiftStdlib 5.5 definition from CMakeLists.txt rather than updating it. 🤦‍♂️

The latest commit (temporarily) restores it and updates everything in _Distributed to come with SwiftStdlib 5.6 availability -- which currently resolves to 9999, sadly.

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

(The restoration is temporary as all these SwiftStdlib definitions (and more) will get moved to the top-level CMakeLists.txt soon.)

@lorentey
Copy link
Member Author

Ugh, there will be a couple of test failures at least, as the tests only see SwiftStdlib 5.1 at the moment.)

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 5e78c3b

@lorentey
Copy link
Member Author

Yep, as expected:

C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Distributed\distributed_actor_resolve.swift:7:24: error: unexpected error produced: reference to undefined version '5.6' for availability macro 'SwiftStdlib'

@available(SwiftStdlib 5.6, *)

                       ^

@lorentey lorentey changed the title [Concurrency] SwiftStdlib 5.5SwiftStdlib 5.1 [stdlib] Introduce availability macros Oct 29, 2021
Introduce "SwiftStdlib x.y"-style availability macros for all known releases of the stdlib, adding them to the swift flags of all Swift libraries and tests.
@lorentey lorentey force-pushed the concurrency-availability branch from 30d5735 to 2732765 Compare October 29, 2021 01:32
@lorentey lorentey requested a review from kylemacomber October 29, 2021 01:32
@lorentey

This comment has been minimized.

@lorentey lorentey force-pushed the concurrency-availability branch from 899660d to 4a48a17 Compare October 29, 2021 02:09
@lorentey lorentey force-pushed the concurrency-availability branch from 4a48a17 to b6f0b6d Compare October 29, 2021 02:10
@lorentey

This comment has been minimized.

@swift-ci

This comment has been minimized.

Copy link
Contributor

@xymus xymus left a comment

Choose a reason for hiding this comment

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

This looks good! Thanks for refactoring the macros definition, it's much cleaner.

@lorentey

This comment has been minimized.

@lorentey
Copy link
Member Author

The Windows build timed out.

@lorentey

This comment has been minimized.

@lorentey
Copy link
Member Author

lit.py: /Users/buildnode/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/llvm-project/llvm/utils/lit/lit/TestingConfig.py:102: fatal: unable to parse config file '/Users/buildnode/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/swift/test/lit.cfg', traceback: Traceback (most recent call last):
  File "/Users/buildnode/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/llvm-project/llvm/utils/lit/lit/TestingConfig.py", line 91, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/Users/buildnode/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/swift/test/lit.cfg", line 435, in <module>
    for macro in lit_config.params.get('availability_macros').split(";"):
AttributeError: 'NoneType' object has no attribute 'split'

/Users/buildnode/jenkins/workspace/swift-PR-macos-smoke-test/branch-main/swift-driver/Tests/SwiftDriverTests/IntegrationTests.swift:241: error: -[SwiftDriverTests.IntegrationTests testLitSymbolGraphFrontendTest] : XCTAssertEqual failed: ("terminated(code: 2)") is not equal to ("terminated(code: 0)")
Test Case '-[SwiftDriverTests.IntegrationTests testLitSymbolGraphFrontendTest]' failed (2.502 seconds).

D'oh

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey merged commit 8e154a4 into swiftlang:main Oct 31, 2021
@lorentey lorentey deleted the concurrency-availability branch October 31, 2021 21:24
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.

4 participants