Repository navigation
fix(sv): resolve input port patterns after specialization - #1772
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0bb163ebfa
ℹ️ 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".
| Self::Runtime { expr, signed } => ( | ||
| expr, | ||
| signed.ok_or_else(|| unsupported("assignment pattern operand signedness"))?, | ||
| ), |
There was a problem hiding this comment.
Coerce each two-state pattern element
When a port pattern targets a mixed packed struct such as struct packed { bit [3:0] a; logic [3:0] b; }, this runtime branch only resizes each value and ignores the selected member shape's is_2state. An input like .cfg('{a:'x, b:'x}) therefore leaves X bits in a; the later whole-port conversion cannot fix this because the aggregate is four-state due to b. SystemVerilog requires X/Z assigned to a bit member to become zero, so apply ToTwoState while lowering each two-state element.
Useful? React with 👍 / 👎.
| tree: &AnalysisContext<'_>, | ||
| dims: &PackedDimensions, | ||
| ) -> Converted<BoundPattern> { | ||
| match binding::value_mode(root, tree, dims, false)? { |
There was a problem hiding this comment.
Defer member-key disambiguation until the target is known
When a structure member name also exists as a constant in the caller, parsing the pattern here without a target misclassifies the member key as an array index. For example, with caller localparam tag = 0 and a child struct member named tag, .cfg('{tag: value, default: 0}) stores Key::Index(0) because prepare_native receives shape=None; binding against the specialized struct later rejects that key instead of assigning its tag member. Preserve ambiguous name keys until the receiving shape can distinguish members from constant indices.
Useful? React with 👍 / 👎.
| let mut connection = PortConnection::new(formal.clone(), formal, None); | ||
| connection.bound_pattern = Some(bound_patterns::from_port(root, tree, dims)?); | ||
| return Ok(connection); |
There was a problem hiding this comment.
Bind patterns on interface input ports before dropping expressions
For an interface instance with an aggregate input port, such as I i(.cfg('{default:'1})), this path replaces the connection's actual_expr with only bound_pattern. Interface elaboration in ast/interface_binding.rs consumes actual_expr directly and skips connections where it is None, while interface declarations are subsequently removed from ordinary module-instance lowering, so bind_port_patterns never gets a chance to restore the expression. The interface input is therefore left unassigned or rejected; resolve the pattern during interface elaboration or carry it through that path.
Useful? React with 👍 / 👎.
| pub(crate) fn bind_port(&self, target: &Type) -> Converted<crate::ir::Expr> { | ||
| let state = AnalysisState::default(); | ||
| let shape = procedural::dimensions_from_type(target); | ||
| self.lower(&state, &shape, &PackedDimensions::default()) | ||
| .map(Into::into) |
There was a problem hiding this comment.
Descend outer packed dimensions before struct members
When the input type is a packed array of a packed struct, procedural::dimensions_from_type retains both the outer packed ranges and the struct members, but BoundPattern::lower checks shape.members before the outer packed dimension. Thus for typedef struct packed { logic a, b; } S; input S [1:0] cfg, .cfg('{default:'1}) is lowered as one two-bit struct instead of two struct elements; glue then widens that value to four bits, producing 4'b0011 rather than 4'b1111. The binding path needs to consume packed dimensions enclosing the aliased struct before selecting its members.
Useful? React with 👍 / 👎.
0bb163e to
110e998
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 110e998798
ℹ️ 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".
| .filter(|shape| !shape.members.is_empty() || !shape.unpacked.is_empty()) | ||
| .and_then(|shape| shape.pattern_type(&tree.state, dims))) |
There was a problem hiding this comment.
Retain packed-array types when deciding default broadcast
When a default item supplies a value of the exact same multidimensional packed type as an unpacked target element, this filter discards its type because it has neither members nor unpacked dimensions. For example, with typedef logic [1:0][3:0] pair_t; input pair_t cfg[2], .cfg('{default:value}) should copy an 8-bit pair_t value into each cfg element, but assignment_value treats it as an untyped scalar, descends the outer packed dimension, and duplicates the low nibble (turning 8'hAB into 8'hBB). Preserve packed aggregate types here so an exact element-type match is assigned as a whole.
Useful? React with 👍 / 👎.
| if !default && !shape.unpacked.is_empty() { | ||
| return Err(unsupported( | ||
| "scalar assignment pattern item for unpacked array", | ||
| )); |
There was a problem hiding this comment.
Permit array-valued items in outer pattern lists
When the target has multiple unpacked dimensions, an outer list item may itself be an expression of the remaining subarray type, but this unconditional check rejects it before the captured value_type can be compared or lowered. For example, given byte row[2] and a port input byte cfg[2][2], the valid connection .cfg('{row, row}) is rejected as a scalar item even though each row exactly matches one outer element. Allow matching unpacked-array values to be assigned as a whole and reserve this error for genuinely scalar or incompatible operands.
Useful? React with 👍 / 👎.
| ) { | ||
| patterns::typed_shape(root, tree, dims)? | ||
| } else { | ||
| dimensions::operand_shape(root, tree, dims)? |
There was a problem hiding this comment.
Preserve aggregate types through conditional pattern operands
When both branches of a conditional have the same packed-struct type, the conditional result retains that aggregate type, but operand_shape reduces the mux to a scalar width here and native_value_type consequently returns None. For item_t a, b and a port input item_t cfg[2], .cfg('{default:(sel ? a : b)}) should replicate the selected struct into both elements; instead assignment_value treats the value as nonmatching and broadcasts its low member-sized bits into every field, turning a selected 8'h35 into 8'h55. Preserve the common aggregate type of conditional operands before deciding whether to descend the default.
Useful? React with 👍 / 👎.
110e998 to
8153322
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81533222a0
ℹ️ 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".
| values.push(if constant { | ||
| Value::Expression(frozen(&tree.state, expr, dims)?) |
There was a problem hiding this comment.
Preserve types for constant aggregate defaults
When a parameter override uses an aggregate constant as a default item, such as localparam item_t V = '{a:3,b:5}; Child #(.P('{default:V})), this branch freezes the expression into Value::Expression without retaining item_t. The new recursive default lowering therefore treats V as untyped and broadcasts its low member-sized bits into every member, producing 8'h55 instead of copying 8'h35 into each item_t. Retain the aggregate type alongside frozen constant values so exact-type defaults are assigned as a whole.
Useful? React with 👍 / 👎.
| let default = default | ||
| && !value_type.is_some_and(|ty| shape.pattern_type(state, dims).as_ref() == Some(ty)); |
There was a problem hiding this comment.
Compare unpacked defaults by assignment compatibility
When an unpacked-array default has compatible element counts but different index bounds, raw Type equality fails here even though the arrays are assignment-compatible. For example, a byte row[4:5] used in .cfg('{default:row}) for input byte cfg[2][0:1] should copy row into each outer element; instead this keeps default set, descends into the target subarray, and eventually rejects row as an array value for a scalar. Use unpacked-array assignment compatibility, rather than exact range equality, when deciding whether to descend.
Useful? React with 👍 / 👎.
| if !shape.members.is_empty() { | ||
| return Ok(Expr::Concat( |
There was a problem hiding this comment.
Reject recursive defaults for packed unions
When an outer array pattern supplies a default for a packed-union element, this branch treats the overlapping union members as independent struct fields and concatenates values for all of them, bypassing the packed-union rejection used when the union is the direct pattern target. For a supported equal-width mixed-state union such as union packed { logic a; bit b; } inside an array, '{default:'x} produces {1'bx,1'b0} per union and downstream width coercion can retain only the final zero bit. Detect the all-zero member offsets here and reject the unsupported union default instead of constructing a value wider than the union.
Useful? React with 👍 / 👎.
|
Queued — the merge queue status continues in this comment ↓. |
Connecting an untyped pattern such as .cfg('{8{'0}}) failed before the receiving
port's shape was available. Preserve caller values, keys and repetition counts
until the module or interface input type is specialized, then lower the pattern
in that assignment context.
Share assignment conversion between native typed and deferred patterns. Convert
two-state members individually, consume outer packed dimensions before struct
fields, and disambiguate name keys against the receiving shape. Retain nominal
aggregate operand types through conditionals and function calls before inlining.
Use one typed value representation for constant and runtime operands; preserve
source sign and type before folding and substitute stored aggregate constants.
This prevents default struct constants such as 8'h35 becoming 8'h55 and retains
signed extension and mixed-state members. Reject unsupported recursive defaults
for packed unions instead of concatenating their overlapping fields.
Allow assignment-compatible unpacked subarrays as explicit pattern items. Keep
the stricter type-matching rule for selecting whole defaults: IEEE 1800-2023
6.22.1(f) requires matching fixed-array bounds, and 10.9.1 uses matching types
there. Review r4354410020's proposed relaxation is not adopted; Slang independently
rejects its row[4:5] default for cfg[2][0:1]. Explicit differently bounded array
items remain accepted. Preliminary function signatures supply types and signs
for calls inside typed patterns.
Add eighteen shared cases covering specialization, caller scope, mixed states,
aggregates, interfaces, collisions, nominal identity, expressions and constants.
Add API rejection checks for incompatible subarrays, array-to-scalar items and
unsupported union defaults. The latest P1 reproduction fails on all five
backends against the published analyzer, returning 0x5555 instead of 0x3535.
Validation:
- Full SV: 4104 passed, 20 existing ignored across five backends.
- Analyzer: 791 passed, 3 existing ignored; frontend: 4 passed.
- Shared suite default-feature library: 30 passed.
- Relevant library/harness Clippy -D warnings, fmt and diff checks pass.
- Verilator passes the latest packed constant matrix, including signed extension,
and the minimal literal case. The mixed-state adapter is unsupported and
Verilator rejects valid unpacked constant rows. The mismatched-bounds case is
rejected but classified as a compile error by the adapter. Earlier results
include the distinct-struct default discrepancy and unpacked-item limits.
- Slang 12.0 corroborates the latest ordinary aggregates, literal values, mixed
states, unpacked rows and rejection of mismatched default bounds. One signed
struct pattern-initializer discrepancy remains recorded: it zero-extends a
signed 0xf5 value. IEEE 7.2.1/10.9.1 and Verilator support sign extension.
- Icarus cannot compile the added pattern/interface cases. External limitations
and disagreements are not passes; no exclusions or expectations were changed.
- Replayed all 20 formerly pattern-blocked Taxi configurations against the final
implementation. The next blockers remain $size x9, interface handles x6,
undriven net x4, non-integer override x1; none reaches cocotb. All 199 resolved
SV sources match the original audit. No RTL, optimization or diagnostic-policy
changes.
Change-Id: Icbecc7d790d68db2fa484738d78188f5afdbf442
8153322 to
78aeed1
Compare
Merge Queue Status
This pull request spent 1 hour 21 minutes 59 seconds in the queue, including 1 hour 20 minutes 36 seconds running CI. Required conditions to merge
|
Connecting an untyped pattern such as .cfg('{8{'0}}) failed before the receiving
port's shape was available. Preserve caller values, keys and repetition counts
until the module or interface input type is specialized, then lower the pattern
in that assignment context.
Share assignment conversion between native typed and deferred patterns. Convert
two-state members individually, consume outer packed dimensions before struct
fields, and disambiguate name keys against the receiving shape. Retain nominal
aggregate operand types through conditionals and function calls before inlining.
Use one typed value representation for constant and runtime operands; preserve
source sign and type before folding and substitute stored aggregate constants.
This prevents default struct constants such as 8'h35 becoming 8'h55 and retains
signed extension and mixed-state members. Reject unsupported recursive defaults
for packed unions instead of concatenating their overlapping fields.
Allow assignment-compatible unpacked subarrays as explicit pattern items. Keep
the stricter type-matching rule for selecting whole defaults: IEEE 1800-2023
6.22.1(f) requires matching fixed-array bounds, and 10.9.1 uses matching types
there. Review r4354410020's proposed relaxation is not adopted; Slang independently
rejects its row[4:5] default for cfg[2][0:1]. Explicit differently bounded array
items remain accepted. Preliminary function signatures supply types and signs
for calls inside typed patterns.
Add eighteen shared cases covering specialization, caller scope, mixed states,
aggregates, interfaces, collisions, nominal identity, expressions and constants.
Add API rejection checks for incompatible subarrays, array-to-scalar items and
unsupported union defaults. The latest P1 reproduction fails on all five
backends against the published analyzer, returning 0x5555 instead of 0x3535.
Validation:
and the minimal literal case. The mixed-state adapter is unsupported and
Verilator rejects valid unpacked constant rows. The mismatched-bounds case is
rejected but classified as a compile error by the adapter. Earlier results
include the distinct-struct default discrepancy and unpacked-item limits.
states, unpacked rows and rejection of mismatched default bounds. One signed
struct pattern-initializer discrepancy remains recorded: it zero-extends a
signed 0xf5 value. IEEE 7.2.1/10.9.1 and Verilator support sign extension.
and disagreements are not passes; no exclusions or expectations were changed.
implementation. The next blockers remain $size x9, interface handles x6,
undriven net x4, non-integer override x1; none reaches cocotb. All 199 resolved
SV sources match the original audit. No RTL, optimization or diagnostic-policy
changes.