[swift-evolution] [Proposal] Swift 2.2: #if swift language version

David Farler dfarler at apple.com
Fri Dec 18 14:32:15 CST 2015


> On Dec 18, 2015, at 12:29 PM, Chris Lattner <clattner at apple.com> wrote:
> 
> 
>> On Dec 18, 2015, at 12:25 PM, Radosław Pietruszewski via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Sounds like it could be super useful for libraries!
>> 
>> How about we drop the quote marks, though? If we have `os(iOS)` and `#available(iOS 9, *)` (in other context), why not `swift(2.2)`?
> 
> I agree with Radek.
> 
> The argument to use a string is if we wanted to support subversions, e.g. like “#if swift(2.2.1)”.  This requires the parameter to be a string, because 2.2.1 isn’t a valid floating point literal - the lexer will be displeased.
> 
> However, I don’t think we *want* the feature to be able to do that.  The most important use case for this feature is to handle syntactic differences across swift versions, and we don’t want those in sub-versions.  Given that, it seems better to keep the syntax clean and simple.
> 
> David know this already, but I’m a huge fan of this feature. :-)
> 
> -Chris

Yep, you took the words out of my mouth re: the version components. If two components are enough though, then we should totally drop the quotes.

David

>> — Radek
>> 
>>> On 18 Dec 2015, at 21:22, David Farler via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Hello everyone,
>>> 
>>> For Swift 2.2, I'd like to add the following build configuration to check for the Swift language version. This is meant to be a short proposal, so let's start with a simple example, compiling with the 2.2 compiler:
>>> 
>>> #if swift("2.2")
>>> print("Hello")
>>> #else
>>> this code will not parse or emit diagnostics
>>> #endif
>>> 
>>> The semantics of the build configuration is, "is the Swift language version at least X?". If it is, the active block is parsed and compiled into your program. Like the other build configuration blocks, this isn't line-based, but break on whole statements and declarations. Unlike the other build configurations, however, the inactive block will not parse or emit syntax errors, so you can include syntax for older Swift language revisions in the same file if you prefer.
>>> 
>>> It sounds like a lot of folks have been wanting something like this, which is why I'm suggesting it for the Swift 2.2 release. I'm curious to hear your feedback!
>>> 
>>> Best,
>>> David
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list