Skip to content

[codegen] Error instead of silently overriding an explicit codegen version for proc-scoped channels - #5163

Open
12yuuuu wants to merge 1 commit into
google:mainfrom
12yuuuu:fix-4554-codegen-version-proc-scoped
Open

12yuuuu wants to merge 1 commit into
google:mainfrom
12yuuuu:fix-4554-codegen-version-proc-scoped

Conversation

@12yuuuu

@12yuuuu 12yuuuu commented Oct 17, 2026

Copy link
Copy Markdown

Fixes #4554

Since #3679, when a package uses proc-scoped channels, codegen always switches to version 1.5, even if the user explicitly set --codegen_version=1.0 (or 2). There is no error or warning. This override is in codegen_main.cc, and also in two more places in xls/tools/codegen.cc.

What this PR changes

  • xls/tools/codegen.cc: add ResolveCodegenVersion() and call it once in CodegenMetadata::Create(). The three old overrides are removed. Rules: unset or 0 -> 1.5 (same as before); 1.5 -> 1.5; explicit 1.0 or 2.0 with proc-scoped channels -> InvalidArgumentError. The error message says which version was requested and gives two options (use 1.5, or convert with --lower_to_proc_scoped_channels=false). Packages without proc-scoped channels are not affected.
  • xls/examples/codegen_options/BUILD: the two f_proc targets were set to "2", but because of the override they were actually generated by 1.5 all along. Changed them to "1.5", so the output is the same.
  • Updated the flag help text and docs. Added 7 test cases to codegen_main_test.py.

Two design choices. I think both are reasonable, but please tell me if you want them changed.

  1. Explicit 2.0 is also rejected, not only 1.0. The issue is about not silently replacing the user's choice, and this applies to 2.0 in the same way. [Proc-scoped channels] Force Codegen 1.5 to be used when proc-scoped channels are generated. #3679 also intended proc-scoped channels to go through 1.5. The only place in the repo that used "explicit 2 + proc-scoped" was the example BUILD above, which was itself misleading. If you prefer to keep 2.0 silently on 1.5, or let it really run 2.0, it is a one-line change in ResolveCodegenVersion().
  2. The check is in CodegenMetadata::Create(), so calling Schedule() alone with this combination also fails. I think this is correct: Schedule() already parses and validates all codegen flags (for example, a bad version string already fails there), so a version that cannot be used for this package is just another invalid flag. This is also what lets codegen_main fail before scheduling, which can take a long time. The other caller, io_printer_main, gets the same error for the same wrong flags. If you prefer Schedule() to not check this, it is about 10 lines to limit the check to the codegen paths.

Testing (macOS, Bazel 8.7.0, on top of 54b1b49): //xls/tools:codegen_main_test and //xls/examples/codegen_options:verilog_targets_build pass. On unpatched main, the same proc-scoped IR with --codegen_version=1.0 succeeds silently, and its output is byte-identical to the 1.5 output. I did not run the full test suite locally, so I rely on CI for that.

Assisted-by: Claude (Anthropic). Code and tests were drafted with AI assistance; I reviewed the diff and ran the tests above myself.

…rsion for proc-scoped channels

Since google#3679, a package with proc-scoped channels forced codegen 1.5
even when the user explicitly asked for another version (`codegen_version =
"1.0"` on a BUILD target, or `--codegen_version=1.0`). The user's choice was
replaced without any message, so they could believe they were exercising
codegen 1.0 while actually running 1.5.

The codegen version is now resolved in one place, `ResolveCodegenVersion()` in
xls/tools/codegen.cc:
  * no version requested (0 / default)     -> 1.5, as before;
  * 1.5 requested                           -> 1.5;
  * 1.0 or 2.0 requested + proc-scoped IR   -> InvalidArgumentError that names
    the requested version and the two ways forward (use 1.5, or convert the
    DSLX with --lower_to_proc_scoped_channels=false). 1.5 is treated as the
    required version for proc-scoped channels per google#3679.
Packages without proc-scoped channels are unaffected.

The version is resolved exactly once, in CodegenMetadata::Create(), which every
entry point of xls/tools/codegen.h goes through (Schedule, Codegen,
ScheduleAndCodegen, ScheduleAndConvertToBlock); codegen_main therefore fails
before scheduling. Note that this means Schedule() alone (scheduling with
codegen flags but no RTL generation) now also rejects an incompatible explicit
version. The resolved version is stored in the CodegenOptions, and the three
former copies of the override (codegen_main.cc, CodegenFromMetadata,
ScheduleAndConvertToBlock) are removed; the two dispatch sites only check that
the version has been resolved.

xls/examples/codegen_options: the two f_proc targets asked for codegen_version
"2" but, because of the override, were generated with 1.5 all along; they now
say "1.5", so their output does not change.

Tests (codegen_main_test.py, new proc-scoped IR input): default version works,
explicit 1.5 works and matches the default, explicit 1 / 1.0 / 2 / 2.0 are
rejected with a message naming the version and "proc-scoped channels", and
explicit 1.0 is still accepted for a proc with global channels.

Fixes google#4554

Assisted-by: Claude (Anthropic) — code and tests drafted with AI assistance; reviewed and tested by the author
@allight

allight commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. LGTM

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proc-scoped channels should not silently force codegen version 1.5

2 participants