Skip to content

feat(sv): support tagged packed unions - #1883

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481
Oct 24, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Support scalar SystemVerilog tagged packed unions following IEEE 1800-2023
7.3.2 and 11.9: constructors and void members, nested/struct payloads, casts,
context-typed function returns and argument defaults, signed values and wide
four-state data. Defaults bind in the enclosing declaration scope.

Check active tags on reads and writes, including output/inout arguments and
system-function destinations/seeds. Retain writable actuals separately from
their checks and recheck before copy-out. Preserve assignment sizing before
checked temporaries, and keep checks effectful during expression inlining so
unused arguments cannot discard them. Conditional and short-circuit paths
only check accesses that execute.

Require nominally compatible whole-union assignments, port connections and
output/inout copy-out, including output-port concatenation elements. Reject
integral formals/system outputs that could
fabricate tags. Unpacked tagged unions, pattern matching and continuous or
concatenation member drivers remain unsupported; port constructor expressions
require an intermediate typed signal.

Evaluate active tagged-member reads in constant functions while preserving
guards, widths and signs. Reject time-function and timescale-query values
before expression fast paths can bypass tagged-target type checks.

Fixes #1909
Fixes #1910

Add nine portable shared cases and Celox runtime-error/type-rejection tests.
Verilator 5.052 rejects seven two-state cases and cannot run the two four-state
cases; Icarus 13.0 rejects all nine. Retain reviewed diagnostics without
skipping cases or changing assertions, with both Rust and JS baseline checks.

The review request for active-payload-only equality remains a specification
investigation in #1889, with a four-state reproducer and the checked LRM clauses.
It is not yet a confirmed defect; whole-value equality remains unchanged.

Validation:

  • Prior full SystemVerilog integration suite: 4,540 passed, 20 existing ignored.
  • Updated tagged-union regressions: 68 passed across configured backends, including
    constant widths, signed and nested payloads, lazy branches and invalid tags.
  • Updated analyzer suite after master synchronization: 803 passed, 3 existing ignored; doctests passed.
  • SV frontend unit tests and doctests from the preceding revision.
  • Affected-crate and SystemVerilog test-target Clippy; cargo fmt --check.
  • Shared-suite retained-report tests and external report gates.
  • All 2,054 official sv-tests CI verdicts match the reviewed expectations;
    the tagged packed union simulation now passes in both state modes.
  • External changed cases with Verilator and Icarus; reviewed failures above.
  • node --test scripts/check-external-suite-report.test.mjs.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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 🔄 Running since 2026-10-24T17:20:58.311962Z da00920 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: 63c6fe0185

ℹ️ 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-tagged-unions/support-tagged-packed-unions--170d9481 branch from 63c6fe0 to f157ae2 Compare October 24, 2026 09:18
@tignear

tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 63c6fe0 2026-10-24 09:17 UTC
2 content 63c6fe0 → f157ae2 Fix P1: preserve destination assignment sizing before checked tagged-member write temporaries; add width, part-select and signed regression coverage. 2026-10-24 09:17 UTC
3 content f157ae2 → 23e5076 Fix P2: retain writable tagged-member actuals and separate live tag checks at argument capture and copy-out; add task/function/system regressions. 2026-10-24 09:30 UTC
4 content 23e5076 → 7eae8d9 Fix three P2 findings: validate nominal copy-out compatibility, retain checked arguments during expression inlining, and bind tagged returns in their declared result type. 2026-10-24 09:45 UTC
5 content 7eae8d9 → 4810a3e Fix output-port concatenation type bypass and bind tagged argument defaults in formal context; track unconfirmed equality semantics in #1889. 2026-10-24 10:02 UTC
6 content 4810a3e → e69a9ed Fix CI expectation drift: review official sv-tests artifacts and promote tagged/packed.sv from fail to pass in both state modes; all 2054 verdicts match. 2026-10-24 14:52 UTC
7 content e69a9ed → 3d77a16 Fix remaining P2 reviews #1909/#1910: evaluate guarded constant member reads and validate tagged targets before time/query fast paths; add regressions and review changed external diagnostics. 2026-10-24 17:13 UTC
8 content 3d77a16 → da00920 Rebase onto current master to resolve conflicts preventing PR CI from starting. 2026-10-24 17:20 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: f157ae208a

ℹ️ 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-tagged-unions/support-tagged-packed-unions--170d9481 branch from f157ae2 to 23e5076 Compare October 24, 2026 09:30

@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: 23e5076ac4

ℹ️ 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-tagged-unions/support-tagged-packed-unions--170d9481 branch from 23e5076 to 7eae8d9 Compare October 24, 2026 09:46

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

