Skip to content

fix(sv): preserve interface bindings during declaration analysis - #1474

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6
Oct 18, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6

Conversation

@tignear

@tignear tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear

tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 refactor(sv)!: lower interfaces from original syntax #1468
2 fix(sv): preserve interface bindings during declaration analysis #1474 👈

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T09:34:10.762520Z f3b6a24 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.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 18, 2026

@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: 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".

Comment on lines +730 to +731
matches!(node, RefNode::Identifier(_))
&& identifier_text(node, tree).is_some_and(|name| deferred.contains(&name))

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 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 👍 / 👎.

Comment on lines +633 to +635
let authored = interfaces::declared_names(RefNode::ModuleDeclarationAnsi(declaration), tree)?
.into_iter()
.collect::<HashSet<_>>();

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 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);

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 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 👍 / 👎.

@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6 branch from 013def0 to 39b29dd Compare October 18, 2026 02:11
@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503 branch from efe55f4 to 2f93125 Compare October 18, 2026 02:11
@tignear

tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 013def0 2026-10-18 02:10 UTC
2 content 013def0 → 39b29dd Register the two reviewed Icarus exclusions in retained report shards so the follow-up independently passes the CI evidence check. 2026-10-18 02:10 UTC
3 content 39b29dd → c2f4f29 Address all five PR #1474 review findings: declaration/reference separation, enum and lexical collision scopes, lexical structure queries, caller type queries, and transitive/inherited port dependenc… 2026-10-18 03:09 UTC
4 content c2f4f29 → f3b6a24 Fix review 4305532348 using scope-aware references, then sync merged #1467 and resolve #1468 base conflicts before requeueing 2026-10-18 09:29 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: 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".

Comment on lines +633 to +635
let authored = interfaces::declared_names(RefNode::ModuleDeclarationAnsi(declaration), tree)?
.into_iter()
.collect::<HashSet<_>>();

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 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 👍 / 👎.

Comment on lines +713 to +715
.filter(|(_, port)| {
!references_deferred(RefNode::AnsiPortDeclaration(port), tree, &deferred)
})

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 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 👍 / 👎.

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

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-18 02:55 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue — 2026-10-18 03:10 UTC · at 39b29ddb0069d6a480a9015c064574559d224888

This pull request spent 15 minutes 4 seconds in the queue, with no time running CI.

Reason

The pull request #1474 has been manually updated

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

@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6 branch from 39b29dd to c2f4f29 Compare October 18, 2026 03:09
tignear added a commit that referenced this pull request Oct 18, 2026
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
@mergify mergify Bot removed the queued Mergify queue entry label Oct 18, 2026

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

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 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
@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6 branch from c2f4f29 to f3b6a24 Compare October 18, 2026 09:30
@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503 branch from 2f93125 to 224fe1f Compare October 18, 2026 09:30
@tignear

tignear commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • depends-on = celox-sim/celox#1468 [⛓️ refactor(sv)!: lower interfaces from original syntax #1468]
  • 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 added the queued Mergify queue entry label Oct 18, 2026
Base automatically changed from stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503 to master October 18, 2026 10:59
@mergify
mergify Bot merged commit 6b30fe4 into master Oct 18, 2026
36 of 57 checks passed
@mergify
mergify Bot deleted the stack/tignear/refactor/sv-native-bindings/preserve-interface-bindings-declaration-analysis--6ad012f6 branch October 18, 2026 11:22
@mergify mergify Bot removed the queued Mergify queue entry label Oct 18, 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.

1 participant