Re: [swift-dev] "Swift 4.1 or Swift 3.3"

2018-01-08 Thread Chris Lattner via swift-dev
On Jan 8, 2018, at 5:26 PM, Jordan Rose via swift-dev  
wrote:
>> On Jan 8, 2018, at 17:18, Chris Lattner > > wrote:
>>> On Jan 5, 2018, at 4:19 PM, Jordan Rose via swift-dev >> > 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?”.
>> 
>> I agree, this is getting bad.  Ted mentioned that something like 
>> __has_feature in clang is probably the best way to go, so people could check 
>> the specific thing they care about, instead of a set of global version 
>> numbers.
>> 
>> Another thing that could help is something along the lines of:
>> 
>>  #if swift_stdlib(>=5.0)
>> 
>> which would presumably be active in any language mode when the 5.0 standard 
>> library is available.  It would be even better to use a generalized 
>> availability system for this: the standard library version could be treated 
>> just like Foundation versions are handled, for example.
> 
> Yep, though there's a difference between compile-time availability (which is 
> what `#if swift` and `@available(swift, …)` check) and run-time availability 
> (which is what `@available(macOS, …)` and `#available` check). Thus far, 
> availability of features in the standard library has been a compile-time 
> check, but as soon as the standard library starts shipping with Apple's OS, 
> it becomes a run-time check. The conclusion I draw is that there's a good 
> chance we'll end up with different solutions for checking compiler versions 
> vs. checking run-time versions.
> 
> (And then there's another thing people have asked for, which is statically 
> checking SDK versions. 

I think your second paragraph answers the issue you observe in the first 
paragraph.  You’re right that we have #available and @available, but neither of 
them are the thing we need here.  We need a third thing that allows people to 
conditionally build (#ifdef-style) based on build time information.

I don’t see the OS or the standard library as being special here.  The same 
thing is true for source packages - a dependent package should be able to write 
conditional code to allow it to work with different versions of some other 
package it depends on.  I outlined this sort of stuff in this ancient doc:
https://github.com/apple/swift/blob/master/docs/proposals/archive/ProgramStructureAndCompilationModel.rst#sdks
 



> Thus far they've been able to emulate that with `#if swift` because we've 
> shipped a new Swift with every new Apple SDK, but it's still potentially an 
> interesting feature.)


Sure, this is just a way of saying that people are already doing this - so we 
might as well make it nice and consistent.  Also, given that Swift is cross 
platform, it would be nice to have a solution that works in other environments 
too.

-Chris

___
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev


Re: [swift-dev] "Swift 4.1 or Swift 3.3"

2018-01-08 Thread Chris Lattner via swift-dev

> On Jan 5, 2018, at 4:19 PM, Jordan Rose via swift-dev  
> 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?”.

I agree, this is getting bad.  Ted mentioned that something like __has_feature 
in clang is probably the best way to go, so people could check the specific 
thing they care about, instead of a set of global version numbers.

Another thing that could help is something along the lines of:

#if swift_stdlib(>=5.0)

which would presumably be active in any language mode when the 5.0 standard 
library is available.  It would be even better to use a generalized 
availability system for this: the standard library version could be treated 
just like Foundation versions are handled, for example.

-Chris


> 
> #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-dev mailing list
> swift-dev@swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev

___
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev


[swift-dev] "Swift 4.1 or Swift 3.3"

2018-01-05 Thread Jordan Rose via swift-dev
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-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev