Skip to content

feat(sv): pass subroutine arguments by reference - #2411

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678
Oct 28, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678

Conversation

@tignear

@tignear tignear commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Support ref and const ref formals of functions and tasks (IEEE 1800-2023 13.5.2). A formal is the actual itself: calls are inlined, so the inlined body names the actual's storage instead of a copy. Writes are visible at once, other names of the actual alias it, and a task keeps the reference while it is suspended. Calls without reference formals lower as before.

Actuals can be variables (scalars, strings, class handles, queues, dynamic and associative arrays, unpacked arrays, and reference formals of the caller), class and static properties, whose object is evaluated at the call, and elements of fixed-size unpacked arrays, whose position is fixed at the call. A select past such an element reads and writes nothing instead of reaching the next element. Handles and positions held across a suspension are private to each forked activation. A formal bound to a property can be passed on to output and inout arguments. Reference formals may have container types. const carries over to following formals with the direction (13.3).

The analyzer rejects static subroutines with reference formals, actuals that are expressions, constants, part-selects or nets, actuals of non-equivalent types (6.22.2), writes to const ref formals (also through selects passed to writable arguments and $readmemb/$readmemh destinations), nonblocking writes to ref formals (6.21), uses in fork ... join_any/join_none outside fork-variable initializers (9.3.2), and ref calls in continuous assignments or event expressions (13.4.1). ref static, elements of dynamically sized arrays (outdated references), elements of properties, members of unpacked structures and run-time selects of a formal bound to an element remain unsupported.

New shared cases in references.vtest pass on all backends. Verilator, Icarus and xezim failures are retained as executed evidence with an adapter-free probe; xezim's copy semantics and subarray-element failure are reviewed as sv_ref_copy_semantics and sv_ref_subarray_element.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T14:14:21.232423Z 2833ceb Manual request
ℹ️ 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: 374971962d

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

@tignear
tignear force-pushed the stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678 branch from 3749719 to bbe0ee6 Compare October 28, 2026 09:23
@tignear

tignear commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 3749719 2026-10-28 09:23 UTC
2 content 3749719 → bbe0ee6 2026-10-28 09:23 UTC
3 content bbe0ee6 → 2f84e58 2026-10-28 10:24 UTC
4 content 2f84e58 → efdb744 2026-10-28 11:08 UTC
5 content efdb744 → 2833ceb 2026-10-28 12:32 UTC

@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: bbe0ee646f

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

@tignear
tignear force-pushed the stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678 branch from bbe0ee6 to 2f84e58 Compare October 28, 2026 10:24

@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: 2f84e58efd

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

@tignear
tignear force-pushed the stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678 branch from 2f84e58 to efdb744 Compare October 28, 2026 11:09

@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: efdb744705

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

Support `ref` and `const ref` formals of functions and tasks (IEEE 1800-2023 13.5.2). A formal is the actual itself: calls are inlined, so the inlined body names the actual's storage instead of a copy. Writes are visible at once, other names of the actual alias it, and a task keeps the reference while it is suspended. Calls without reference formals lower as before.

Actuals can be variables (scalars, strings, class handles, queues, dynamic and associative arrays, unpacked arrays, and reference formals of the caller), class and static properties, whose object is evaluated at the call, and elements of fixed-size unpacked arrays, whose position is fixed at the call. A select past such an element reads and writes nothing instead of reaching the next element. Handles and positions held across a suspension are private to each forked activation. A formal bound to a property can be passed on to `output` and `inout` arguments. Reference formals may have container types. `const` carries over to following formals with the direction (13.3).

The analyzer rejects static subroutines with reference formals, actuals that are expressions, constants, part-selects or nets, actuals of non-equivalent types (6.22.2), writes to `const ref` formals (also through selects passed to writable arguments and `$readmemb`/`$readmemh` destinations), nonblocking writes to `ref` formals (6.21), uses in `fork ... join_any/join_none` outside fork-variable initializers (9.3.2), and `ref` calls in continuous assignments or event expressions (13.4.1). `ref static`, elements of dynamically sized arrays (outdated references), elements of properties, members of unpacked structures and run-time selects of a formal bound to an element remain unsupported.

