Skip to content

Conversation

@MaxDesiatov
Copy link
Contributor

@MaxDesiatov MaxDesiatov commented Oct 22, 2025

This ensures that builds of swift-format for WASI don't regress.

@MaxDesiatov
Copy link
Contributor Author

cc @kkebo

@kkebo
Copy link
Contributor

kkebo commented Oct 23, 2025

@allevato
Copy link
Member

swift-corelibs-libdispatch

Certainly happy to dust off #675 again if it makes this requirement go away.

@MaxDesiatov
Copy link
Contributor Author

Yes, removing the Dispatch dependency would be greatly appreciated! 🙏

@MaxDesiatov
Copy link
Contributor Author

  • Atomic file writing

Is this required for in-place formatting? I wonder if a better near-term option is just to disable directly in-place formatting in files, and IIUC in-place formatting in memory would still be possible when SwiftFormat is used as a library?

@kkebo
Copy link
Contributor

kkebo commented Oct 23, 2025

@MaxDesiatov

Is this required for in-place formatting?

Yes, it is.

I wonder if a better near-term option is just to disable directly in-place formatting in files

That's one option. Or, how about using non-atomic file writing for WASI?

and IIUC in-place formatting in memory would still be possible when SwiftFormat is used as a library?

What does "in-place formatting in memory" mean? IIUC swift-format with in-place disabled will only print the formatting results.

@MaxDesiatov
Copy link
Contributor Author

MaxDesiatov commented Oct 23, 2025

That's one option. Or, how about using non-atomic file writing for WASI?

IMO that's a significant change in behavior with potential for unexpected data loss. I'd prefer that to be a new CLI flag, like --in-place-nonatomic.

What does "in-place formatting in memory" mean? IIUC swift-format with in-place disabled will only print the formatting results.

I'm referring to the SwiftFormat library product, not the executable. I'm not familiar with its API, but isn't there something there would allow in-place in-memory formatting that someone could rely on, say in a browser editor or something like that?

@allevato
Copy link
Member

I'm referring to the SwiftFormat library product, not the executable. I'm not familiar with its API, but isn't there something there would allow in-place in-memory formatting that someone could rely on, say in a browser editor or something like that?

SwiftFormat the library API doesn't write files at all, directly. The various APIs can take either a URL to read from or a String with the source as inputs, and they write the output by calling TextOutputStream.write, so the behavior is based on whatever the caller's abstraction does.

Only the swift-format executable product needs atomic file writes.

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