Skip to content

refactor(sv)!: lower interfaces from original syntax - #1468

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503
Oct 18, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503

Conversation

@tignear

@tignear tignear commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Interface instances, modport views and generic bindings now resolve through semantic scopes over the original syntax tree. Remove generated probe modules, interface source replacement, timescale call replacement and source blanking in the external verification adapter.

Preserve per-instance parameters, process and function bindings, generate scopes, timescales and initialized array members. Bind interface array ports in declaration order across differing bounds and forwarded connections, and reject shape mismatches. Inspect declarations through an explicit analyzer mode so timed bodies need no text edits.

Validation: analyzer/frontend units; full SV backend suite; DPI, unpacked-array and mixed frontend tests; formatting and clippy. New array-port and initialization regressions agree with Verilator. Icarus passes array initialization and rejects interface port syntax; the latter is recorded under its existing interface limitation. Both external tools pass the timed declaration-inspection case.

BREAKING CHANGE: Remove the elaborate_interfaces source-rewriting APIs. InterfacePrototype exposes its analyzed module instead of generated probe source.

@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:11.869797Z 224fe1f 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

if let Some(prefix) = interface_prefix {
name.push('.');
name.push_str(prefix);

P2 Badge Escape percent signs in interface instance prefixes

When an interface containing $printtimescale is instantiated with a legal escaped identifier containing a format sequence, such as I \info%b ();, the instance prefix is copied into the generated $display template without passing through literal_name. The resulting %b is interpreted as another display conversion with no argument, corrupting the message or producing a runtime formatting error. Escape percent signs in interface_prefix just as this function already does for absolute names and relative paths.

ℹ️ 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 +603 to +607
for name in module
.ports
.iter()
.map(|port| &port.name)
.chain(module.signals.iter().map(|signal| &signal.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 Reject collisions with interface subroutine names

When a module legally declares h$f while interface instance h defines method f, interface binding also renames that method to h$f. This check examines only ports and signals, so analysis succeeds; Module::from_scope_node_with_parameter_overrides inserts the module's local function before imported functions (ast.rs:908-913), causing h.f() to call the module's h$f instead of the interface method. Include bound functions/subroutines and other renamed interface symbols in the collision check, or generate collision-free internal names, to prevent silent incorrect simulation.

Useful? React with 👍 / 👎.

Comment on lines +249 to +253
// Resolve the caller's declarations before evaluating instance overrides.
let header = declaration_view(&view);
let mut header_imports = imported.clone();
header_imports.declarations_only = true;
let caller = Module::from_scope_node_with_parameter_overrides(

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 Bind local interfaces before analyzing dependent declarations

When an ordinary declaration depends on an earlier local interface instance, such as Cfg cfg(); logic [cfg.N-1:0] data;, this declaration-only pass runs before the pending interface instantiations populate imported.interface_members. Consequently cfg.N cannot be resolved and the valid module is rejected before the later loop gets a chance to bind cfg. Bind top-level interface instance constants before analyzing caller declarations, while still collecting the module-local constants needed by interface overrides.

Useful? React with 👍 / 👎.

Comment on lines +207 to 208
let path = variable_path(node, select, syntax_tree, dimensions)?;
let (_, ty) = selected_member(&path, dimensions)?;

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 Bind interface prefixes in structure dimension queries

For an interface member that is a packed structure, a query such as $dimensions(i.payload.field) produces the path i.payload.field, but this helper calls selected_member before applying the interface-prefix binding that variable_member and net_member use. The dimensions table contains the flattened i$payload, not i, and the exact interface-member map contains only i.payload, so nested fields cannot be recovered and valid dimension queries fail. Apply bind_interface_path in both dimension helpers before looking up the selected member.

Useful? React with 👍 / 👎.

Comment on lines 45 to +49
let design = Design::collect(&files)?;
let mut declarations = design.interfaces.values().collect::<Vec<_>>();
let mut declarations = design
.interfaces
.values()
.filter(|interface| selected.is_none_or(|names| names.contains(&interface.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 Filter unrequested interfaces before collecting semantics

interface_prototypes_for performs Design::collect before applying selected, so unsupported constructs in an unrequested interface still abort contract generation. In particular, the mixed-language builder can pass an empty or narrow reference set yet fail because an unrelated SV interface has an unsupported type parameter, ANSI port, enum, or nested declaration; this defeats the new selective API and its stated behavior of analyzing only requested declarations. Restrict semantic collection to selected interfaces, or return early when the selected set is empty.

Useful? React with 👍 / 👎.

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 (366 passed, 4 existing ignores), complete
SystemVerilog suite (2584 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.
All four review findings are addressed. Internal name collisions produce an
explicit diagnostic.

Change-Id: I6ad012f664d5e6f9dadc0ed7001dccf5247eae8b
@tignear
tignear force-pushed the stack/tignear/refactor/sv-native-bindings/bind-assignment-patterns-without-rewriting-source--6d1a9211 branch from c39aa09 to b4519bc 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 efe55f4 2026-10-18 02:10 UTC
2 content efe55f4 → 2f93125 Fix CI: replace obsolete interface rejection assertions with lifetime and defining-unit behavior checks; register the reviewed interface-array exclusion. 2026-10-18 02:10 UTC
3 content 2f93125 → 224fe1f 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: 2f93125f8a

ℹ️ 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 child_alias = if generic.is_empty() {
child_name.clone()
} else {
clone_module_name(&child_name, &generic)

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 Reject collisions in generated generic module names

When a legal authored module G$I coexists with generic module G(interface p) instantiated using interface I, this generates the same G$I name. The result.modules.contains_key check then skips whichever declaration is processed second, while child bindings still target G$I, so the frontend can silently lower the authored module instead of the specialization (with the winner depending on hash-map queue order). Generate collision-free aliases or reject these collisions.

Useful? React with 👍 / 👎.

imported.declarations_only = declarations_only;
let name = module_name_from_node(node.clone(), tree)?;
let _timescales = timescales::install_for_tree(packages.timescales.clone(), tree)?;
Module::from_scope_node_with_parameter_overrides(

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 Defer undriven-net checks until interfaces are bound

When an interface net is driven only by its consumer, such as interface I; wire x; endinterface with a parent assign i.x = a or a child output connected through a modport, this call analyzes I as a standalone module before the parent assignments and connections are merged. The module-level undriven-net validation therefore rejects the valid interface even though the final bound parent would see the driver; suppress that validation for exported interface scopes or perform it after binding.

Useful? React with 👍 / 👎.

};
let mut modules = Vec::new();
for node in index.nodes(syntax_tree, module_name) {
let interface_plan = packages.interface_plan.modules.get(module_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 Build interface plans for the module-only numeric API

For analyze_source_module_with_parameter_overrides on a module with an interface port, the Packages value created by from_syntax_module_with_parameter_overrides never receives a native interface plan, so this lookup returns None. The analyzer consequently does not remove or bind the interface port and ordinary port lowering rejects the module, while the expression-override and whole-source entry points work because they use ParsedSource::analyze_packages; route the numeric module-only API through the same setup.

Useful? React with 👍 / 👎.

Comment on lines +111 to +115
if !packages.interface_sources.is_empty()
&& trees.iter().any(|(tree, _)| {
tree.into_iter()
.any(|node| matches!(node, sv_parser::RefNode::InterfacePortHeader(_)))
})

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 Validate shared names even without interface ports

When a source declares both interface I and module I but uses interfaces only as local instances, there is no InterfacePortHeader, so this guard skips plan_interfaces. The preceding insertion detects only duplicate interfaces, while the shared module/interface namespace check lives in Design::collect; analysis can therefore publish module I yet flatten I i() as the interface instead of rejecting the duplicate. Run the namespace validation whenever interface declarations exist.

Useful? React with 👍 / 👎.

Comment on lines +386 to +390
let connections = instances::port_connections_from_hierarchical_instance(
instance,
tree,
&dimensions,
Some(&interface),

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 Distribute interface-array port connections by element

For an interface instance array such as I i[1:0](.clk(clks)), where clk is scalar and clks has one bit per instance, SystemVerilog distributes the actual across the array elements. This call lowers the unchanged hierarchical instance inside every element iteration, so both flattened ports are assigned the complete clks expression and typically receive the same truncated bit. Select the ordinal-specific slice when lowering each interface-array element's connections.

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:30 UTC · at 2f93125f8a8aeffdf61e435252381b79189d0783

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

Reason

The pull request conflicts with the base branch

The pull request was held in the queue, conflicting with at least one of 4 pull requests ahead of it. The conflict became a base branch one after #1459, #1467, #1471 merged.

Automatic conflict resolution can merge a conflict like this one instead of stopping on it, but only in a queue using the merge-batch or fast-forward merge method.

Hint

You should update or rebase your pull request.

If you want to requeue this pull request, you can post a @mergifyio queue comment.

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

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
Base automatically changed from stack/tignear/refactor/sv-native-bindings/bind-assignment-patterns-without-rewriting-source--6d1a9211 to master October 18, 2026 03:30
@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 18, 2026
Interface instances, modport views and generic bindings now resolve through semantic scopes over the original syntax tree. Remove generated probe modules, interface source replacement, timescale call replacement and source blanking in the external verification adapter.

Preserve per-instance parameters, process and function bindings, generate scopes, timescales and initialized array members. Bind interface array ports in declaration order across differing bounds and forwarded connections, and reject shape mismatches. Inspect declarations through an explicit analyzer mode so timed bodies need no text edits.

Validation: analyzer/frontend units; full SV backend suite; DPI, unpacked-array and mixed frontend tests; formatting and clippy. New array-port and initialization regressions agree with Verilator. Icarus passes array initialization and rejects interface port syntax; the latter is recorded under its existing interface limitation. Both external tools pass the timed declaration-inspection case.

BREAKING CHANGE: Remove the elaborate_interfaces source-rewriting APIs. InterfacePrototype exposes its analyzed module instead of generated probe source.

Change-Id: I95623503dff2b19c4acd10e87298a0d92e60c077
tignear added a commit that referenced this pull request Oct 18, 2026
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/lower-interfaces-original-syntax--95623503 branch from 2f93125 to 224fe1f Compare October 18, 2026 09:30
@tignear tignear removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 18, 2026
@mergify

mergify Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 41 minutes 37 seconds in the queue, including 36 minutes 45 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 merged commit 6dbf34b into master Oct 18, 2026
30 checks passed
@mergify
mergify Bot deleted the stack/tignear/refactor/sv-native-bindings/lower-interfaces-original-syntax--95623503 branch October 18, 2026 10:59
@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