Repository navigation
refactor(sv)!: bind assignment patterns without rewriting source - #1467
Conversation
|
This pull request is part of a Mergify stack:
|
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. |
Parameter assignment patterns now travel as structured bindings from the caller into the receiving declaration. This preserves declaration defaults, independent instance bindings, caller-resolved types and constants, and the receiver's sizing context without serializing expressions into replacement SystemVerilog. Remove pattern text substitution and reparsing from specialization. Add shared regressions for isolated instance bindings and enclosing arithmetic, with retained Icarus unsupported-syntax evidence. Validation: analyzer/frontend unit tests; full SV backend suite; DPI and unpacked-array suites; formatting; clippy on analyzer, frontend and test suite. Verilator passes both new shared regressions; Icarus rejects their unsupported parameter-pattern syntax, recorded under the existing limitations. BREAKING CHANGE: ParameterOverride::pattern_text becomes bound_pattern, ParsedSource::analyze_module accepts structured pattern bindings, and with_pattern_parameter_overrides is removed. Change-Id: I6d1a921182f71c4e4bcebfc945366be9d27c872d
c39aa09 to
b4519bc
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b4519bc46b
ℹ️ 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".
| shapes = vec![ | ||
| VariableDimensions { | ||
| unpacked: rest.to_vec(), | ||
| ..shape.clone() | ||
| }; | ||
| count | ||
| ]; |
There was a problem hiding this comment.
Validate pattern arity before allocating target elements
When a large unpacked parameter is overridden by a wrong-sized positional or repeated pattern, this eagerly clones one VariableDimensions and creates one key for every declared element before the arity checks at lines 353–369 can reject the override. A declaration such as a billion-element unpacked array with a one-item override can therefore abort compilation from allocation failure instead of returning the intended unsupported-pattern error; check list/repetition cardinality before materializing these vectors or construct the shapes lazily.
Useful? React with 👍 / 👎.
| keys.iter() | ||
| .map(|key| { | ||
| items | ||
| .iter() | ||
| .rev() | ||
| .find(|(k, _)| k == key) |
There was a problem hiding this comment.
Index keyed pattern entries instead of repeatedly scanning them
For a valid keyed override with n explicit entries, lowering first calls keys.contains for every item and then scans the full item list again for every target key, making specialization quadratic in the array size. Generated parameter tables with thousands of keyed entries can consequently spend tens or hundreds of millions of comparisons here, whereas the previous slot-based lowering was linear; build a key-to-value map or indexed slot vector once.
Useful? React with 👍 / 👎.
| || identifier_locate(RefNode::ParameterIdentifier(¶m.nodes.0)).is_some_and(|loc| { | ||
| scope::imported() | ||
| .pattern_parameter_bindings | ||
| .contains_key(&loc.offset) |
There was a problem hiding this comment.
Keep enclosing pattern expressions as constant parameters
When an override merely contains a typed pattern inside a larger scalar expression, such as .P(int'{default: 1} + 1), from_param stores it as Items::Value, but this predicate classifies every bound pattern as an array parameter. parameters_from_declaration consequently omits P from the parameter/constant environment and array_parameters turns it into a signal, so dependent parameter defaults, port ranges, and generate conditions that reference P become unresolved even though the old rewritten scalar initializer remained a compile-time constant. Distinguish fully bound scalar Items::Value overrides from shape-dependent patterns and apply them through the normal value-override path.
Useful? React with 👍 / 👎.
Merge Queue Status
This pull request spent 39 minutes 27 seconds in the queue, including 24 minutes 34 seconds running CI. Required conditions to merge
|
Interface-dependent caller declarations were analyzed before their bindings existed, while unrelated declarations could be delayed merely because an identifier matched a later interface instance. For example, pkg::later must remain available to I #(W) first() even when I later() follows it. Collect independent caller declarations and restore dependent ones as local interfaces become bound. Use the existing scope-aware reference collector so package-qualified names, structure members and nested lexical bindings do not create false dependencies. Propagate dependencies through ANSI ports and their inherited types, and resolve caller type queries before entering an interface. Preserve lexical roots in packed-structure dimension queries; reject collisions between module declarations (including enum literals) and imported interface symbols without rejecting subroutine-local shadowing. Select requested interface contracts before analyzing unsupported prototypes. All work uses original CSTs. Covers the four review findings on #1468 and six on #1474, including #1474 (comment). Shared cases exercise dependent declarations/ports, dimensions, and independent package/member/local bindings on all five Celox backends. API regressions cover collisions and selective collection. Retain narrow evidence for existing Icarus hierarchical-constant and structure-dimension limitations; the latest binding regression passes both Verilator and Icarus without exclusions. Sync the remaining stack onto master after #1467 merged. Preserve both generate import resolution and interface scopes in the overlapping analyzer paths, and keep master's time-scale API alongside the interface-plan API. Validate #1468 independently before validating this top member. Validation after syncing: analyzer/frontend units (371 passed, 4 existing ignores), full SV suite (2827 passed, 110 existing ignores), DPI (68), lifetime / unit-scope / arrays (33), mixed frontend (7), retained reports (3), formatting and affected-crate clippy with -D warnings. The lower member independently passes its units, full SV suite (2797), related integrations, retained reports and clippy. The new shared case also passes Verilator and Icarus. Change-Id: I6ad012f664d5e6f9dadc0ed7001dccf5247eae8b
Parameter assignment patterns now travel as structured bindings from the caller into the receiving declaration. This preserves declaration defaults, independent instance bindings, caller-resolved types and constants, and the receiver's sizing context without serializing expressions into replacement SystemVerilog.
Remove pattern text substitution and reparsing from specialization. Add shared regressions for isolated instance bindings and enclosing arithmetic, with retained Icarus unsupported-syntax evidence.
Validation: analyzer/frontend unit tests; full SV backend suite; DPI and unpacked-array suites; formatting; clippy on analyzer, frontend and test suite. Verilator passes both new shared regressions; Icarus rejects their unsupported parameter-pattern syntax, recorded under the existing limitations.
BREAKING CHANGE: ParameterOverride::pattern_text becomes bound_pattern, ParsedSource::analyze_module accepts structured pattern bindings, and with_pattern_parameter_overrides is removed.