[swift-evolution] [Proposal] Swift 2.2: #if swift language version
Radosław Pietruszewski
radexpl at gmail.com
Fri Dec 18 15:09:58 CST 2015
> I agree — my reasoning was that it’s more like the current iOS availability statement.
Is it? You can do `#available(iOS 9.2, *)` there.
— Radek
> On 18 Dec 2015, at 21:58, Harlan Haskins via swift-evolution <swift-evolution at swift.org> wrote:
>
> I agree — my reasoning was that it’s more like the current iOS availability statement.
>
> I wonder if the iOS availability statement could use some work too? It’s kinda weird and magical ("why do I have to type that *?")
>
>> On Dec 18, 2015, at 3:56 PM, David Farler <dfarler at apple.com <mailto:dfarler at apple.com>> wrote:
>>
>> I had considered this format but I don't think it reads as well as you'd expect for a version. It kind of makes it seem like each component is an independent argument, each with possibly a different meaning. It makes sense from a parsing point of view but I think we should allow folks to write it the same way they'd write it in normal prose, since it's not much more effort.
>>
>> David
>>
>> On Dec 18, 2015, at 12:48, Harlan Haskins <harlan at harlanhaskins.com <mailto:harlan at harlanhaskins.com>> wrote:
>>
>>> How about
>>>
>>> #if swift(2, 2, *)
>>> #endif
>>>
>>> ?
>>>
>>>> On Dec 18, 2015, at 3:32 PM, David Farler via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>>
>>>>>
>>>>> On Dec 18, 2015, at 12:29 PM, Chris Lattner <clattner at apple.com <mailto:clattner at apple.com>> wrote:
>>>>>
>>>>>
>>>>>> On Dec 18, 2015, at 12:25 PM, Radosław Pietruszewski via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto: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 <mailto:swift-evolution at swift.org>
>>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>>>>
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>>>
>>>>
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151218/2850d6a5/attachment.html>
More information about the swift-evolution
mailing list