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

generate-check-code-prefix: Run rustfmt automatically; only write if changed #1282

Merged
merged 3 commits into from
Dec 18, 2022

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Dec 18, 2022

This avoids unnecessary recompilation when nothing changed.

@@ -16,3 +16,4 @@ rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "c01f014b1269eedcf4bdb45d5fbc62ae2beecf31" }
strum = { version = "0.24.1", features = ["strum_macros"] }
strum_macros = { version = "0.24.3" }
subprocess = "0.2.9"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why the dependency on this crate and not std::process?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

std::process doesn’t have the functionality of simultaneously writing to and reading from the child in a deadlock-free way:

The difference between this and simply writing input data to self.stdin and then reading output from self.stdout and self.stderr is that the reading and the writing are performed simultaneously. A naive implementation that writes and then reads has an issue when the subprocess responds to part of the input by providing output. The output must be read for the subprocess to accept further input, but the parent process is still blocked on writing the rest of the input daata. Since neither process can proceed, a deadlock occurs. This is why a correct implementation must write and read at the same time.

But actually, it looks like rustfmt always buffers all input before starting to write, so maybe std::process is fine.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@charliermarsh charliermarsh merged commit 20ac823 into astral-sh:main Dec 18, 2022
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