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

Remove all #if swift(...)s, all the ones I've seen in SwiftNIO are wrong. Needs to be #if compiler #2718

Open
weissi opened this issue May 9, 2024 · 1 comment

Comments

@weissi
Copy link
Member

weissi commented May 9, 2024

#if swift(...) is testing the language version and not the compiler version. We (almost) always want to check the compiler version.

(This ticket should be for all repos in the swift-nio* family)

Consider this program

#if swift(>=5.0)
print("I'm Swift language version 5+")
#endif
#if compiler(>=5.0)
print("I'm Swift compiler version 5+")
#endif
#if swift(>=6.0)
print("I'm Swift language version 6+")
#endif
#if compiler(>=6.0)
print("I'm Swift compiler version 6+")
#endif

output (on a recent Swift 6 preview snapshot)

language version 5 (default):

$ swiftc t6.swift && ./t6
I'm Swift language version 5+
I'm Swift compiler version 5+
I'm Swift compiler version 6+

language version 4:

$ swiftc -swift-version 4 t6.swift && ./t6
I'm Swift compiler version 5+
I'm Swift compiler version 6+

language version 6:

$ swiftc -swift-version 6 t6.swift && ./t6
I'm Swift language version 5+
I'm Swift compiler version 5+
I'm Swift language version 6+
I'm Swift compiler version 6+

Please note how compiler does the right thing but swift does not?

@weissi
Copy link
Member Author

weissi commented May 9, 2024

We went through the same during the Swift 4 to Swift 5 transition: https://gist.github.com/weissi/83d491d44ec4c7d7d93097b569339beb

But back then it was a little more difficult because #if compiler didn't exist in Swift 4.{0,1,2}. So we had to use the weird 4.0.150 versions to mean "Swift 4.1 compiler in Swift 4 language mode"

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

No branches or pull requests

1 participant