New shared cases in `references.vtest` pass on all backends. Verilator, Icarus and xezim failures are retained as executed evidence with an adapter-free probe; xezim's copy semantics and subarray-element failure are reviewed as `sv_ref_copy_semantics` and `sv_ref_subarray_element`.

Change-Id: I0402167840488bdc299af95f29abbfad8c2782ca
@tignear
tignear force-pushed the stack/tignear/feat/sv-uvm-ref-args/pass-subroutine-arguments-ref--04021678 branch from efdb744 to 2833ceb Compare October 28, 2026 12:32
@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear

tignear commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into master as 6639e9d at 15:09 UTC

Merged together with #2446, #2449. 1 h 20 min in the queue, 30 min of it CI.

So far

Merge conditions: 7 of 7 met

The batch, tested on draft #2452

Condition Required by
✅ check-success = Conventional Commit title —
✅ check-success = Queue validation —
✅ any of: check-success = @github-actions/Lint & Format, check-neutral = @github-actions/Lint & Format, check-skipped = @github-actions/Lint & Format GitHub repository ruleset rule master
✅ any of: check-success = @github-actions/Rust Test & NAPI Build, check-neutral = @github-actions/Rust Test & NAPI Build, check-skipped = @github-actions/Rust Test & NAPI Build GitHub repository ruleset rule master
✅ any of: check-success = @github-actions/JS Test (Ubuntu), check-neutral = @github-actions/JS Test (Ubuntu), check-skipped = @github-actions/JS Test (Ubuntu) GitHub repository ruleset rule master
✅ any of: check-success = @github-actions/Conventional Commit title, check-neutral = @github-actions/Conventional Commit title, check-skipped = @github-actions/Conventional Commit title GitHub repository ruleset rule master
✅ any of: check-success = @github-actions/Queue validation, check-neutral = @github-actions/Queue validation, check-skipped = @github-actions/Queue validation GitHub repository ruleset rule master

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued Mergify queue entry label Oct 28, 2026
@tignear

tignear commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 2833ceb133

ℹ️ 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 +353 to +357
(Some(high), Some(low)) if high >= *width as i128 || low >= *width as i128 => {
let total = *total as i128;
(
ConstExpr::Literal((total + high - low.min(high)).to_string()),
ConstExpr::Literal((total + low - low.min(high)).to_string()),

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 Preserve the valid bits of partially out-of-range selects

When a packed part-select straddles the boundary of an element reference, this condition moves the entire select past the containing array, discarding its valid bits too. For example, with logic [7:0] a[2], calling f(a[0]) where f(ref logic [7:0] r) executes r[9:6] = 4'hf should set a[0][7:6], but instead writes nothing. The existing constant_select_write behavior and indexed_select.vtest regressions preserve the in-range portion of such writes. Clip the access to the referenced element while retaining the corresponding RHS bits, rather than treating a partially out-of-range access as wholly invalid.

Useful? React with 👍 / 👎.

Comment on lines +4635 to +4639
let actual = args
.get(position)
.cloned()
.flatten()
.or_else(|| param.default.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 Include default reference actuals in pre-scanned write targets

When an edge-triggered process omits a writable reference argument, this fallback aliases the default variable even though Ff::scan only records writable actuals explicitly present in args; default_calls scans calls inside defaults, not their destinations. For example, function automatic void inc(ref int x = g); x++; endfunction called by always @(posedge clk) inc(); writes g in the working region, but g is absent from the precomputed publication targets, so its stable value never receives the increment. Resolve omitted reference defaults during the write-target scan as well as during call execution; the existing default-argument regression only exercises an initial process, which stores directly into stable state.

Useful? React with 👍 / 👎.

Comment on lines +4750 to +4751
for (formal, _, target) in &references {
self.m.name_to_id.insert(formal.clone(), *target);

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 Preserve formal packed coordinates when aliasing variable storage

When equivalent integral types have different packed bounds, replacing the formal's variable ID also replaces the layout used to interpret its selects. For example, logic [15:8] a is accepted by f(ref logic [7:0] x), but x[0] = 1'b1 is subsequently interpreted by constant_select_write against a's [15:8] range, so the write is discarded instead of setting a[8]. Ascending actual ranges can likewise redirect writes to the wrong bit. Keep the formal's coordinate mapping while aliasing the actual's storage, and apply the same treatment to the corresponding remapping in Comb::call.

Useful? React with 👍 / 👎.

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