Skip to content

Support SwiftSyntax v601 #93

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 2 commits into from
Jun 23, 2025
Merged

Conversation

scottrhoyt
Copy link
Contributor

Issue/Motivation

SwiftSyntax 601.0.1 is the first version of the library that supports the new preview for prebuilts in SPM. This functionality dramatically improves build times (especially in release configuration) for macro libraries. Now that Mockable 0.4.0 supports SwiftSyntax v601, the path is cleared for this library.

Tasklist

  • Update Package.swift to support SwiftSyntax up to and including v601.
  • Add conditional support for new generic argument API in SwiftSyntax v601.
  • Build MapLibreSwiftUI in debug/release configurations and benchmark against SwiftSyntax 510.0.3 and 601.0.1.

Outcome

MapLibreSwiftUI builds dramatically faster in both configurations. While it was hard to benchmark builds in Xcode accurately--since swift build will fail--I saw times drop from several minutes to archive down to just a matter of seconds. This is consistent with the results I saw on Mockable with release builds falling from ~140s down to 9s.

Caution

MapLibreSwiftUI won't build against SwiftSyntax 601.0.0 due to a missing marker module that was fixed in 601.0.1.

@ianthetechie ianthetechie self-requested a review June 17, 2025 02:31
#if canImport(SwiftSyntax601)
// This provides compatibility for the new SwiftSyntax API, returning an empty result if the argument has
// been parsed as an expression.
private func generateStyleProperty(for attributes: AttributeSyntax, valueType: GenericArgumentSyntax.Argument,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be used anywhere; am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it might not be straight forward, but this is what's going on:

  • SwiftSyntax 601 introduces a new nested GenericArgument.Argument type because the parser can now parse types and expressions (experimental).
  • So in 601, GenericArgumentSyntax.argument doesn't give you a TypeSyntax as before, but this new enum.
  • This code provides an override (conditional on SwiftSyntax601) to generateStyleProperty that takes this new Argument type and unwraps it to send to the existing generateStyleProperty function.
  • This means you don't need any changes at the call site, but in 601 it is actually calling this override.

Does that make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, wow 😅 Yeah, I think that makes sense. Thanks! I'll get the swiftformat stuff cleaned up and we can get this merged.

@ianthetechie ianthetechie merged commit ee68391 into maplibre:main Jun 23, 2025
2 checks passed
@scottrhoyt
Copy link
Contributor Author

Thanks for the merge. Excited for the faster compile times!

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