Repository navigation
refactor(sv)!: lower interfaces from original syntax - #1468
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
celox/crates/celox-sv-analyzer/src/ast/timescales.rs
Lines 38 to 40 in efe55f4
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".
| for name in module | ||
| .ports | ||
| .iter() | ||
| .map(|port| &port.name) | ||
| .chain(module.signals.iter().map(|signal| &signal.name)) |
There was a problem hiding this comment.
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 👍 / 👎.
| // 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( |
There was a problem hiding this comment.
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 👍 / 👎.
| let path = variable_path(node, select, syntax_tree, dimensions)?; | ||
| let (_, ty) = selected_member(&path, dimensions)?; |
There was a problem hiding this comment.
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 👍 / 👎.
| 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))) |
There was a problem hiding this comment.
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 👍 / 👎.
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
c39aa09 to
b4519bc
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: 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) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 👍 / 👎.
| if !packages.interface_sources.is_empty() | ||
| && trees.iter().any(|(tree, _)| { | ||
| tree.into_iter() | ||
| .any(|node| matches!(node, sv_parser::RefNode::InterfacePortHeader(_))) | ||
| }) |
There was a problem hiding this comment.
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 👍 / 👎.
| let connections = instances::port_connections_from_hierarchical_instance( | ||
| instance, | ||
| tree, | ||
| &dimensions, | ||
| Some(&interface), |
There was a problem hiding this comment.
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 👍 / 👎.
Merge Queue Status
This pull request spent 35 minutes 27 seconds in the queue, with no time running CI. ReasonThe 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 HintYou should update or rebase your pull request. If you want to requeue this pull request, you can post a Requeued — the merge queue status continues in this comment ↓. |
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
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
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
2f93125 to
224fe1f
Compare
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
|
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.