[swift-evolution] [Pitch] #if swift version with third version component

Alex Martini amartini at apple.com
Mon Oct 24 11:52:32 CDT 2016


When you file the bug, can you post the Jira number?  The grammar in TSPL will also need to be changed to accept three version components.

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/swift-version

Thanks!
— Alex


> On Oct 23, 2016, at 9:25 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Oct 22, 2016, at 2:44 PM, Richard Wei via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hi,
>> 
>> Foundation in 3.0-RELEASE didn't fully resolve the renaming in SE-0086, so we have `RegularExpression` on Linux and `NSRegularExpression` on macOS. The naming is now unified in Swift 3.0.1, but there doesn’t seem to be a possible way to resolve the code breaking change. Consider the example below:
> 
> +1.  Assuming there are no major objections, I don’t think this needs a full evolution cycle.  This seems like a bug fix to me.
> 
> -Chris
> 
> 
>> 
>> Currently the following code is only compatible with 3.0-RELEASE, because RegularExpression on Linux becomes NSRegularExpression in 3.0.1, while we cannot use `#if` to differentiate between 3.0 and 3.0.1.
>> 
>>   #if !os(macOS)
>>   let regex = try RegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])
>>   #else
>>   let regex = try NSRegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])
>>   #endif
>> 
>> Proposed solution:
>> 
>> If `#if swift(>=)` can take the third version component, we can make the code compatible with 3.0.1 by the following:
>> 
>>   #if os(macOS) || swift(>=3.0.1)
>>   let regex = try NSRegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])  
>>   #else
>>   let regex = try RegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])
>>   #endif
>> 
>> Additionally, we can consider supporting the == operator, so that checking only the version with inconsistent naming is sufficient:
>> 
>>   #if !os(macOS) && swift(==3.0.0)
>>   let regex = try RegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])
>>   #else
>>   let regex = try NSRegularExpression(pattern: pattern, options: [ .dotMatchesLineSeparators ])
>>   #endif
>> 
>> Impact on existing code:
>> 
>> `#if swift(>=X.X.X)` and `#if swift(==X.X.X)` are purely additive.
>> 
>> -Richard
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> 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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161024/07e68884/attachment.html>


More information about the swift-evolution mailing list