[swift-build-dev] "Swift 4.1 or Swift 3.3"
Jordan Rose
jordan_rose at apple.com
Mon Jan 8 15:43:17 CST 2018
> On Jan 5, 2018, at 23:43, David Hart <david at hartbit.com> wrote:
>
> I was really surprised when I saw that the release of 4.0 introduced this 3.2 version to mean “the 4.0 compiler running in 3.1 compatibility mode”. So of course, I’m even more surprised to see a new 3.3 version. I find it very counter-intuitive. It also means we will continue to have to increment all previous Swift language versions from now on whenever a new compiler is released:
>
> Swift 3.4 = Swift 5 compiler in Swift 3 compatibility mode
> Swift 4.2 = Swift 5 compiler in Swift 4 compatibility mode
> Swift 3.5 = Swift 5.1 compiler in Swift 3 compatibility mode
> Swift 4.3 = Swift 5.1 compiler in Swift 4 compatibility mode
The most common use of `#if swift` is `#if swift(>=4.0)`, to check for things that actually changed in Swift 4 and not in the 3 compatibility modes. I agree that the "subtraction" going on here is very weird, though, and of course it leads to this problem when you're actually trying to test the compiler release rather than the language mode.
(Your predictions are right, though, if nothing else here changes: https://github.com/apple/swift/pull/13767)
> I have the impression that what we really need is a different directive to test for the compiler version:
>
> #if compiler(>=4.1)
> // Swift 3.3
> // Swift 4.1
> #endif
That certainly seems reasonable. If that's the direction we want to go, the next question is whether it's important enough to put through swift-evolution in time for Swift 4.1, or whether it could wait for Swift 5. (I'd also love if someone else shepherded that proposal and implementation through. I could put it up as a StarterBug/StarterProposal.)
Jordan
>
> On 6 Jan 2018, at 01:19, Jordan Rose via swift-build-dev <swift-build-dev at swift.org <mailto:swift-build-dev at swift.org>> wrote:
>
>> Hi, all. Swift 4.1 is off on its own branch and going well, but we never quite came up with an answer for a particular problem developers might have: "am I running a Swift 4.1 compiler?".
>>
>> #if swift(>=3.2)
>> // Swift 3.2 (4.0 in compatibility mode)
>> // Swift 3.3 (4.1 in compatibility mode)
>> // Swift 4.0
>> // Swift 4.1
>> #endif
>>
>> #if swift(>=3.3)
>> // Swift 3.3 (4.1 compatibily mode)
>> // Swift 4.0
>> // Swift 4.1
>> // this one is probably not very useful
>> #endif
>>
>> #if swift(>=4.0)
>> // Swift 4.0
>> // Swift 4.1
>> #endif
>>
>> #if ???
>> // Swift 3.3
>> // Swift 4.1
>> #endif
>>
>> I don't think this is going to come up a lot, but given that we do have changes to the standard library and to the language, I can see people wanting it. Right now the only way to do it is the rather unwieldy:
>>
>> #if swift(>=4.1) || (swift(>=3.3) && !swift(>=4.0))
>> print("new")
>> #else
>> print("old")
>> #endif
>>
>> Do we need something better here, or do you think people will be okay with this? I'm realizing I don't really know how many people try to keep their libraries working across Swift versions and run into compatibility issues.
>>
>> (Strictly speaking this problem is already present with Swift 4.0.2 with 3.2.2 compatibility mode, but that's much less likely to come up.)
>>
>> Jordan
>> _______________________________________________
>> swift-build-dev mailing list
>> swift-build-dev at swift.org <mailto:swift-build-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-build-dev <https://lists.swift.org/mailman/listinfo/swift-build-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-build-dev/attachments/20180108/5864bd14/attachment.html>
More information about the swift-build-dev
mailing list