-
Notifications
You must be signed in to change notification settings - Fork 440
Various improvements and tweaks to bring SwiftIfConfig in line with the compiler #2774
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
DougGregor
merged 11 commits into
swiftlang:main
from
DougGregor:if-config-compiler-align
Aug 5, 2024
Merged
Various improvements and tweaks to bring SwiftIfConfig in line with the compiler #2774
DougGregor
merged 11 commits into
swiftlang:main
from
DougGregor:if-config-compiler-align
Aug 5, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ecks Implement a warning to recognize `#if` conditions like this: ```swift ((os(iOS) || os(tvOS)) && (arch(i386) || arch(x86_64))) ``` and suggest `targetEnvironment(simultator)` instead.
The error about only a `*` being meaningful in the second position is a warning in the compiler, so match that behavior.
The compiler issues a warning, so do the same here.
This matches the behavior of the compiler.
My old hack of taking the text of the whole expression and splitting it on a period was showing its age by failing to reject invalid code. Perform the proper translation, throwing errors if the import path doesn't match the proper A.B.C form.
Only && and || are allowed as infix operators within an #if condition, so note that in the diagnostic (just like the compiler does).
… top level This matches the compiler's behavior.
Within the compiler, canImport involves side effects, so we need to follow along with how the compiler works precisely to avoid changing behavior.
@swift-ci please test |
:sadblob: |
ahoppen
reviewed
Aug 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement a number of improvements and minor wording tweaks to bring SwiftIfConfig in line with the expectations of the compiler, as determined by the compiler's test suite. This includes:
#if
conditions like(os(iOS) || os(tvOS)) && (arch(i386) || arch(x86_64))
that should be replaced bytargetEnvironment(simulator)
.macabi
target environment tomacCatalyst
._compiler_version
's second version component being non-*
to a warning._endian
platform condition to a warning..
" hack.&&
,||
, or!
.canImport
when it won't affect the result, becausecanImport
in the compiler has side effects.