[Review] SE-0020 Swift Language Version Build Configuration

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  swift-evolution/0020-if-swift-version.md at master · apple/swift-evolution · GitHub

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  swift-evolution/process.md at master · apple/swift-evolution · GitHub

Thank you,
Doug Gregor
Review Manager

On the key statement of the proposal:

Like other build configurations, if swift isn't line-based - it encloses whole statements or declarations. However, unlike the others, the compiler won't parse inactive branches guarded by if swift or emit lex diagnostics, so syntactic differences for other Swift versions can be in the same file.

I wonder if some structural check should be done nonetheless, like proper balancing of curly braces, and of comment marker (/**/). Neither of these can be overridden (afaik), and their pairing is unlikely to ever change.

The current if syntax does prevent you from doing what I consider a bad habit that I have seen way too often in C.

if os(Linux)
  if (boolCheck()) {
#else
  if (optionalBoolCheck() ?? false) {
#endif
    /* Some code */
  }

Main reason why I hate these unbalanced curly brace, is that it messes up with simple tool like the % to jump to matching brace in vi.

Some may suggest that this fall in the coding style/lint bucket, but I have a feeling that such structural check coud help the parser.

Dany

···

Le 12 janv. 2016 à 13:28, Douglas Gregor via swift-evolution <swift-evolution@swift.org> a écrit :

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,
Doug Gregor
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

On the key statement of the proposal:

Like other build configurations, if swift isn't line-based - it encloses whole statements or declarations. However, unlike the others, the compiler won't parse inactive branches guarded by if swift or emit lex diagnostics, so syntactic differences for other Swift versions can be in the same file.

I wonder if some structural check should be done nonetheless, like proper balancing of curly braces, and of comment marker (/**/). Neither of these can be overridden (afaik), and their pairing is unlikely to ever change.

The current if syntax does prevent you from doing what I consider a bad habit that I have seen way too often in C.

if os(Linux)
  if (boolCheck()) {
#else
  if (optionalBoolCheck() ?? false) {
#endif
    /* Some code */
  }

Main reason why I hate these unbalanced curly brace, is that it messes up with simple tool like the % to jump to matching brace in vi.

Some may suggest that this fall in the coding style/lint bucket, but I have a feeling that such structural check coud help the parser.

Dany

···

Le 12 janv. 2016 à 13:28, Douglas Gregor via swift-evolution <swift-evolution@swift.org> a écrit :

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,
Doug Gregor
Review Manager

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I think the proposal addresses a need that we have with Swift, but I think the proposal introduces yet-another-special case solution.

There is already a construct that nearly serves this purpose. I’d rather see those constructs bolstered and unified.

Previous feedback:

The @available() and if #available constructs are not sufficient as they fall under the same limitations that your proposal addresses: they require that the non-valid branch not be parsed. For example, an API that has changes with a new language feature, such as variadic generic arguments, would not be able to be defined.

If we look at the grammar, I don’t see why the grammar for “availability-argument” couldn’t look like this:

    availability-argument: (platform-name | language-name | package-name) version.
GRAMMAR OF AN AVAILABILITY CONDITION

<>availability-condition → #available­(­availability-arguments <The Swift Programming Language: Redirect
<>availability-arguments → availability-argument <The Swift Programming Language: Redirect availability-argument <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>availability-argument → platform-name <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>availability-argument → *­
<>platform-name → iOS­ iOSApplicationExtension­
<>platform-name → OSX­ OSXApplicationExtension­
<>platform-name → watchOS­
<>platform-version → decimal-digits <The Swift Programming Language: Redirect
<>platform-version → decimal-digits <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>platform-version → decimal-digits <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
I’d further argue that the version argument properly adhere to the semver spec: http://semver.org <http://semver.org/&gt;\.

The above change, in addition to the change for the if #available (change to: if available) statement to not parse the unavailable path would seem to provide the solution you want to have in addition to the solution that many package developers could use as well.

The nice thing is that this could be done in stages:

1. Add support for the language condition and change if available to not parse the non-valid paths
2. Add support for package names
3. Add support for proper semver versioning.

The only breaking change is #1 as the else-clause would no longer parse the code today. When/if semver was supported, the version could still take the decimal digits while adding semver support.

-David

···

On Jan 12, 2016, at 10:28 AM, Douglas Gregor <dgregor@apple.com> wrote:

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,
Doug Gregor
Review Manager

_______________________________________________
swift-evolution-announce mailing list
swift-evolution-announce@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution-announce

I disagree that these constructs are similar. #available and @available are inherently runtime queries, whereas checking the version of Swift is a compile-time query. An app ships with code for both branches of "if #available".

Jordan

···

On Jan 15, 2016, at 10:49, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

I think the proposal addresses a need that we have with Swift, but I think the proposal introduces yet-another-special case solution.

There is already a construct that nearly serves this purpose. I’d rather see those constructs bolstered and unified.

Previous feedback:

The @available() and if #available constructs are not sufficient as they fall under the same limitations that your proposal addresses: they require that the non-valid branch not be parsed. For example, an API that has changes with a new language feature, such as variadic generic arguments, would not be able to be defined.

If we look at the grammar, I don’t see why the grammar for “availability-argument” couldn’t look like this:

    availability-argument: (platform-name | language-name | package-name) version.
GRAMMAR OF AN AVAILABILITY CONDITION

<>availability-condition → #available­(­availability-arguments <The Swift Programming Language: Redirect
<>availability-arguments → availability-argument <The Swift Programming Language: Redirect availability-argument <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>availability-argument → platform-name <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>availability-argument → *­
<>platform-name → iOS­ iOSApplicationExtension­
<>platform-name → OSX­ OSXApplicationExtension­
<>platform-name → watchOS­
<>platform-version → decimal-digits <The Swift Programming Language: Redirect
<>platform-version → decimal-digits <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
<>platform-version → decimal-digits <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect <The Swift Programming Language: Redirect
I’d further argue that the version argument properly adhere to the semver spec: http://semver.org <http://semver.org/&gt;\.

The above change, in addition to the change for the if #available (change to: if available) statement to not parse the unavailable path would seem to provide the solution you want to have in addition to the solution that many package developers could use as well.

The nice thing is that this could be done in stages:

1. Add support for the language condition and change if available to not parse the non-valid paths
2. Add support for package names
3. Add support for proper semver versioning.

The only breaking change is #1 as the else-clause would no longer parse the code today. When/if semver was supported, the version could still take the decimal digits while adding semver support.

-David

On Jan 12, 2016, at 10:28 AM, Douglas Gregor <dgregor@apple.com <mailto:dgregor@apple.com>> wrote:

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,
Doug Gregor
Review Manager

_______________________________________________
swift-evolution-announce mailing list
swift-evolution-announce@swift.org <mailto:swift-evolution-announce@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution-announce

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

They are similar in that they are trying to restrict codeflow based on external conditions.

Today we have if os(), if arch(), plus the ability to set build configuration identifiers. And now there is a new proposal to add if swift().

Keep the #available() and @available() runtime versions. What I'm saying is add if available() as a compile-time version and generalize the current uses of the if usages (these could happen migration steps and don't need to necessarily happen all at once).

When packages start working, it's very easy to see use cases where we want to do the same thing based on package name and version. Build configurations identifiers aren't sufficient for it (version comparison, for instance). So instead needing to propose another construct, if package(), is there a way to generalize the pattern we are already seeing that could still fit in the scope of this proposal? I think so.

···

Sent from my iPhone

On Jan 15, 2016, at 3:35 PM, Jordan Rose <jordan_rose@apple.com> wrote:

I disagree that these constructs are similar. #available and @available are inherently runtime queries, whereas checking the version of Swift is a compile-time query. An app ships with code for both branches of "if #available".

Jordan

On Jan 15, 2016, at 10:49, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

I think the proposal addresses a need that we have with Swift, but I think the proposal introduces yet-another-special case solution.

There is already a construct that nearly serves this purpose. I’d rather see those constructs bolstered and unified.

Previous feedback:

The @available() and if #available constructs are not sufficient as they fall under the same limitations that your proposal addresses: they require that the non-valid branch not be parsed. For example, an API that has changes with a new language feature, such as variadic generic arguments, would not be able to be defined.

If we look at the grammar, I don’t see why the grammar for “availability-argument” couldn’t look like this:

    availability-argument: (platform-name | language-name | package-name) version.
GRAMMAR OF AN AVAILABILITY CONDITION

availability-condition → #available­(­availability-arguments­)­
availability-arguments → availability-argument­ availability-argument­,­availability-arguments­
availability-argument → platform-name­platform-version­
availability-argument → *­
platform-name → iOS­ iOSApplicationExtension­
platform-name → OSX­ OSXApplicationExtension­
platform-name → watchOS­
platform-version → decimal-digits­
platform-version → decimal-digits­.­decimal-digits­
platform-version → decimal-digits­.­decimal-digits­.­decimal-digits­
I’d further argue that the version argument properly adhere to the semver spec: http://semver.org.

The above change, in addition to the change for the if #available (change to: if available) statement to not parse the unavailable path would seem to provide the solution you want to have in addition to the solution that many package developers could use as well.

The nice thing is that this could be done in stages:

1. Add support for the language condition and change if available to not parse the non-valid paths
2. Add support for package names
3. Add support for proper semver versioning.

The only breaking change is #1 as the else-clause would no longer parse the code today. When/if semver was supported, the version could still take the decimal digits while adding semver support.

-David

On Jan 12, 2016, at 10:28 AM, Douglas Gregor <dgregor@apple.com> wrote:

Hello Swift community,

The review of SE-0020 "Swift Language Version Build Configuration” begins now and runs through January 17th. The proposal is available here:

  https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md

Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at

  https://lists.swift.org/mailman/listinfo/swift-evolution

or, if you would like to keep your feedback private, directly to the review manager.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  * What is your evaluation of the proposal?
  * Is the problem being addressed significant enough to warrant a change to Swift?
  * Does this proposal fit well with the feel and direction of Swift?
  * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

  https://github.com/apple/swift-evolution/blob/master/process.md

Thank you,
Doug Gregor
Review Manager

_______________________________________________
swift-evolution-announce mailing list
swift-evolution-announce@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution-announce

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution