Skip to content
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

Bump the deployment target to macOS 13 🚀 #957

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

TTOzzi
Copy link
Member

@TTOzzi TTOzzi commented Mar 7, 2025

This PR addresses the follow-up work discussed in #950 (comment).

  • Bump the deployment target to macOS 13
  • Relax regex restrictions to allow rules containing _ or other special characters
  • Drop NSRegularExpression and migrate to Swift Regex

.macOS("12.0"),
.iOS("13.0"),
.macOS("13.0"),
.iOS("16.0"),
Copy link
Member Author

Choose a reason for hiding this comment

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

I also raised the iOS deployment target to 16 to use Swift Regex.
One thing I'm curious about—does swift-format need to support iOS?

Copy link
Member

Choose a reason for hiding this comment

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

Someone added it a while back. I guess theoretically you could write an editor for iPad and want to format Swift code in it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see! That could be a possible use case.

@TTOzzi
Copy link
Member Author

TTOzzi commented Mar 7, 2025

It seems that RegexBuilder is not supported in Swift 5.9 on Windows.. 😨

스크린샷 2025-03-08 오전 2 44 48

@TTOzzi TTOzzi marked this pull request as draft March 7, 2025 17:29
.macOS("12.0"),
.iOS("13.0"),
.macOS("13.0"),
.iOS("16.0"),
Copy link
Member

Choose a reason for hiding this comment

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

Someone added it a while back. I guess theoretically you could write an editor for iPad and want to format Swift code in it.

/// Regex pattern to match an ignore directive comment.
/// - Capture group #1 captures the rule names if `":"` is present.
fileprivate func makeRegex() -> Regex<(Substring, Substring?)> {
let pattern = #"^\s*\/\/\s*"# + description + #"(?:\s*:\s*(.+))?$"#
Copy link
Member

Choose a reason for hiding this comment

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

If we can't use RegexBuilder here because of platform limitations, it would still be nice to use real regex literals.

I don't remember from the previous PR, but if the description property is only used here, you could lift the regexes up into that instead, something like:

var regex: Regex {
  switch self {
  case .node: return /...swift-format-ignore.../
  case .file: return /...swift-format-ignore-file.../
}

Copy link
Member

Choose a reason for hiding this comment

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

It would also be great to use named capture groups so that the result tuples elsewhere get labels, to make it more readable.

Copy link
Member Author

@TTOzzi TTOzzi Mar 7, 2025

Choose a reason for hiding this comment

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

description is used in OrderedImports to distinguish directives.
Also, after modifying it to use regex literals and running the CI, I found that, as @ahoppen mentioned below, regex literals are not supported on Windows Swift 5.9 (5.10). Given this, it seems best to keep the current implementation as is 🥲

스크린샷 2025-03-08 오전 4 12 07

Copy link
Member Author

Choose a reason for hiding this comment

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

It would also be great to use named capture groups so that the result tuples elsewhere get labels, to make it more readable.

I have utilized the named capture group in the regex to add the label ruleNames.

Copy link
Member

Choose a reason for hiding this comment

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

Every time we try to do some good, Windows is there lurking in the background. 🙁

Thanks for checking!

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Nice

/// - Capture group #1 captures the rule names if `":"` is present.
fileprivate func makeRegex() -> Regex<(Substring, Substring?)> {
let pattern = #"^\s*\/\/\s*"# + description + #"(?:\s*:\s*(.+))?$"#
return try! Regex(pattern)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment that we can’t use regex literals here because Windows didn’t have support for regex literals until Swift 5.10 (at least I think it was 5.10)? Just so we don’t go back and wonder why we aren’t using regex literals here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I've added it.

@TTOzzi TTOzzi force-pushed the bump-macos-version-13 branch from a51d245 to 9757b67 Compare March 7, 2025 19:07
@TTOzzi TTOzzi marked this pull request as ready for review March 7, 2025 19:10
@TTOzzi TTOzzi force-pushed the bump-macos-version-13 branch from 9757b67 to 4e51ade Compare March 7, 2025 19:23
- Bump the deployment target to macOS 13
- Relax regex restrictions to allow rules containing _ or other special characters
- Drop NSRegularExpression and migrate to Swift Regex
@TTOzzi TTOzzi force-pushed the bump-macos-version-13 branch from 4e51ade to af6f7ab Compare March 7, 2025 19:24
Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

Thanks!

@allevato allevato merged commit 67983dd into swiftlang:main Mar 7, 2025
19 checks passed
@TTOzzi TTOzzi deleted the bump-macos-version-13 branch March 7, 2025 19:51
@ahoppen
Copy link
Member

ahoppen commented Mar 19, 2025

This change regressed performance of swift-format by 3% in release mode

To reproduce this regression, run

git clone https://github.com/apple/swift-syntax.git
cd swift-syntax
git checkout -f 509.0.0

.build/release/swift-format lint --measure-instructions --recursive path/to/above/checkout/of/swift-syntax 2> /dev/null

@TTOzzi Could you check if there’s a good way to recover that performance regression?

@TTOzzi
Copy link
Member Author

TTOzzi commented Mar 19, 2025

This change regressed performance of swift-format by 3% in release mode

To reproduce this regression, run

git clone https://github.com/apple/swift-syntax.git
cd swift-syntax
git checkout -f 509.0.0

.build/release/swift-format lint --measure-instructions --recursive path/to/above/checkout/of/swift-syntax 2> /dev/null

@TTOzzi Could you check if there’s a good way to recover that performance regression?

Oh, I see! Thank you for letting me know.
I didn't think to check the performance at the time 😓
I'll look into it by this weekend and open a PR 🙇

@ahoppen
Copy link
Member

ahoppen commented Mar 20, 2025

Thank you ❤️

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