Repository navigation
fix(sv): preserve interface bindings during declaration analysis - #1474
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 013def0548
ℹ️ 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".
| matches!(node, RefNode::Identifier(_)) | ||
| && identifier_text(node, tree).is_some_and(|name| deferred.contains(&name)) |
There was a problem hiding this comment.
Distinguish declaration names from deferred references
When a declaration contains an identifier that merely declares a struct/union member matching a later interface handle, this predicate treats it as an interface dependency and removes the entire declaration. For example, typedef struct packed { logic later; } T; I #($bits(T)) first(); I later(); drops T before evaluating first's override, even though struct members have their own namespace and the typedef does not reference the interface. This makes valid parameter overrides fail depending only on an unrelated member-name coincidence.
Useful? React with 👍 / 👎.
| let authored = interfaces::declared_names(RefNode::ModuleDeclarationAnsi(declaration), tree)? | ||
| .into_iter() | ||
| .collect::<HashSet<_>>(); |
There was a problem hiding this comment.
Include enum literals in binding-collision detection
declared_names does not collect EnumNameDeclaration, so a module-level enum literal such as h$f is omitted from this new collision check. If interface instance h exports a parameter or enum named f, both become the semantic name h$f; module analysis then keeps the imported constant in const_env, causing authored references to the enum literal to resolve to the interface value instead. Enumerated constants need the same rejection or hygienic handling as the localparams covered by the added tests.
Useful? React with 👍 / 👎.
| ) -> Option<usize> { | ||
| let path = variable_path(node, select, syntax_tree, dimensions)?; | ||
| let mut path = variable_path(node, select, syntax_tree, dimensions)?; | ||
| bind_interface_path(&mut path); |
There was a problem hiding this comment.
Respect lexical shadowing before binding interface paths
When a procedural or subroutine-local packed struct shadows an interface handle, this unconditional rewrite resolves $dimensions through the module-level interface instead of the local variable. For example, inside a function that declares a local struct variable i with members payload.field, while the module also has interface instance i exporting payload, $dimensions(i.payload.field) is now computed from the interface member's type. Check the active lexical dimensions for a local root before applying the imported interface mapping; the same issue affects the newly changed $size helper.
Useful? React with 👍 / 👎.
013def0 to
39b29dd
Compare
efe55f4 to
2f93125
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 39b29ddb00
ℹ️ 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".
| let authored = interfaces::declared_names(RefNode::ModuleDeclarationAnsi(declaration), tree)? | ||
| .into_iter() | ||
| .collect::<HashSet<_>>(); |
There was a problem hiding this comment.
Restrict collision checks to module-scope declarations
When a subroutine-local declaration or formal is named like an imported binding, this rejects otherwise valid lexical shadowing because declared_names recursively includes function/task ports, locals, loop variables, and genvars. For example, a module containing interface instance h with member f and an unrelated function formal named h$f now reports an interface-binding collision, even though the formal exists only within that function; limit this check to declarations in the binding's actual scope or make it scope-aware.
Useful? React with 👍 / 👎.
| .filter(|(_, port)| { | ||
| !references_deferred(RefNode::AnsiPortDeclaration(port), tree, &deferred) | ||
| }) |
There was a problem hiding this comment.
Propagate dependencies from deferred ports
When an ANSI port's type depends on an unbound interface and a body declaration depends only on that port, the body fixed-point runs before this filter and never adds the removed port's name to deferred. For example, with output logic [base.N-1:0] x, localparam W = $bits(x), followed by instances Cfg base(); Cfg #(W) next();, the temporary header keeps W but removes x, so declaration analysis tries to evaluate $bits(x) before base can be bound. Deferred ports need to contribute their declared names before dependent body declarations are collected.
Useful? React with 👍 / 👎.
Merge Queue Status
This pull request spent 15 minutes 4 seconds in the queue, with no time running CI. ReasonThe pull request #1474 has been manually updated Requeued — the merge queue status continues in this comment ↓. |
39b29dd to
c2f4f29
Compare
Local interface constants were unavailable while collecting caller declarations, packed-struct dimension queries missed interface prefix bindings, and authored functions could silently replace interface methods with the same internal name. Selective contract collection also rejected unsupported, unrequested interfaces. Collect independent caller declarations first, then restore dependent declarations as local instances become bound, including constants used by later instances. Bind packed-struct paths for both dimension helpers, reject collisions with renamed interface symbols, and filter interface declarations before collecting selected contracts. All changes operate on the original syntax tree. Covers all four review findings on #1468: - #1468 (comment) - #1468 (comment) - #1468 (comment) - #1468 (comment) Add API regressions for function/constant/type collisions and unrequested unsupported interfaces, plus shared executable cases for dependent declarations and structure-member dimension queries across all five Celox backends. Validation: analyzer/frontend units (367 passed, 4 existing ignores), complete SystemVerilog suite (2599 passed, 285 existing ignores), DPI (62), unpacked arrays (7), mixed frontend (7), affected-crate clippy with -D warnings, and formatting. Both new shared cases pass Verilator 5.052. Icarus 13.0 rejects the hierarchical parameter initializer and misreports the structure field's dimension count; retain narrow reproduction evidence and classify these external-tool limitations. Also address the five scope/dependency findings on this PR: - Exclude declaration tokens from deferred references and bind caller type queries before entering an interface (#1474 (comment)). - Include module-scope enum literals in collision diagnostics (#1474 (comment)). - Prefer lexical packed-structure roots over interface mappings (#1474 (comment)). - Keep subroutine formals, locals and structure members out of module-scope collision checks (#1474 (comment)). - Propagate deferred port names and inherited port types through the declaration dependency closure (#1474 (comment)). Three additional shared cases exercise these paths on all five backends and Verilator. Icarus's hierarchical constant and structure-dimension limitations have retained evidence and matching report rows. Retained-report integration checks, lifetime/unit-scope integrations (26 tests), clippy and formatting pass. Change-Id: I6ad012f664d5e6f9dadc0ed7001dccf5247eae8b
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2f4f29dcf
ℹ️ 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".
| matches!(node, RefNode::Identifier(_)) | ||
| && identifier_locate(node.clone()) | ||
| .is_some_and(|locate| !declarations.contains(&locate.offset)) | ||
| && identifier_text(node, tree).is_some_and(|name| deferred.contains(&name)) |
There was a problem hiding this comment.
Track deferred references by binding, not spelling
When a module-scope declaration contains a lexically unrelated reference whose final identifier matches a later interface handle, this spelling-only test removes it. For example, localparam W = pkg::later; I #(W) first(); I later(); defers W even though pkg::later is a package member; because first is elaborated before later, W is absent and the valid override fails. The new declaration-token exclusion does not address qualified or lexically shadowed references, so dependency detection needs to account for the identifier's binding or scope.
Useful? React with 👍 / 👎.
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
c2f4f29 to
f3b6a24
Compare
2f93125 to
224fe1f
Compare
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 55 minutes 14 seconds in the queue, including 36 minutes 43 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.
Depends-On: #1468