zig icon indicating copy to clipboard operation
zig copied to clipboard

Support running LLVM backend in a separate thread

Open antlilja opened this issue 1 year ago • 4 comments

Closes #20635

@jacobly0

Most changes are quite straightforward, I did however have to move some Compilation mutex locking from Compilation.zig into PerThread.zig in order to fix a race condition on Zcu.import_tables. This seemed like the most reasonable solution as it's accessed all over the place in Sema.zig, but maybe it goes against some overarching locking strategy?

antlilja avatar Aug 13 '24 15:08 antlilja

Backends should never be calling importPkg, another solution to this will need to be found before enabling llvm backend threading.

jacobly0 avatar Aug 13 '24 19:08 jacobly0

The only caller of importPkg seems to be getStackTraceType which is used when lowering function types. I threw together a bit of a hacky fix which stores the stack trace type inside the Zcu to test it if works.

antlilja avatar Aug 16 '24 15:08 antlilja

What makes it "hacky" and what would a non "hacky" fix do differently?

andrewrk avatar Aug 16 '24 16:08 andrewrk

What makes it "hacky" and what would a non "hacky" fix do differently?

Checking the value every time at the end of finishFunc feels a bit unnecessary, but maybe this it's a reasonable solution. I just wanted to point it out in case someone reviewing with more experience of the codebase had encountered something similar and had a better solution to initializing Zcu state.

antlilja avatar Aug 16 '24 17:08 antlilja