Skip to content

GH-118943: Fix a race condition when generating jit_stencils.h #118957

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 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a possible race condition affecting parallel builds configured with
``--enable-experimental-jit``, in which compilation errors could be caused
by an incompletely-generated header file.
19 changes: 12 additions & 7 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,18 @@ def build(
):
return
stencil_groups = asyncio.run(self._build_stencils())
with jit_stencils.open("w") as file:
file.write(digest)
if comment:
file.write(f"// {comment}\n\n")
file.write("")
Copy link
Contributor

@hroncok hroncok May 13, 2024

Choose a reason for hiding this comment

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

Not entirely sure what was the purpose of this line, but it is no longer there. I guess it did nothing, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. Yeah, I think this was originally intended to write a newline, but it was really doing nothing. But I think we do want to add a newline whether or not there's a comment, so I'll move one of them from the comment line to here.

for line in _writer.dump(stencil_groups):
file.write(f"{line}\n")
jit_stencils_new = out / "jit_stencils.h.new"
try:
with jit_stencils_new.open("w") as file:
file.write(digest)
if comment:
file.write(f"// {comment}\n")
file.write("\n")
for line in _writer.dump(stencil_groups):
file.write(f"{line}\n")
jit_stencils_new.replace(jit_stencils)
finally:
jit_stencils_new.unlink(missing_ok=True)


class _COFF(
Expand Down
Loading