Repository navigation
fix(sv)!: keep Veryl module identity across mixed hierarchy links #1488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,14 +49,15 @@ pub fn parse_ir_with_external_hierarchy<'a>( | |
|
|
||
| /// Link the explicitly identified Veryl exports without matching SV namesakes. | ||
| /// `native_modules` maps each external module name that stands for a Veryl | ||
| /// body to the name of that body in `ir`. | ||
| /// body to the index of that body in `ir.components`, so bodies that share a | ||
| /// source name stay distinct. | ||
| pub fn parse_ir_with_external_hierarchy_and_native_modules<'a>( | ||
| ir: &'a veryl_analyzer::ir::Ir, | ||
| loop_provenance: &LoopProvenance, | ||
| external: &'a ExternalHierarchy, | ||
| config: &BuildConfig, | ||
| top: &StrId, | ||
| native_modules: &HashMap<String, StrId>, | ||
| native_modules: &HashMap<String, usize>, | ||
| ) -> Result<VerylSymbolicRtl<'a>, ParserError> { | ||
| parse_external_hierarchy( | ||
| ir, | ||
|
|
@@ -74,7 +75,7 @@ fn parse_external_hierarchy<'a>( | |
| external: &'a ExternalHierarchy, | ||
| config: &BuildConfig, | ||
| top: &StrId, | ||
| native_modules: Option<&HashMap<String, StrId>>, | ||
| native_modules: Option<&HashMap<String, usize>>, | ||
| ) -> Result<VerylSymbolicRtl<'a>, ParserError> { | ||
| // Token-to-scope resolution uses process-global analyzer state and is not | ||
| // safe while independent compilations run on other test threads. Snapshot | ||
|
|
@@ -174,17 +175,25 @@ fn parse_external_hierarchy<'a>( | |
| binding.package = external_ids[&binding.package]; | ||
| } | ||
| module_names.insert(global_id, external_module.sim_module.name.clone()); | ||
| let native_name = match native_modules { | ||
| Some(names) => names.get(&external_module.sim_module.name).copied(), | ||
| None => Some(resource_table::insert_str(&external_module.sim_module.name)), | ||
| let native_module = match native_modules { | ||
| Some(names) => names | ||
| .get(&external_module.sim_module.name) | ||
| .and_then(|&index| match &ir.components[index] { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a caller of this public API supplies an out-of-range or stale component index, this direct indexing panics instead of returning a Useful? React with 👍 / 👎. |
||
| Component::Module(module) => Some(module), | ||
| _ => None, | ||
| }), | ||
| None => name_to_ir | ||
| .get(&resource_table::insert_str( | ||
| &external_module.sim_module.name, | ||
| )) | ||
| .copied(), | ||
| }; | ||
| if let Some(native_name) = native_name | ||
| && let Some(&native_module) = name_to_ir.get(&native_name) | ||
| if let Some(native_module) = native_module | ||
| && !module_ir.contains_key(&global_id) | ||
| { | ||
| module_names.insert( | ||
| global_id, | ||
| resource_table::get_str_value(native_name).unwrap_or_default(), | ||
| resource_table::get_str_value(native_module.name).unwrap_or_default(), | ||
| ); | ||
| module_ir.insert(global_id, native_module); | ||
| signature_to_id.insert(native_module.signature.clone(), global_id); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # This file is automatically @generated by Veryl. | ||
| # It is not intended for manual editing. | ||
| version = 1 | ||
|
|
||
| [[projects]] | ||
| name = "lib" | ||
| source = "lib" | ||
| dependencies = [] | ||
|
|
||
| [projects.properties] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [project] | ||
| name = "app" | ||
| version = "0.1.0" | ||
|
|
||
| [build] | ||
| sources = ["src"] | ||
|
|
||
| [dependencies] | ||
| lib = { path = "lib" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [project] | ||
| name = "lib" | ||
| version = "0.1.0" | ||
|
|
||
| [build] | ||
| sources = ["src"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module Child #( | ||
| param K: u32 = 0, | ||
| ) ( | ||
| a: input logic<8>, | ||
| y: output logic<8>, | ||
| ) { | ||
| assign y = a + 8'd2 + K; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module Child #( | ||
| param K: u32 = 0, | ||
| ) ( | ||
| a: input logic<8>, | ||
| y: output logic<8>, | ||
| ) { | ||
| assign y = a + 8'd1 + K; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module Top( | ||
| input logic [7:0] a, | ||
| output logic [7:0] app_y, lib_y, app_wide, lib_wide | ||
| ); | ||
| app_Child app_child(.a(a), .y(app_y)); | ||
| lib_Child lib_child(.a(a), .y(lib_y)); | ||
| app_Child #(.K(16)) app_specialized(.a(a), .y(app_wide)); | ||
| lib_Child #(.K(32)) lib_specialized(.a(a), .y(lib_wide)); | ||
| endmodule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a large mixed hierarchy where exported Veryl modules share descendants—or form a chain
M0 -> M1 -> ... -> Mn—each iteration ofexternal_signatures_namedrecursively walks the whole subtree again, whileseendeduplicates only SV names. A chain therefore performs quadratic native-module visits, and repeated fan-out can be worse, before lowering begins; memoize the SV-descendant set by native module identity/signature instead of recursively recomputing it for every exported root.Useful? React with 👍 / 👎.