Skip to content

feat(sv)!: let always @* blocks share a variable - #2135

Closed
tignear wants to merge 1 commit into
masterfrom
feature/fix/2129-shared-comb-loop-temporaries
Closed

tignear wants to merge 1 commit into
masterfrom
feature/fix/2129-shared-comb-loop-temporaries

Conversation

@tignear

@tignear tignear commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Closes #2129. The level-sensitive twin of #1945 (#1950): several plain always @* blocks may write one variable, such as a shared loop index (IEEE 1800-2023 6.5, 9.2.2). Only always_comb, always_latch and always_ff restrict a variable to one process.

Semantics (decided on #2129: option C)

  • Default, strict LRM. Each block waits on the variables it reads, the shared one included (9.4.2.2), so its writes wake the other blocks. Such blocks now run as processes that wait on their implicit event expression (Module::run_comb_processes_as_processes), which gives exactly that behavior.

    • Blocks that keep waking each other end the run with time T does not settle: processes keep resuming: alwaysat f.sv:7:3 intop, alwaysat f.sv:11:3 intop``. Verilator reports DIDNOTCONVERGE for the same design.
    • Blocks that do converge run as the standard says. The shared case below agrees with Icarus and Verilator.
  • Opt-in deviation: shared_always_temporary (--diagnostic shared_always_temporary=warn|allow; the default is error, meaning strict). The variable becomes a temporary of each block when all of the following hold:

    • only always @* blocks write it;
    • each block writes it before reading it on every path;
    • nothing else reads it: no other process, continuous assignment, subroutine, port, instance connection, or hierarchical name from another module.

    Its writes then wake no other block, as in Icarus, and the variable keeps its initial value. warn reports the variable and the blocks. Documented in docs/guide/celox-toml.md (and the Japanese version) as a deviation, with "declare the variable inside each block" as the standard-conforming alternative.

  • Diagnostics with locations. "multiple variable drivers for x" now names the writers' locations; always_comb blocks sharing a variable are still rejected that way. The run-time "does not settle" and "does not suspend" errors name the processes (RuntimeSchema::process_origins) instead of indices.

Tests

  • Shared case procedural::level_processes_share_a_written_variable (strict; one block's writes wake the other once). It passes verify-sv-icarus and verify-sv-verilator, and Celox in two- and four-state.
  • tests/frontends/systemverilog/procedural.rs:
    • strict non-convergence names both blocks;
    • the opt-in prints Icarus's 1 1 in two- and four-state; warn reports j with both blocks;
    • the opt-in is not applied, so the strict behavior and no warning remain, for another reader, a read before the write, and a hierarchical reader;
    • always_comb sharing is rejected with locations.

Validation

  • Workspace with CI features (rebased on master 5b789f2): 17,762/17,762 pass. Clippy is clean; celox --no-default-features is clean with -D warnings.

Effect on rtlmeter HummingbirdV2-E203 (nodelay configuration, DISABLE_SV_ASSERTION, shared_always_temporary=warn)

The opt-in applies to 3 variables and E203 gets past the multiple-driver error. It now stops at the scheduler's "Combinational loop detected" through the always @* processes of the APB SPI controller (u_spictrl: data_to_tx_ready -> rx_clk_en -> u_rxreg.clk_en_o -> ... -> spi_en_tx -> ...), which is a separate gap.

Several plain always blocks may write one variable, such as a shared
loop index (IEEE 1800-2023 6.5, 9.2.2); only always_comb, always_latch
and always_ff restrict it to one process. always @* blocks that write a
common variable now run as processes waiting on their implicit event
expression (9.4.2.2), so their writes wake each other as the standard
requires. Blocks that keep waking each other end the run with "does
not settle", which now names the processes instead of their indices.

The shared_always_temporary diagnostic (error by default) opts into a
deviation: with warn or allow, a variable that only such blocks write,
each before it reads it, and that nothing else reads is a temporary of
each block, as in Icarus. The multiple-driver error names the writers.

Closes #2129.

BREAKING CHANGE: AnalysisOptions has a new field,
shared_always_temporaries, and FrontendWarningKind a new variant,
SharedAlwaysTemporary.

Change-Id: Id83fadfd087ffacbd71224f39bc3ede1910ee053
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T09:51:27.032200Z 60d730a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60d730a5f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1416 to +1418
.ff_processes()
.iter()
.any(|process| stmts_mention(process.body(), name))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check edge-event signals before privatizing a shared variable

With shared_always_temporary=warn|allow, a variable used only in another process's edge control is incorrectly considered unobserved because this check examines only FfProcess::body(), not FfProcess::events(). For example, two blocks containing always @* j = a; and always @* j = b; qualify for privatization even when always @(posedge j) q <= 1'b1; observes their writes. Renaming both writers leaves the real j at its initial value, suppressing the edge and changing q. Include event signals in the outside-reader check so this design retains strict behavior.

Useful? React with 👍 / 👎.

; here the second block's writes to `j` wake the first one, which reads it,
; while the first block's loop writes wake nothing. Which block writes `j`
; last is not defined, so the output leaves it out.
(case level_processes_share_a_written_variable

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Register the convergent shared-variable case on Celox backends

This new case has no Celox backend test registration: a repository-wide search for level_processes_share_a_written_variable finds only this definition. crates/celox/tests/systemverilog.rs generates executable backend tests from explicit sv_backends! entries, while compiled_scheduler_coverage only builds timed designs without running their assertions. Consequently, ordinary Celox test runs do not verify this case's convergent behavior or expected output; the added Rust tests instead cover non-convergence and the opt-in deviation. Add the corresponding @case registration in the procedural backend tests. AGENTS.md explicitly requires: “Wire shared cases into Celox's backend test harness”.

AGENTS.md reference: AGENTS.md:L102-L104

Useful? React with 👍 / 👎.

Comment on lines +1316 to +1318
let local = format!("{}$always{driver}", signal.name());
module = module.add_local(sv::ir::LocalVariable {
name: local.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Generate temporary names without colliding with user identifiers

With shared_always_temporary=warn|allow, the generated name can collide with a legal SystemVerilog identifier such as j$always0. procedural::register_locals inserts these names into the same name_to_id map as ports and signals without checking for an existing entry, so privatizing j in combinational process 0 silently replaces the binding of an unrelated input or signal named j$always0. For example, a block containing j = 0; y = j$always0; then reads the generated temporary instead of the input, corrupting y. Allocate a fresh name against the module's existing identifiers before adding each temporary.

Useful? React with 👍 / 👎.

@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@tignear tignear closed this Nov 1, 2026
@tignear
tignear deleted the feature/fix/2129-shared-comb-loop-temporaries branch November 8, 2026 20:19
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.

SV: accept loop temporaries shared by level-sensitive always blocks (blocks rtlmeter E203)

1 participant