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

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

> On 6 Jan 2018, at 01:19, Jordan Rose via swift-build-dev 
> <swift-build-...@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-...@swift.org
> https://lists.swift.org/mailman/listinfo/swift-build-dev
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to