Repository navigation
feat(sv): support generate-block imports of types and subroutines that differ from the module's - #1440
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99a00bde18
ℹ️ 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, target) in self.bindings() { | ||
| if let Some(r#type) = aliases.get(target) { | ||
| visible.to_mut().insert(name.clone(), r#type.clone()); | ||
| } |
There was a problem hiding this comment.
Remove type aliases hidden by non-type imports
When a module sees a typedef such as q::T but a generate block imports a value or subroutine p::T, this loop leaves the module's T entry untouched because p::T is absent from the alias table. The block import still owns that name, so declarations such as T n must not resolve to the outer typedef; retaining it can silently give the declaration the wrong type instead of rejecting the non-type name. Remove the simple-name alias whenever an effective block import targets a non-type declaration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 80ea43a: when a block import binds a name to something that is not a type, BlockImports::type_aliases now removes the module's type alias of that name, so a block declaration T n; can no longer take the outer typedef. With a module typedef q::T and a block import of localparam int T from p, T n; in the block is rejected, and assign a = T; there still reads p::T. Both are covered in generate_block_imports_bind_their_own_types.
| let rebound: Vec<_> = self | ||
| .bindings() | ||
| .filter(|(_, target)| installed.contains(target)) | ||
| .collect(); | ||
| if rebound.is_empty() { | ||
| return None; |
There was a problem hiding this comment.
Hide outer constant functions for every effective import
If a module has a constant function f and a generate block imports a same-named declaration that is not in the installed constant-function table—most notably a DPI function, or a function whose table has only a global conversion error—this filter drops the binding entirely and the early return leaves the module's f installed. A block-local parameter or width expression calling f can therefore execute the outer function and produce a wrong elaborated value instead of binding to or rejecting the imported declaration. The outer binding must be hidden even when the target cannot be installed as a constant function.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 80ea43a: install_constant_functions now also covers block imports whose target is not in the constant-function table, as long as the name hides an outer constant function. That outer function is renamed away and nothing is installed under the name. A block localparam int Y = f(1); with a DPI-C p::f is now rejected ("user constant function call") instead of running the module's f, whether the module declares f or imports q::f. For a target with only a module-wide conversion error, a call of the hidden name reports that error. Covered by generate_block_dpi_imports_hide_outer_constant_functions in sv_dpi.rs.
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. |
99a00bd to
80ea43a
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80ea43a5f3
ℹ️ 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".
| // The declarations and nested blocks are elaborated with the types and | ||
| // constant functions those imports bind. | ||
| let _constant_functions = scope.block_imports().install_constant_functions(); | ||
| let aliases = scope.block_imports().type_aliases(self.module_aliases); |
There was a problem hiding this comment.
Clear inherited overrides when an inner import restores the module binding
When a module imports q::t, an outer generate block imports p::t, and a nested block imports q::t again, resolve_imports omits the nested binding because it matches the module-level target. The nested Scope is cloned from its parent, however, so this lookup still sees the inherited p::t entry and declarations such as t n use the outer block's type (for example, 4 bits instead of 8). Applying a nested import that returns to the module binding must remove the inherited override rather than leaving it active.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in cd8ca9c. The bug was in resolve_imports: it skipped an inner block's import whenever that import matched the module's binding. It now records the import when an enclosing block imports another declaration or declares the name, so the inner block no longer inherits the outer override. This was already wrong for plain values since #1184 (an inner import q::* under an outer import p::* read p::X), and also when an outer block declared localparam X and an inner block did import q::X. nested_generate_block_imports_restore_the_module_binding covers values, types, constant and runtime calls, an alternating p/q/p chain, and the outer-declaration case. All five cases fail without the fix.
|
Queued — the merge queue status continues in this comment ↓. |
cd8ca9c to
ac7255d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac7255d9ee
ℹ️ 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".
| fn bindings(self) -> impl Iterator<Item = (&'s String, &'s String)> { | ||
| self.imports | ||
| .iter() | ||
| .filter(move |(name, target)| self.names.get(*name) == Some(*target)) |
There was a problem hiding this comment.
Remove type aliases hidden by local declarations
When a generate-local value declaration hides an inherited imported type, this filter drops the import from bindings() but leaves the module's simple-name type alias visible. For example, if the module imports q::T, an outer generate block imports and uses p::T, a child declares localparam T, and a grandchild declares T n, the newly accepted design lowers n as q::T; the local parameter should instead hide both outer type bindings, making T n invalid. Preserve the declaration's shadowing information so type_aliases removes T rather than falling back to the module alias.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b78b0f5. BlockImports::type_aliases now uses the generate scope's shadowed set: any name the enclosing blocks declare or import hides the module's type alias of that name, and imported types are then re-added under their name. With the import chain you describe, a child localparam T makes a grandchild's T n; invalid, and it is now rejected. The same was true without any import: a module typedef T was never hidden by a generate-local localparam T or logic T, so that case is fixed too. The lookup walks the smaller of the alias table and the shadowed set. Covered by generate_block_declarations_hide_outer_types, which fails without the fix.
…t differ from the module's Closes #1206. A generate block that imports a type or subroutine under a name the module binds to another declaration was rejected, because types, constant functions and subroutine metadata were looked up module-wide by the plain name. This gives the generate scope its own view of those tables instead. - `Scope` and `Item` record the names the block's imports bind (`imports`, filled by `bind_import`). `BlockImports` keeps the ones an inner declaration has not hidden again, and derives from them: - the type aliases the block sees: a name the blocks declare or import hides the module's type of that name, and an imported `t` denotes `p::t`'s type; - the installed constant-function table, with `f` aliased to `p::f`, or hidden when the block's `f` is no constant function (a DPI-C import). Calls in the bodies of the functions it hides are renamed to the outer binding, so a module function still calls the `f` it was declared with. - The elaborator evaluates a block's declarations, conditions and nested blocks with that view, and resolves a generate condition's call to the qualified declaration ahead of a module function of the same name. - `Item::dimensions` carries the block's type aliases (casts, `$bits(t)`), next to the function, formal-name and shape aliases it already had. The signal, process, instance, function and subroutine collectors use the item's type aliases and install its constant functions. - The two "imports as another declaration than its module" rejections are removed. - `resolve_imports` also records a block import of the declaration the module sees when a block around it imports another declaration or declares the name, so the inner block no longer inherits the outer binding. This was already wrong for values since #1184. - As a result, a generate-local declaration such as `localparam T` now also hides a module typedef `T`, so `T n;` under it is rejected instead of taking the outer type (IEEE 1800-2023 23.9). Validation: - `cargo fmt --all -- --check` - `cargo clippy -p celox-sv-analyzer -p celox-frontend-sv -p celox --all-targets --features celox/systemverilog,celox/sv-dpi --no-deps` - `cargo test -p celox-sv-analyzer -p celox-frontend-sv` - `cargo test -p celox --features systemverilog,sv-dpi` (11465 passed, 0 failed) New regressions: `generate_block_imports_bind_their_own_subroutines`, `generate_block_imports_bind_their_own_types`, `nested_generate_block_imports_restore_the_module_binding` and `generate_block_declarations_hide_outer_types` in `sv_packages.rs`, and `generate_block_imports_bind_their_own_dpi_formals` and `generate_block_dpi_imports_hide_outer_constant_functions` in `sv_dpi.rs`. Every case also uses the name outside the block, so the block-local binding is taken rather than the module-wide alias for names only blocks use. Unrelated defects found while testing are filed as #1435, #1436, #1437, #1438 and #1461. Change-Id: Ic706ae8c0a61ae10d0a6e8afa53fc99b83d759d2
ac7255d to
b78b0f5
Compare
Merge Queue Status
This pull request spent 52 minutes 12 seconds in the queue, including 49 minutes 18 seconds running CI. Required conditions to merge
|
Closes #1206.
A generate block that imports a type or subroutine under a name the module
binds to another declaration was rejected, because types, constant functions
and subroutine metadata were looked up module-wide by the plain name. This
gives the generate scope its own view of those tables instead.
ScopeandItemrecord the names the block's imports bind(
imports, filled bybind_import).BlockImportskeeps the ones aninner declaration has not hidden again, and derives from them:
hides the module's type of that name, and an imported
tdenotesp::t's type;faliased top::f,or hidden when the block's
fis no constant function (a DPI-Cimport). Calls in the bodies of the functions it hides are renamed
to the outer binding, so a module function still calls the
fitwas declared with.
blocks with that view, and resolves a generate condition's call to the
qualified declaration ahead of a module function of the same name.
Item::dimensionscarries the block's type aliases (casts,$bits(t)),next to the function, formal-name and shape aliases it already had.
The signal, process, instance, function and subroutine collectors use
the item's type aliases and install its constant functions.
removed.
resolve_importsalso records a block import of the declaration themodule sees when a block around it imports another declaration or
declares the name, so the inner block no longer inherits the outer
binding. This was already wrong for values since fix(sv): scope imports in generate blocks to their block #1184.
localparam Tnowalso hides a module typedef
T, soT n;under it is rejected insteadof taking the outer type (IEEE 1800-2023 23.9).
Validation:
cargo fmt --all -- --checkcargo clippy -p celox-sv-analyzer -p celox-frontend-sv -p celox --all-targets --features celox/systemverilog,celox/sv-dpi --no-depscargo test -p celox-sv-analyzer -p celox-frontend-svcargo test -p celox --features systemverilog,sv-dpi(11465 passed, 0 failed)New regressions:
generate_block_imports_bind_their_own_subroutines,generate_block_imports_bind_their_own_types,nested_generate_block_imports_restore_the_module_bindingandgenerate_block_declarations_hide_outer_typesinsv_packages.rs, andgenerate_block_imports_bind_their_own_dpi_formalsandgenerate_block_dpi_imports_hide_outer_constant_functionsinsv_dpi.rs.Every case also uses the name outside the block, so the block-local binding
is taken rather than the module-wide alias for names only blocks use.
Unrelated defects found while testing are filed as #1435, #1436, #1437,
#1438 and #1461.