Skip to content

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
merged 11 commits into from
Aug 5, 2024

Conversation

DougGregor
Copy link
Member

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:

  • Add warning for #if conditions like (os(iOS) || os(tvOS)) && (arch(i386) || arch(x86_64)) that should be replaced by targetEnvironment(simulator).
  • Add warning and remapping for the rename of the macabi target environment to macCatalyst.
  • Downgrade the error about _compiler_version's second version component being non-* to a warning.
  • Downgrade error about bad _endian platform condition to a warning.
  • Properly process expressions as import paths, replacing my horrible "grab the string and split on ." hack.
  • Ensure that we diagnose compound names where they aren't permitted.
  • Improve diagnostics for uses of operators other than &&, ||, or !.
  • Avoid evaluating canImport when it won't affect the result, because canImport in the compiler has side effects.

…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.
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.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 8740e15 into swiftlang:main Aug 5, 2024
3 checks passed
@DougGregor DougGregor deleted the if-config-compiler-align branch August 5, 2024 15:02
@CodaFi
Copy link
Contributor

CodaFi commented Aug 6, 2024

canImport in the compiler has side effects.

:sadblob:

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.

3 participants