ℹ️ 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 +56 to +60
if plan.tag.payload_width > width {
parts.push(Expr::Literal(format!(
"{}'bx",
plan.tag.payload_width - width
)));

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 Compare only the active payload in tagged-union equality

In four-state simulation, constructors fill unused payload bits with X, but Finish::Binary in expression_binding/direct.rs still lowers tagged-union equality as ordinary packed-vector equality. For a union with void Empty and an eight-bit Full member, assigning tagged Empty to two variables and comparing them with == therefore produces X instead of true. Tagged-union equality must compare the tags and then only the active member's value, ignoring unused payload bits; otherwise comparisons involving void or shorter members return incorrect results.

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.

Tracked in #1889. The observed X equality was reproduced, but the requested active-payload-only semantics still need a normative basis. The issue records the checked clauses and resolution criteria. Equality is unchanged; leaving this thread unresolved pending that investigation.

@tignear
tignear force-pushed the stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481 branch from 7eae8d9 to 4810a3e Compare October 24, 2026 10:02

@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: 4810a3e9cc

ℹ️ 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-tagged-unions/support-tagged-packed-unions--170d9481 branch from 4810a3e to e69a9ed Compare October 24, 2026 14:55
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear
tignear force-pushed the stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481 branch from e69a9ed to 3d77a16 Compare October 24, 2026 17:14
Support scalar SystemVerilog tagged packed unions following IEEE 1800-2023
7.3.2 and 11.9: constructors and void members, nested/struct payloads, casts,
context-typed function returns and argument defaults, signed values and wide
four-state data. Defaults bind in the enclosing declaration scope.

Check active tags on reads and writes, including output/inout arguments and
system-function destinations/seeds. Retain writable actuals separately from
their checks and recheck before copy-out. Preserve assignment sizing before
checked temporaries, and keep checks effectful during expression inlining so
unused arguments cannot discard them. Conditional and short-circuit paths
only check accesses that execute.

Require nominally compatible whole-union assignments, port connections and
output/inout copy-out, including output-port concatenation elements. Reject
integral formals/system outputs that could
fabricate tags. Unpacked tagged unions, pattern matching and continuous or
concatenation member drivers remain unsupported; port constructor expressions
require an intermediate typed signal.

Evaluate active tagged-member reads in constant functions while preserving
guards, widths and signs. Reject time-function and timescale-query values
before expression fast paths can bypass tagged-target type checks.

Fixes #1909
Fixes #1910

Add nine portable shared cases and Celox runtime-error/type-rejection tests.
Verilator 5.052 rejects seven two-state cases and cannot run the two four-state
cases; Icarus 13.0 rejects all nine. Retain reviewed diagnostics without
skipping cases or changing assertions, with both Rust and JS baseline checks.

The review request for active-payload-only equality remains a specification
investigation in #1889, with a four-state reproducer and the checked LRM clauses.
It is not yet a confirmed defect; whole-value equality remains unchanged.

Validation:
- Prior full SystemVerilog integration suite: 4,540 passed, 20 existing ignored.
- Updated tagged-union regressions: 68 passed across configured backends, including
  constant widths, signed and nested payloads, lazy branches and invalid tags.
- Updated analyzer suite after master synchronization: 803 passed, 3 existing ignored; doctests passed.
- SV frontend unit tests and doctests from the preceding revision.
- Affected-crate and SystemVerilog test-target Clippy; cargo fmt --check.
- Shared-suite retained-report tests and external report gates.
- All 2,054 official sv-tests CI verdicts match the reviewed expectations;
  the tagged packed union simulation now passes in both state modes.
- External changed cases with Verilator and Icarus; reviewed failures above.
- node --test scripts/check-external-suite-report.test.mjs.

Change-Id: I170d94817a52f2d1b382daf800f3908d8e94d5c3
@tignear
tignear force-pushed the stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481 branch from 3d77a16 to da00920 Compare October 24, 2026 17:20
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-24 18:19 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1883 on master (c430061) #1920
  • ✅ Merged — 2026-10-24 20:24 UTC · at bb056674a8d2ac0b5aea1b629da7aba9724076ac · merge

This pull request spent 2 hours 4 minutes 37 seconds in the queue, including 2 hours 3 minutes 19 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify mergify Bot mentioned this pull request Oct 24, 2026
40 of 71 tasks
@mergify
mergify Bot merged commit bb05667 into master Oct 24, 2026
31 checks passed
@mergify
mergify Bot deleted the stack/tignear/feat/sv-tagged-unions/support-tagged-packed-unions--170d9481 branch October 24, 2026 20:24
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sv): reject time-function values assigned to tagged unions fix(sv): evaluate checked tagged members in constant functions

1 participant