Skip to content

Store Original Macro Implementations Per SwiftSyntax Version as Separate Files#62

Open
omochi wants to merge 1 commit intogohanlon:mainfrom
omochi:versioned-macrosample-splitfile
Open

Store Original Macro Implementations Per SwiftSyntax Version as Separate Files#62
omochi wants to merge 1 commit intogohanlon:mainfrom
omochi:versioned-macrosample-splitfile

Conversation

@omochi
Copy link
Copy Markdown
Contributor

@omochi omochi commented Jan 10, 2026

The background and purpose of this patch are the same as the previous PR,

, so please refer to that.

Content of this patch:

As discussed there, this implements the method of storing multiple versions of sample macros in this repository by having separate files for each version, instead of one long file divided by #if.

When maintaining multiple versions of implementations, individual files are enclosed in #if so that only specific sample macros can be enabled, in combination with the currently adopted SwiftSyntax version.

Adding Comments

We are disabling swift-format so that the sample macro code can be saved as is.

We are including the version of the source package to facilitate tracking when the sample macro is updated upstream.

//===----------------------------------------------------------------------===//
// swift-format-ignore-file
// The content of this file was copied from the swift-syntax repository.
// version: 602.0.0
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a discrepancy between the filename 601 and the commit version 602.0.0, but this is not a mistake.
The implementation included in 602.0.0 of the swift-syntax repository
can be compiled with Swift Syntax 601 but not with Swift Syntax 600.
Therefore, the filename is 601 to indicate that it is "available from 601",
and this corresponds to the parameter of canImport.

@gohanlon
Copy link
Copy Markdown
Owner

I haven't read through this properly yet, but I wanted to be sure that you'd seen the DEVELOPMENT.md file that I added recently. It mentions make tasks you may find helpful, including a task to run test suite over the full matrix of Swift × swift-syntax versions.

Given all that:

  • Do the full matrix of tests still pass with this PR (make test-linux)?
  • Are the // swift-format-ignore-file comments working to disable swift-format (make format), or must they need to literally be "at the top of the file" (as the docs describe)?
  • Do you have any questions about the DEVELOPMENT.md, or suggested improvements?

@omochi
Copy link
Copy Markdown
Contributor Author

omochi commented Jan 10, 2026

Sorry, I missed DEVELOPMENT.md. I will work on it later when I have time.

@omochi
Copy link
Copy Markdown
Contributor Author

omochi commented Jan 11, 2026

Do the full matrix of tests still pass with this PR (make test-linux)?

I tried installing podman with brew, running bin/setup-podman, and then make test-linux, but it didn't work.
The script produced the following error, preventing the tests from running:

[omochi@omochi-mbp 2-swift-memberwise-init-macro (versioned-macrosample-splitfile =)]$ bin/setup-podman --status
Podman: ✓ installed (5.7.1)
Machine: ✓ running (16 GB, 9 CPUs)

Host: 32 GB RAM, 12 CPUs
[omochi@omochi-mbp 2-swift-memberwise-init-macro (versioned-macrosample-splitfile =)]$ make test-linux
./bin/test-linux --parallel --continue-on-error --log-dir ./tmp/logs
Auto-detected 2 parallel jobs (16 GB Podman VM)
Logging to: ./tmp/logs/2026-01-11_154245
Running 25 combinations with 2 parallel jobs...
./bin/test-linux: line 420: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
make: *** [test-linux] Error 2

My machine environment is macOS Tahoe 26.1.


By the way, I was manually testing 5 different environments like this on my end.

export SWIFT_SYNTAX_VERSION=602.0.0..<603.0.0
swift package clean && swift package update swift-syntax \
	&& swift test --disable-experimental-swift-testing

swift-format-ignore-file appears to be working correctly. As a quick test, I removed it and ran make format, and the indentation changed.


Do you have any questions about the DEVELOPMENT.md, or suggested improvements?

I wasn't used to such a conventional file name, so I overlooked it.
It would be good to have a link in the README to guide contributors to that file.

For example, in the SwiftSyntax repository, it says:

Contributing
Start contributing to SwiftSyntax see this guide for more information.
https://github.com/swiftlang/swift-syntax/tree/main?tab=readme-ov-file#contributing

When opening the link, it describes how to build and test, and we can naturally find the relevant information.

When I read DEVELOPMENT.md again, I realized that I had noticed its contents, but since I didn’t know what "podman" was, I thought it looked like a hassle and ended up ignoring it.

It might be more approachable if it said something like:

This project uses podman to set up a Linux environment for running automated tests.
Podman is similar to Docker and can be easily installed via Homebrew.
Please install it first before proceeding.

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