-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Float16/Intel: Add an explicit Sendable conformance to work around a swiftinterface issue #36669
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 extension (introduced in swiftlang#35264) was placed in a file location where it wasn’t correctly guarded against mentioning Float16 on macOS/x86_64, so the generated .swiftinterface file included a reference to an unavailable declaration. (The dummy stand-in Float16 type that we currently use on Intel macOS.) Moving the declaration out of the “AnyHashable” section and into a file region that’s more suitable for it (i.e., enclosed in `#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))`) resolves the issue. rdar://76025365
@swift-ci test |
Build failed |
Windows failures are due to currently flaky concurrency support on MSVC; I'm disabling these tests in #36671. |
@swift-ci smoke test windows platform |
Please open a bug to track this if you haven't already. =) |
Build failed |
|
The Linux failure is hopefully addressed by swiftlang/swift-integration-tests#85. |
@swift-ci smoke test linux platform |
So it turns out this is all wrong. The generated Given the following (de-gybbed) input: // .../swift-macosx-x86_64/stdlib/public/core/8/FloatingPointTypes.swift
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
...
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
@frozen
public struct Float16 {...}
...
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
extension Float16: BinaryFloatingPoint {...}
...
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
extension Float16 : Sendable { }
#else
/// A half-precision (16b), floating-point value type.
@frozen
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
public struct Float16 {...}
#endif The generated interface includes the struct declaration from the // .../swift-macosx-x86_64/lib/swift/macosx/Swift.swiftmodule/x86_64-apple-macos.swiftinterface
...
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@frozen public struct Float16 {
@_transparent public init() {
fatalError("Float16 is not available")
}
}
...
#if compiler(>=5.3) && $MarkerProtocol
@available(iOS 14, tvOS 14, watchOS 7, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
extension Float16 : Swift.Sendable {}
#endif I'm guessing those magically emitted conditionals might be interfering with the regular |
Given the above, this won't fix the original issue, but it may be still worth merging this as a purely decorative change. |
Ha, it turns out the puzzle piece I was missing was that the compiler is able (and willing!) to implicitly derive The real issue is that the generated conformance declaration omits the subtle, but crucial % if bits == 16:
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
extension ${Self}: Sendable { }
% end With this explicit extension, the compiler simply copies the availability declaration to the generated interface, and all is well:
Tricky! |
…iftinterface issue
@swift-ci test |
Build failed |
Build failed |
@swift-ci please smoke test |
These will be addressed by swiftlang/llvm-project#2770:
|
@swift-ci smoke test macOS platform |
@swift-ci smoke test macOS |
@swift-ci test macOS platform |
Build failed |
This extension (introduced in #35264) was placed in a file location where it wasn’t correctly guarded against mentioning Float16 on macOS/x86_64, so the generated .swiftinterface file included a reference to an unavailable declaration. (The dummy stand-in Float16 type that we currently use on Intel macOS.)Moving the declaration out of the “AnyHashable” section and into a file region that’s more suitable for it (i.e., enclosed in#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
) resolves the issue.Note: The reason why the original extension produces an unusable .swiftinterface file without triggering a build error is currently a mystery to me.This is a workaround for a compiler bug that omits the full availability information of an unavailable struct from the implicit Sendable conformance declaration emitted into the generated
.swiftinterface
file. See the discussion below for details.rdar://76025365