Skip to content

driver: -j with --legacy-codegen checks in parallel, then the AST code generator makes the MLIR - #4006

Open
bajpainaman wants to merge 2 commits into
vx-lang:mainfrom
bajpainaman:jobs-with-legacy-codegen
Open

bajpainaman wants to merge 2 commits into
vx-lang:mainfrom
bajpainaman:jobs-with-legacy-codegen

Conversation

@bajpainaman

@bajpainaman bajpainaman commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

vxc -j N --legacy-codegen stopped with "-j does not support --legacy-codegen yet". execute_parallel in src/driver.rs gave the work of the parallel frontend only to the flat code generator. So a RUN line with -j could not run on the AST code generator, and the parity mode of #1831 skipped those lines.

Now -j N --legacy-codegen runs the parallel frontend. A new function, check_modules_for_ast_codegen in src/pipeline.rs, then builds the entry module and the imported modules in the form that the sequential driver gives to MeliorGenerator. It takes the generic instances in the order of the sequential checks: the entry module's functions, methods and transfer lowerings, then the lowerings and the free functions of the imported modules. Each parallel check makes its own copy of an instance, so it keeps the first one by name, as the sequential checker makes it once. Comptime functions are removed as the sequential driver removes them. The output is the same bytes as a normal --legacy-codegen compile.

One decision for review: the checker names a closure with a counter (Closure_1), and that name is in the MLIR. A sequential check keeps one counter for the whole program. A parallel check starts it again in each function, so two functions would both make Closure_1. Renaming them would need a change in the checker. Instead, a program with a closure goes to the sequential driver, with a note on stderr. The names that ?, vec! and tasks get from counters stay in one function, and the sequential driver also starts them again in each function. So those programs take the parallel path. #4012 asks to number closures per program in a parallel check. This is the same thing -j does when the flat emitter does not take a program. Without that rule, the second closure in the new closure fixture runs the body of the first one, and the program prints 12 instead of 6.

The parity mode in compile_test.rs no longer skips -j lines. Four old -j fixtures check text that only the flat code generator writes, such as the order of its functions. Their RUN lines now end with # flat-codegen, so the normal run keeps its exact checks and the parity mode runs them unchanged. jobs_refuses_a_flag_it_cannot_honour.vx now checks --verify-seams, which -j still refuses.

Tested:

  • Before: vxc -j 2 --legacy-codegen --emit-mlir printed "-j does not support --legacy-codegen yet" with exit 1. After: it compiles.
  • Byte comparison of vxc --legacy-codegen --emit-mlir with vxc -j 2 --legacy-codegen --emit-mlir on every file in tests/backend/pass, tests/frontend/pass and tests/optimizations/pass (1,472 files):
    • 1,157 were the same bytes on the parallel path, and 85 were the same after a decline to the sequential driver.
    • 193 do not compile alone with --legacy-codegen (they need flags such as --machine, or a GPU).
    • 32 fail on the flat -j path on main too, with the same errors (E3063 with ? on std Results -j: ? on a Result of std::net gets E3063 although the function returns Result<_, NetError> #3834, E3003, E3033, E3036, E8006). This PR does not change the checks.
    • 5 differ: gpu_that_shares_host_memory_gets_host_tensors.vx, spirv_region_with_a_lane_routine_gets_an_image.vx, a_spirv64_kernel_with_an_nvvm_op_gets_no_image.vx, built_in_gpu_topology_reaches_smem.vx and gpu_kernels_written_as_ptx.vx. Each one gives two different outputs in 8 runs of plain --legacy-codegen, without -j. The cause is a walk of a HashMap in lower_spawn_region, and this PR does not cause it.
  • The new fixture compares the bytes at -j 1, -j 2 and -j 8 with the sequential output, and has functions with ? and vec! that must take the parallel path.
  • The RUN lines of the 61 old -j fixtures and the 2 new ones, as compile_test.rs runs them, with VX_NO_AST_FALLBACK=1. All 63 pass, and all 63 pass again in the parity mode.
  • I broke each part of the fix separately and read which check failed. No parallel path for --legacy-codegen: the same bytes CHECK failed, and the closure fixture's note CHECK failed. Instances sorted by name: same bytes. No first-by-name dedup: the -j 2 compile failed. No closure rule: the closure fixture's note CHECK failed, and its program printed 12 instead of 6. Comptime functions kept: same bytes. Checks in their parallel order: same bytes. Every program sent to the sequential driver: the PATH CHECK. A wrong order only at -j 1: same bytes at -j 1. A wrong order only at 8 threads: same bytes at -j 8.
  • cargo fmt --all. cargo clippy --workspace --all-targets -- -D warnings on Rust 1.100 stops at 10 errors from main's own span: _, .. patterns, which clippy: remove wildcard fields that a .. in the same pattern matches #3977 fixes. With only that lint allowed (-A clippy::unneeded_wildcard_pattern), clippy passes on every target.

I did not run the full cargo test suite, the CI parity workflow, or macOS or GPU fixtures.

Fixes #3139.

bajpainaman and others added 2 commits November 25, 2026 09:21
…e generator makes the MLIR

`vxc -j N --legacy-codegen` stopped with "-j does not support
--legacy-codegen yet". The parallel compile in execute_parallel gave its
work only to the flat code generator. So a RUN line with -j could not run
on the AST code generator, and the parity mode skipped those lines.

Now -j with --legacy-codegen runs the parallel frontend. The new
check_modules_for_ast_codegen in src/pipeline.rs then builds the modules
in the form that the sequential driver gives to MeliorGenerator. It takes
the generic instances in the order of the sequential checks, keeps the
first copy of each by name and removes comptime functions. The MLIR is
the same bytes as a normal --legacy-codegen compile.

The checker names closures, tasks and vec! values with a counter, such as
Closure_1. Each parallel check starts the counter again, so two functions
would get the same name. A program that has one goes to the sequential
driver, with a note on stderr.

The parity mode no longer skips -j lines. Four -j fixtures checked text
that only the flat code generator writes. Two now end with
`# flat-codegen`, and two use -DAG checks.

Fixes: vx-lang#3139
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iver

The rule that sent a program to the sequential driver read every
counter of the checker. A `?` on a Result also counts, so every program
with `?` took the sequential path, and the note on stderr named the
wrong reason. Only the names of closures reach the MLIR. The names that
`?`, `vec!` and tasks get stay in one function. So the rule now looks
only for a closure, which is the one thing that makes a struct.

The fixture now compares the bytes at -j 1, -j 2 and -j 8 with a
sequential compile, and has functions with `?` and `vec!` that must take
the parallel path. Two old -j fixtures keep their exact checks of the
flat code generator's order, with `# flat-codegen` instead of -DAG.

Issue: vx-lang#3139
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@hiraditya hiraditya left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I read the code. Three points:

  1. The PR description says that the normal compile starts the counters of ?, vec! and tasks again in each function. It does not: TaskCx::enter_function keeps next_id, and TypeChecker.next_id never restarts. So the names $okN and _vec_macro_tmp_N differ between a normal and a parallel compile. They do not reach the --emit-mlir text, so cmp passes. Please correct the description, and check that the debug information is also the same.
  2. For an imported function with a type error that nothing uses, a normal compile keeps the generic instances that its check made. The parallel compile clears them (c.monomorphs.clear()). That can give an extra function, or another order. I did not run it.
  3. The branch is from d3ed6cf, and main changed the normal compile since then (#4136, #4163, #4485, #4531). Please merge main and run the byte comparison of the 1,472 files again.

Generated With Claude Code

This branch has not been deployed

No deployments
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.

-j does not support --legacy-codegen

2 participants