-
Notifications
You must be signed in to change notification settings - Fork 148
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
Yams: add an alias to explicitly dispatch pow
#281
Conversation
We must disambiguate `Double.pow(_: Double, _: Double) -> Double` and `__C.pow(_: Double, _: Double) -> Double` as the Swift for TensorFlow branch adds the former into the standard library. The explicit module dispatch ensures that we make the overload resolution unambiguous allowing building Yams.
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS) | ||
import Darwin | ||
fileprivate let cpow: (_: Double, _: Double) -> Double = Darwin.pow | ||
#elseif os(Windows) | ||
import ucrt | ||
fileprivate let cpow: (_: Double, _: Double) -> Double = ucrt.pow | ||
#else | ||
import Glibc | ||
fileprivate let cpow: (_: Double, _: Double) -> Double = Glibc.pow | ||
#endif |
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.
Can this be simplified to this?
#if canImport(Darwin)
private let cpow: (_: Double, _: Double) -> Double = Darwin.pow
#elseif canImport(ucrt)
private let cpow: (_: Double, _: Double) -> Double = ucrt.pow
#elseif canImport(Glibc)
private let cpow: (_: Double, _: Double) -> Double = Glibc.pow
#else
#error("Unsupported platform")
#endif
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 don't think that is really a simplification - it's different semantics. If I were to have a C module or a Swift module with the name Darwin
on Windows, this would cause a build failure. I can certainly change it to that if you feel strongly though.
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 don't feel strongly, and see the risk of name collisions, although I would advise against naming new modules Darwin for a slew of reasons. I consider it a simplification in the sense that if new platforms were introduced (e.g. os(HomePod)
) we wouldn't have to touch this code.
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.
Sure, but I still think that introduction of an os(Darwin)
or vendor(Apple)
is better. However, that's not the current reality. I'll update this in a few minutes.
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.
No need to update, I'll merge as-is.
I'd love to add Swift for TensorFlow and Windows CI jobs so we can catch these kinds of issues more proactively. @compnerd are you aware of any good examples of open source Swift projects using those platforms on CI that I could take a look at as a jumping off point? |
Sure, the question is what are you looking for in terms of Windows CI? Azure Pipelines or GitHub Actions? I'll try to get a recent Windows TensorFlow toolchain uploaded. |
Lovely, we use Azure Pipelines for this project, so this looks like a good start: https://github.com/compnerd/swift-win32/blob/master/azure-pipelines.yml |
We must disambiguate
Double.pow(_: Double, _: Double) -> Double
and__C.pow(_: Double, _: Double) -> Double
as the Swift for TensorFlowbranch adds the former into the standard library. The explicit module
dispatch ensures that we make the overload resolution unambiguous
allowing building Yams.