Repository navigation
compile: parallel module compile by default, with a make jobserver client - #4782
Merged
Merged
Conversation
aleksisch
force-pushed
the
aleksisch/jobserver-support
branch
12 times, most recently
from
November 26, 2026 01:22
2476bec to
4bf457d
Compare
A job learns that its module nests a compile only when the module's compile ends. From that walk position on no job starts, later results that finished are dropped, and the main thread compiles those modules in walk order with the whole sequential pipeline. The deferred macro context build, which ran after the module's GC finalizer had shared its types, is gone. A comment reader reads every module parsed after it, required or not, so a module that installs one has to be declared `!inscope`, and is an error otherwise. The require scan reads `!inscope` from the module line, and every module after such a module in walk order depends on it in the DAG: it is parsed after the reader exists, and still runs in parallel with the others. A parse that takes a reader holds one lock for the whole parse, so parallel parses no longer interleave on the reader's state (the lint crashed in rst_comment).
fork_debug_agent_context creates a second context and runs code in it, like the builtins already marked nestsCompile. A macro module that calls it - daslib/profiler's installer - now builds its macro context on the main thread after the DAG jobs; built on a worker, it installed its thread-local debug agent there, and that agent outlived the process.
run_split_emit in llvm_jit_run.das optimizes and emits each partition on jobque jobs, which call the LLVM C API directly; jobs and results travel through channels, so no string crosses a context. jit_par_emit_begin/ add/run and their std::thread pool leave module_jit.cpp. A job runs on a clone of the JIT context, so llvm_macro's LLVMShutdown finalizer now skips job and thread clones: a dying job no longer shuts LLVM down under the jobs still running. Same codegen times on the lint (25 partitions).
Each module of the compile DAG and each partition of the split JIT emit holds a token of the build's GNU make jobserver while it runs (MAKEFLAGS --jobserver-auth: a make 4.4 fifo, inherited pipe fds, or a Windows semaphore). Jobserver::acquire returns the process's implicit token or a pool token, or waits; the JobserverToken gives it back. das reaches it through jobque's with_jobserver and with_jobserver_token. With no jobserver advertised acquire returns at once, as before.
aleksisch
force-pushed
the
aleksisch/jobserver-support
branch
from
November 26, 2026 08:24
4bf457d to
8c1e2bf
Compare
A read-only walk is a ConstVisitor: the printer keeps the levels that place its brackets in a table of its own, and the inliner's clone shape stores no children back. ConstVisitor gains the program-level hooks the printer needs (constVisitProgram, constVisitFunction). A module freezes with its types' alias caches filled, a dynamic module loaded on demand freezes like the startup ones, and folding never stamps access_fold on a frozen global. A wasm build without threads compiles in walk order. compile_threads still defaults to 1; -compile-threads turns jobs on.
On Windows popen runs the line through cmd.exe, which drops the first and the last quote of a line that starts with one. The child command starts with the quoted daslang path, so the path broke and the test failed with "The filename, directory name, or volume label syntax is incorrect". The line is wrapped in one more pair of quotes there.
aleksisch
force-pushed
the
aleksisch/jobserver-support
branch
from
November 26, 2026 15:07
b75fd27 to
cdf4abd
Compare
The POSIX pool calls dup and reads /proc/self/fd, and the PS4/PS5 libc has neither, so jobserver.cpp did not compile there. On DAS_TARGET_PS the pool is a stub: open returns null, and Jobserver falls back to its own limit, as it does when no make jobserver is in the environment.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Behavior change: required modules now compile on all cores by default - a host that wants one thread sets
CodeOfPolicies.compile_threads = 1.Why. The parallel module compile was opt-in, and a parallel compiler under
make -jor a parallel test runner starts N processes that each use every core.What changes.
src/misc/jobserver.cpp) reads--jobserver-authfromMAKEFLAGS(make 4.4 fifo, inherited pipe fds, Windows semaphore); the compile DAG and the split JIT emit run on one thread plus the tokens the pool grants.CodeOfPolicies.compile_threadsdefaults to 0, theJobQuethread count.daslangkeeps one thread for-aot,-use-aot,-exeand-lib;-compile-threadsstill overrides the last three.Observable behavior.
daslang x.dascompiles required modules on 1 thread -> on all cores.make -j3with a+recipe -> the compile takes at most 2 extra threads, and gives them back.-aot/-use-aot/-exe/-lib-> unchanged, one thread.Where to look.
JobserverTokensinsrc/misc/jobserver.cpp, its two call sites (compileModules,jit_par_emit_run), and the new default incode_of_policies.h.Validation, claims, ledger
Validation
make -j3/-j16with-compile-threads 8, strace shows 2 / 7 tokens read from the pool and the same count written back; a recipe without+gets no fds and the client stays off.tests/languageunder dastest (now parallel by default) passed before the rebase.Claims - stated, not tested
/proc, so the pipe-fd form turns the client off there; the make 4.4 fifo form still works.Not done