Skip to content

fix(sv): count writes through called subroutines as process drivers - #1135

Merged
tignear merged 3 commits into
masterfrom
fix/sv-output-argument-drivers
Oct 9, 2026
Merged

tignear merged 3 commits into
masterfrom
fix/sv-output-argument-drivers

Conversation

@tignear

@tignear tignear commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Validation of variable drivers only looked at assignment targets. A variable written another way could therefore also be written by a second process without any error:

  • through a call's output or inout argument, e.g. always_ff ... x <= pick(q, q); next to always_ff ... q <= d;
  • by the body of a called subroutine, e.g. a task that assigns q

A subroutine writes for the process that calls it (IEEE 1800-2023 9.2.2.2), so these designs are now rejected with "multiple variable drivers", like other conflicting drivers. The driver scan follows each call it finds in a statement or expression to its output and inout actuals, and then into the subroutine body, recursively and visiting each subroutine once. A variable written only through one process's calls is still accepted.

collect_calls moves from the FF lowering to the shared procedural helpers. A new stmt_calls gathers the calls in one statement's own expressions, now including system task arguments and repeat counts. The FF commit-target scan uses stmt_calls too.

Tests

SystemVerilog-only regressions, since Verilator and Icarus do not reject multiply driven variables:

  • review_regressions::rejects_variables_also_written_through_output_arguments
  • review_regressions::rejects_variables_also_written_by_called_subroutine_bodies
  • review_regressions::accepts_a_variable_written_only_through_one_process_calls

Validation

  • cargo test -p celox --features systemverilog --test systemverilog: 1431 passed.
  • ::sv tests with --include-ignored: 837 passed / 91 failed, the same failing set as master.
  • cargo test -p celox-test-suite --features verilator,icarus passes, including the retained-report checks.
  • clippy and fmt are clean.
  • sv-tests conformance: matches conformance/sv-tests/expected.tsv.

Variable driver validation only looked at assignment targets, so a
variable written through a call's output argument, or by a called
subroutine body, could also be written by another process. The driver
scan now follows each call to its output actuals and its body, which
write for the calling process (IEEE 1800-2023 9.2.2.2).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T11:25:51.644933Z 6a65dfb New commits
ℹ️ 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: 310dd14579

ℹ️ 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".

driver_id,
net_lvalue_range(lvalue, constants, parameter_types),
));
for (param, arg) in subroutine.params.iter().zip(&args) {

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 Traverse calls in omitted arguments' defaults

When a call omits an input with a default expression, zipping the parameters only with the supplied args skips that default entirely. For example, if f(input logic a = side_effect()) is invoked as f() and side_effect() assigns module variable q, this scan does not attribute the write to the calling process, so a second always_ff that writes q is incorrectly accepted. The FF target scan has the same omission, even though call lowering evaluates param.default; traverse the selected defaults for omitted arguments and their nested calls.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reproduced and fixed in eb514c1: the driver scan and the FF target scan now also follow the calls in the defaults of omitted arguments. Covered by review_regressions::rejects_variables_also_written_by_default_argument_calls.

Comment on lines +594 to +595
if visited.insert(name) {
self.body(drivers, &subroutine.body, driver_id, visited);

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 Bound recursive driver traversal by the call-depth limit

With a sufficiently long acyclic chain of subroutine calls, this newly recursive scan descends once per callee without enforcing the existing MAX_CALL_DEPTH limit of 64. Because driver validation runs before the comb/FF lowerers perform their guarded call traversal, a generated or otherwise large input can exhaust the compiler thread's stack instead of returning the intended subroutine call depth limit exceeded diagnostic. Track depth here or make the call-graph walk iterative.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in eb514c1: the driver scan carries the call depth and stops beyond MAX_CALL_DEPTH; process lowering then reports the depth limit as before.

Omitted arguments evaluate their defaults, whose calls may write
variables for the calling process; the driver and FF target scans now
follow them. The driver scan stops at the call depth limit, which the
process lowering reports.
@tignear

tignear commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: eb514c157f

ℹ️ 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".

@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks


Comparing fix/sv-output-argument-drivers (6a65dfb) with master (09b6b33)

Open in CodSpeed

…rivers

Follow calls in the select positions of assignment targets, which master now runs, when scanning for drivers.
@tignear
tignear enabled auto-merge October 9, 2026 11:52
@tignear
tignear added this pull request to the merge queue Oct 9, 2026
Merged via the queue into master with commit dde867e Oct 9, 2026
36 checks passed
@tignear
tignear deleted the fix/sv-output-argument-drivers branch October 9, 2026 12:59
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.

1 participant