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

Chris Lattner clattner at apple.com
Sun Oct 23 23:25:04 CDT 2016


> On Oct 22, 2016, at 2:44 PM, Richard Wei via swift-evolution <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
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161023/851770c4/attachment.html>


More information about the swift-evolution mailing list