Skip to content

[6.0] Parse #if canImport as a function call instead of a specialized expression node #2550

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 1 commit into from
Mar 20, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 19, 2024

  • Explanation: The parser had special knowledge about how to parse canImport inside #if conditions. This was inconsistent with eg. the parsing of #if swift(<6.0), which gets parsed as a function call. To make it easier to interpret the version passed to canImport(MyModule, _version: <#version#>), add ExprSyntax.interpretedAsVersionTuple that takes eg. 1.2.3, which got parsed as a member access 3 to the 1.2 float literal and re-parses it as a VersionTupleSyntax. This relaxation also allows string literals as version parameters to #if canImport.
  • Scope: Parsing of canImport directives in #if conditions.
  • Risk: Low, we’ve to quite a few tests for this, function calls are more permissive than CanImportExprSyntax and it is unlikely that anyone is relying on the interpretation of the version number
  • Testing: Updated the existing test cases
  • Issue: rdar://121070235, Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax #1972
  • Reviewer: @bnbarham and @rintaro on Remove CanImportExprSyntax and provide API to interpret an ExprSyntax as a VersionTupleSyntax #2025

…ression node

To make it easier to interpret the version passed to `canImport(MyModule, _version: <#version#>)`, add `ExprSyntax.interpretedAsVersionTuple` that takes eg. `1.2.3`, which got parsed as a member access `3` to the `1.2` float literal and re-parses it as a `VersionTupleSyntax`.

This relaxation also allows string literals as version parameters to `#if canImport`.

Fixes swiftlang#1972
rdar://121070235

Co-Authored-By: Ziyang Huang <stevenhuang12@outlook.com>
@ahoppen ahoppen requested a review from bnbarham as a code owner March 19, 2024 15:17
@ahoppen
Copy link
Member Author

ahoppen commented Mar 19, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 20, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 3cfa2b3 into swiftlang:release/6.0 Mar 20, 2024
@ahoppen ahoppen deleted the ahoppen/6.0/canimport branch March 20, 2024 13:40
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.

2 participants