Skip to content

[dslx] Apply the same label rules to assert! and fail! - #5529

Open
cdleary wants to merge 2 commits into
google:mainfrom
xlsynth:cdleary/2026-11-22-dslx-assert-labels
Open

cdleary wants to merge 2 commits into
google:mainfrom
xlsynth:cdleary/2026-11-22-dslx-assert-labels

Conversation

@cdleary

@cdleary cdleary commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

DSLX introduced assert!(ok, label) as shorthand for taking a fail!(label, ()) path when ok is false. Both lower to the same IR assertion. The parser already checked labels on fail! calls. Original change

Previously, assert!(ok, "bad input") could pass DSLX interpreter tests and IR verification, then fail in default SystemVerilog codegen because the label becomes an assertion name. Two surviving assertions with the same label can also collide there. Plain Verilog codegen normally omits assertions, which explains why builds such as the Zstd RTL targets could succeed. Upstream reproduction

Apply the same label rule to both builtins during parsing. A label must be a string literal with identifier spelling and must be unique across both builtins in its enclosing function. Each lambda and each proc member function (config, init, and next) owns its own label scope. Diagnostics point at the offending argument. Recording its span allows speculative parsing to revisit one assertion without treating it as a duplicate.

This tightens source compatibility for assert!. For example, a constant byte array spelling a legal RTL name, such as [u8:111, u8:107], must now be written as "ok". The change updates affected callers and documents the shared rules. Direct calls with explicit parametrics retain the same checks, and an unsupported parenthesized specialization now produces a parser diagnostic.

Validation

  • All 2,232 targets in the optimized //xls/... sweep passed. The selection excludes contrib, dev_tools, visualization, and five test targets that require OpenROAD, Yosys, or Clang.
  • All 18 focused targets passed, including the parser, bindings, typechecker, IR conversion, fixed-point library, affected Zstd modules, and the dev-tools proc constancy test.
  • Ran the proc and lambda examples through the DSLX interpreter and IR converter. Verified direct specialized calls execute and the unsupported indirect spelling produces a positional parse error.
  • Clang-format, Bant dependency and BUILD syntax checks, and git diff --check passed.

Validate both literal labels at their argument spans and register them in a shared function scope. Track source locations so a speculative parse can revisit one assertion without reporting a duplicate. Update existing DSLX callers, examples, and parser coverage for the common contract.
}
} else {
// A parenthesized specialization such as (assert!<N>)(...) puts a
// FunctionRef in the callee position, bypassing the direct builtin call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It'd be nice if we could handle this correctly, but agreed.

cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 23, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026
cdleary added a commit to xlsynth/xlsynth that referenced this pull request Nov 24, 2026

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.

2 participants