-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3578ca6
Make the generation of jit_stencils.h atomic
brandtbucher bc32227
blurb add
brandtbucher dc9404c
Don't stick jit_stencils.h in a temporary directory
brandtbucher 04ff733
Remove empty write
brandtbucher 5266129
Feedback from code review
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Don't stick jit_stencils.h in a temporary directory
- Loading branch information
commit dc9404c5457a33da24f2564f60ae35d3fe9ae99a
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -180,18 +180,18 @@ async def _compile( | |||||
| await _llvm.run("clang", args_o, echo=self.verbose) | ||||||
| return await self._parse(o) | ||||||
|
|
||||||
| async def _build_stencils( | ||||||
| self, work: pathlib.Path | ||||||
| ) -> dict[str, _stencils.StencilGroup]: | ||||||
| async def _build_stencils(self) -> dict[str, _stencils.StencilGroup]: | ||||||
| generated_cases = PYTHON_EXECUTOR_CASES_C_H.read_text() | ||||||
| opnames = sorted(re.findall(r"\n {8}case (\w+): \{\n", generated_cases)) | ||||||
| tasks = [] | ||||||
| async with asyncio.TaskGroup() as group: | ||||||
| coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work) | ||||||
| tasks.append(group.create_task(coro, name="trampoline")) | ||||||
| for opname in opnames: | ||||||
| coro = self._compile(opname, TOOLS_JIT_TEMPLATE_C, work) | ||||||
| tasks.append(group.create_task(coro, name=opname)) | ||||||
| with tempfile.TemporaryDirectory() as tempdir: | ||||||
| work = pathlib.Path(tempdir).resolve() | ||||||
| async with asyncio.TaskGroup() as group: | ||||||
| coro = self._compile("trampoline", TOOLS_JIT / "trampoline.c", work) | ||||||
| tasks.append(group.create_task(coro, name="trampoline")) | ||||||
| for opname in opnames: | ||||||
| coro = self._compile(opname, TOOLS_JIT_TEMPLATE_C, work) | ||||||
| tasks.append(group.create_task(coro, name=opname)) | ||||||
| return {task.get_name(): task.result() for task in tasks} | ||||||
|
|
||||||
| def build( | ||||||
|
|
@@ -211,18 +211,19 @@ def build( | |||||
| and jit_stencils.read_text().startswith(digest) | ||||||
| ): | ||||||
| return | ||||||
| with tempfile.TemporaryDirectory() as tempdir: | ||||||
| work = pathlib.Path(tempdir).resolve() | ||||||
| stencil_groups = asyncio.run(self._build_stencils(work)) | ||||||
| new_jit_stencils = work / "jit_stencils.h" | ||||||
| with new_jit_stencils.open("w") as file: | ||||||
| stencil_groups = asyncio.run(self._build_stencils()) | ||||||
| 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\n") | ||||||
| file.write("") | ||||||
| for line in _writer.dump(stencil_groups): | ||||||
| file.write(f"{line}\n") | ||||||
| new_jit_stencils.replace(jit_stencils) | ||||||
| jit_stencils_new.replace(jit_stencils) | ||||||
| finally: | ||||||
| jit_stencils_new.unlink(True) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to guess (and look up) what the boolean stands for. Would you mind using a keyword argument instead?
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, good suggestion. |
||||||
|
|
||||||
|
|
||||||
| class _COFF( | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.