Skip to content
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

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

compnerd
Copy link
Contributor

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.

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.
Comment on lines +17 to +26
#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
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

@jpsim jpsim merged commit 682d498 into jpsim:master Oct 26, 2020
@jpsim
Copy link
Owner

jpsim commented Oct 26, 2020

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?

@compnerd
Copy link
Contributor Author

Sure, the question is what are you looking for in terms of Windows CI? Azure Pipelines or GitHub Actions?
Azure Pipelines - compnerd/swift-win32
GitHub Actions - compnerd/swift-com

I'll try to get a recent Windows TensorFlow toolchain uploaded.

@jpsim
Copy link
Owner

jpsim commented Oct 26, 2020

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

@bradleymackey bradleymackey mentioned this pull request Dec 2, 2024
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