Skip to content

[Parser] Support "<" unary operator in #if swift() and #if compiler() expressions #17960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

danielmartin
Copy link
Contributor

@danielmartin danielmartin commented Jul 15, 2018

Swift-evolution proposal: swiftlang/swift-evolution#877
Resolves #49401.

Until now, only ">=" was supported in #if swift() expressions, for example:

#if swift(>=2.1)
#endif

This means that if we want to evaluate code only when the language version is
less than a particular version we need to do the following:

#if !swift(>=2.1)
#endif

An alternative to make this more readable (the "!" can be easily missed in a code
review) is to introduce another supported unary operator, "<". The previous
example could be rewritten like this:

#if swift(<2.1)
#endif

This commit adds support for that unary operator, along with some tests.

@CodaFi
Copy link
Contributor

CodaFi commented Jul 15, 2018

Why not just lift the restriction on comparison operators altogether?

@CodaFi CodaFi requested a review from jrose-apple July 15, 2018 23:37
@jrose-apple
Copy link
Contributor

We don't want to support > or <= because they don't account for patch versions. That is, if a problem is not fixed in a patch, you'd need to update your condition, and if it is fixed in a patch, you can use >= or < instead.

@jrose-apple jrose-apple added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Jul 16, 2018
Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual implementation looks pretty good, just a few nitpicks. Merging needs to wait for the review, of course, or for the Core Team to formally say this doesn't need one (still possible given Chris's positive feedback on the forum thread).

Until now, only ">=" was supported in #if swift() expressions, for example:

```#if swift(>=2.1)
```#endif

This means that if we want to evaluate code only when the language version is
less than a particular version we need to do the following:

```#if !swift(>=2.1)
```#endif

An alernative to make this more readable (the "!" can be easily missed in a code
review) is to introduce another supported unary operator, "<". The previous
example could be rewritten like this:

```#if swift(<2.1)
```#endif

This commit adds support for that unary operator, along with some tests.
@danielmartin danielmartin force-pushed the new-unary-operator-ifconfig branch from 5823273 to e66095b Compare August 2, 2018 18:36
@tkremenek
Copy link
Member

SE-0224 has been approved, so this is clear to land once this PR is approved.

@danielmartin danielmartin changed the title [Parser] Support "<" unary operator in #if swift() expressions [Parser] Support "<" unary operator in #if swift() and #if compiler() expressions Aug 26, 2018
@jrose-apple
Copy link
Contributor

@tkremenek, I think this is waiting on you.

@swift-ci Please test

@tkremenek
Copy link
Member

Re-running CI against latest master.

@swift-ci test

@jrose-apple jrose-apple merged commit ceaa5db into swiftlang:master Sep 26, 2018
@AnthonyLatsis AnthonyLatsis removed the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants