From ef1e83e58216c37088041471a19348e56976dcd5 Mon Sep 17 00:00:00 2001 From: tignear Date: Sun, 25 Oct 2026 01:16:41 +0900 Subject: [PATCH] fix(sv): accept undriven nets with high impedance defaults A legal undriven internal net was rejected during AST conversion or after parameter specialization. Accept it and use the existing high-impedance initialization, as required by IEEE 1800-2023 6.6 and 6.7.1. Keep overlapping-driver checks, and remove private expression walkers used only by the obsolete rejection. Replace rejection expectations with shared behavior checks for internal nets, all unpacked array elements, child input connections, generate-disabled drivers, and conversion to bit values. Validation on master bd4fb45555 with the lower two stack members: - Full SV suite: 4,518 pass, 20 existing ignored; all 10 new regression variants pass across five Celox backends. - Analyzer/frontend unit tests and doctests pass. - Affected analyzer/frontend clippy checks (-D warnings), formatting and diff checks pass. - Reviewed all 2,054 official sv-tests CI verdicts: only the pragma probe improves in both state modes. Update those two expectations and document the undriven-net cause. The local pinned probe also passes elaboration in both modes. External evidence for the unchanged cases: both portable cases pass Icarus, including internal nets and all unpacked array elements as Z. Verilator passes the two-state conversion case; its adapter does not run the raw four-state case. Before the fix, both new case sources fail with the former undriven-net rejection. In the upstream check on base 48f908e110, two original Taxi FIFO configurations advance to interface_array_query diagnostic policy; no simulation success is claimed for those configurations. Latest integration verification on master d9e44c9221: - Full SV suite: 4,659 pass, 20 existing ignored; false-loop suite: 25 pass. - Rust retained-report checks: three pass; report-reader/gate script tests: nine pass. - The changed retained-report Rust test passes clippy (-D warnings); formatting and diff checks pass. - Conflict resolution preserves master's tagged-union failure checks alongside all three packed-parameter failures, and retains both conformance review notes. Change-Id: I34535db18212ea20dc2c4b917524f22d6444e765 --- conformance/sv-tests/README.md | 8 +++ conformance/sv-tests/expected.tsv | 4 +- crates/celox-frontend-sv/src/lowering.rs | 14 ++--- crates/celox-sv-analyzer/src/ast.rs | 33 +----------- .../src/ast/bound_patterns/ports.rs | 22 -------- crates/celox-sv-analyzer/src/ast/instances.rs | 22 -------- .../src/source_tree/tests/net_ownership.rs | 14 +++-- .../celox-test-suite/src/sv/cases/types.vtest | 52 +++++++++++++++++++ .../systemverilog/review_regressions.rs | 49 +---------------- .../tests/frontends/systemverilog/types.rs | 9 ++++ 10 files changed, 86 insertions(+), 141 deletions(-) diff --git a/conformance/sv-tests/README.md b/conformance/sv-tests/README.md index 54eb8ebdb3e..24dc1a681cb 100644 --- a/conformance/sv-tests/README.md +++ b/conformance/sv-tests/README.md @@ -206,6 +206,14 @@ the assertion. The [reviewed full CI run](https://github.com/celox-sim/celox/act contains 2054 case/mode verdicts; these are the only two changed rows, and all verdicts match the updated expectations. +Accepting undriven nets updates both rows for +`5.6.4--compiler-directives-pragma` from fail to pass. Its `protected_wire` +has no driver and now elaborates with the standard net default (IEEE 1800-2023 +6.6 and 6.7.1). The official runner selects elaboration for this probe; runtime +high-impedance values are checked by the shared undriven-net simulation cases. +The [reviewed CI run](https://github.com/celox-sim/celox/actions/runs/40112270471) +changes only these two verdicts across 2,054 mode runs. + The report contains each case’s state mode, verdict, selected execution mode, tags, tool return code and path to the official log. The output directory retains both the official log and runner diagnostics for each case and state mode. diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index 5d3d4d4fb63..00331ded775 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1039,8 +1039,8 @@ chapter-5/5.6.4--compiler-directives-define.sv 2state pass chapter-5/5.6.4--compiler-directives-define.sv 4state pass chapter-5/5.6.4--compiler-directives-include.sv 2state pass chapter-5/5.6.4--compiler-directives-include.sv 4state pass -chapter-5/5.6.4--compiler-directives-pragma.sv 2state fail -chapter-5/5.6.4--compiler-directives-pragma.sv 4state fail +chapter-5/5.6.4--compiler-directives-pragma.sv 2state pass +chapter-5/5.6.4--compiler-directives-pragma.sv 4state pass chapter-5/5.6.4--compiler-directives-preprocessor-macro_0.sv 2state skip chapter-5/5.6.4--compiler-directives-preprocessor-macro_0.sv 4state skip chapter-5/5.6.4--compiler-directives-preprocessor-macro_1.sv 2state pass diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index 8cf8c077ad4..0f1a39aa4e3 100644 --- a/crates/celox-frontend-sv/src/lowering.rs +++ b/crates/celox-frontend-sv/src/lowering.rs @@ -592,19 +592,19 @@ fn validate_specialized_instance_net_drivers( .signals() .iter() .filter(|signal| signal.is_net()) - .map(|signal| (signal.name(), true)) + .map(|signal| signal.name()) .chain( module .source .ports() .iter() .filter(|port| port.is_net()) - .map(|port| (port.name(), false)), + .map(|port| port.name()), ); - for (signal_name, require_driver) in net_names { + for signal_name in net_names { let child_driver_ranges = child_output_driver_ranges(module, signal_name, module_ids, modules); - validate_net_driver_ranges(module, signal_name, &child_driver_ranges, require_driver)?; + validate_net_driver_ranges(module, signal_name, &child_driver_ranges)?; } let variable_names = module @@ -768,7 +768,6 @@ fn validate_net_driver_ranges( module: &LoweredSvModule, signal_name: &str, child_driver_ranges: &[(usize, Option<(i128, i128)>)], - require_driver: bool, ) -> Result<(), sv::AnalyzerError> { let local_drivers = local_driver_ranges( &module.source, @@ -803,11 +802,6 @@ fn validate_net_driver_ranges( "multiple net drivers for `{signal_name}`" ))); } - if require_driver && child_driver_ranges.is_empty() && local_drivers.is_empty() { - return Err(sv::AnalyzerError::Unsupported(format!( - "undriven net declaration `{signal_name}`" - ))); - } Ok(()) } diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index a9c0f9536f7..4819968a3fd 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -188,7 +188,7 @@ use ff_process::ff_processes_from_scope; use functions::{functions_from_scope, procedural_truth_condition}; use inlining::{expand_expr_calls, expr_signedness_with_return_types, substitute_expr_idents}; pub(crate) use instances::normalize_identifier; -use instances::{collect_connected_nets, expr_ident_name, instances_from_scope}; +use instances::{expr_ident_name, instances_from_scope}; use parameters::{ apply_parameter_overrides, coerce_const_parameter_value, const_env_from_parameters, const_expr_from_i128, const_expr_to_expr, enum_member_constants_from_scope, @@ -1266,37 +1266,6 @@ impl Module { }, ); } - let procedurally_written = procedural::written_names( - comb_processes - .iter() - .flat_map(|process| process.body.iter()) - .chain(ff_processes.iter().flat_map(|process| process.body.iter())), - ); - let mut connected_nets = HashSet::default(); - for connection in instances - .iter() - .flat_map(|instance| instance.port_connections()) - { - if let Some(expr) = connection.actual_expr() { - collect_connected_nets(expr, &mut connected_nets); - } - if let Some(pattern) = connection.bound_pattern() { - pattern.visit_expressions(&mut |expr| { - collect_connected_nets(expr, &mut connected_nets) - }); - } - } - if let Some(signal) = signals.iter().find(|signal| { - !imported.declarations_only - && signal.is_net() - && !procedurally_written.contains(signal.name()) - && !connected_nets.contains(signal.name()) - }) { - return Err(AnalyzerError::Unsupported(format!( - "undriven net declaration `{}`", - signal.name() - ))); - } // A call of a name an import binds calls the package subroutine or // DPI import. Calls of subroutines declared in a generate block were // already bound to those. diff --git a/crates/celox-sv-analyzer/src/ast/bound_patterns/ports.rs b/crates/celox-sv-analyzer/src/ast/bound_patterns/ports.rs index c9eaace4b74..ba3e838e836 100644 --- a/crates/celox-sv-analyzer/src/ast/bound_patterns/ports.rs +++ b/crates/celox-sv-analyzer/src/ast/bound_patterns/ports.rs @@ -99,28 +99,6 @@ impl BoundPattern { Ok(()) } - pub(in crate::ast) fn visit_expressions<'a>(&'a self, visit: &mut impl FnMut(&'a Expr)) { - fn value<'a>(value: &'a Value, visit: &mut impl FnMut(&'a Expr)) { - match value { - Value::Pattern(pattern) => pattern.visit_expressions(visit), - Value::Expression { expr, .. } => visit(expr), - } - } - match &self.items { - Items::Value(expr) | Items::ArrayValue { value: expr, .. } => visit(expr), - Items::List(items) | Items::Repeat(_, items) => { - for item in items { - value(item, visit); - } - } - Items::Keyed(items) => { - for (_, item) in items { - value(item, visit); - } - } - } - } - pub(in crate::ast) fn map_expressions(&mut self, map: &mut impl FnMut(Expr) -> Expr) { fn value(value: &mut Value, map: &mut impl FnMut(Expr) -> Expr) { match value { diff --git a/crates/celox-sv-analyzer/src/ast/instances.rs b/crates/celox-sv-analyzer/src/ast/instances.rs index f1442ad9380..5588b3c612c 100644 --- a/crates/celox-sv-analyzer/src/ast/instances.rs +++ b/crates/celox-sv-analyzer/src/ast/instances.rs @@ -298,28 +298,6 @@ pub(super) fn instance_ranges( constant_binding::unpacked_ranges(&native.dimensions, tree, env, aliases) } -// Child port directions are resolved by the frontend adapter. Defer its net -// driver check for selected/concatenated connections as well as whole nets. -pub(super) fn collect_connected_nets<'a>(expr: &'a Expr, names: &mut HashSet<&'a str>) { - match expr { - Expr::Ident(actual) => { - names.insert(actual); - } - Expr::Select { expr, .. } - | Expr::Resize { expr, .. } - | Expr::Unary { - op: UnaryOp::ToTwoState, - expr, - } => collect_connected_nets(expr, names), - Expr::Concat(parts) => { - for part in parts { - collect_connected_nets(part, names); - } - } - _ => {} - } -} - pub(super) fn expr_ident_name(expr: &Expr) -> Option { match expr { Expr::Ident(name) => Some(name.clone()), diff --git a/crates/celox-sv-analyzer/src/source_tree/tests/net_ownership.rs b/crates/celox-sv-analyzer/src/source_tree/tests/net_ownership.rs index 8588a5106c1..b0439686a29 100644 --- a/crates/celox-sv-analyzer/src/source_tree/tests/net_ownership.rs +++ b/crates/celox-sv-analyzer/src/source_tree/tests/net_ownership.rs @@ -116,14 +116,18 @@ fn native_net_declarators_and_initializers_are_authoritative() { assert!(source.modules()[0].signals().is_empty()); assert_eq!(source.modules()[0].assignments().len(), 1); } else if matches!(defect, "name" | "initializer") { - let error = Source::from_syntax(&tree).unwrap_err(); + let source = Source::from_syntax(&tree).unwrap(); + let module = &source.modules()[0]; let undriven = if defect == "name" { "other" } else { "b" }; assert!( - error - .to_string() - .contains(&format!("undriven net declaration `{undriven}`")), - "{error}" + module + .signals() + .iter() + .any(|signal| signal.name() == undriven) ); + assert!(!module.assignments().iter().any(|assignment| { + matches!(assignment.lhs_value(), LValue::Ident(name) if name == undriven) + })); } else { let source = Source::from_syntax(&tree).unwrap(); let module = &source.modules()[0]; diff --git a/crates/celox-test-suite/src/sv/cases/types.vtest b/crates/celox-test-suite/src/sv/cases/types.vtest index ebeb518f33f..abdd5e37810 100644 --- a/crates/celox-test-suite/src/sv/cases/types.vtest +++ b/crates/celox-test-suite/src/sv/cases/types.vtest @@ -408,3 +408,55 @@ (top Top) (eval) (assert_eq matched 1)) + +(case undriven_internal_nets_are_high_impedance + (four_state) + (source "undriven_internal.sv" #" + module Driver(output wire y); + assign y=1'b1; + endmodule + module Sink(input wire a, output wire y); + assign y=a; + endmodule + module Parent #(parameter ENABLE=1)(output wire y); + wire w; + if (ENABLE) Driver driver(.y(w)); + Sink sink(.a(w),.y(y)); + endmodule + module Top(output wire [7:0] floating, + output wire [11:0] array_values, + output wire enabled,disabled, + output bit [3:0] two_state); + wire unused; + wire [7:0] w; + wire [3:0] words[3]; + assign floating=w; + assign array_values={words[2],words[1],words[0]}; + assign two_state=w[3:0]; + Parent #(.ENABLE(1)) a(enabled); + Parent #(.ENABLE(0)) b(disabled); + endmodule + "#) + (top Top) (eval) + (assert_eq floating (fourstate 0 0xff)) + (assert_eq array_values (fourstate 0 0xfff)) + (assert_eq enabled 1) + (assert_eq disabled (fourstate 0 1)) + (assert_eq two_state 0)) + +(case undriven_internal_nets_convert_to_two_state_zero + (source "undriven_two_state.sv" #" + module Sink(input bit [7:0] a, output wire [7:0] y); + assign y=a; + endmodule + module Top(output bit [7:0] y, output bit [11:0] array_values); + wire unused; + wire [7:0] w; + wire [3:0] words[3]; + Sink sink(w,y); + assign array_values={words[2],words[1],words[0]}; + endmodule + "#) + (top Top) (eval) + (assert_eq y 0) + (assert_eq array_values 0)) diff --git a/crates/celox/tests/frontends/systemverilog/review_regressions.rs b/crates/celox/tests/frontends/systemverilog/review_regressions.rs index 0b5bcf1427b..7c6b4f10ca6 100644 --- a/crates/celox/tests/frontends/systemverilog/review_regressions.rs +++ b/crates/celox/tests/frontends/systemverilog/review_regressions.rs @@ -946,29 +946,6 @@ fn coerces_ir_parameter_constants_to_their_declared_widths() { assert_eq!(sim.get(sim.signal("y")), 1u8.into()); } -#[test] -fn validates_net_drivers_after_parameter_specialization() { - let error = cranelift_build_error( - r#" - module Driver(output logic y); assign y = 1'b1; endmodule - module Sink(input logic a); endmodule - module Child #(parameter ENABLE = 1) (output logic y); - wire w; - if (ENABLE) Driver driver(.y(w)); - Sink sink(.a(w)); - assign y = 1'b0; - endmodule - module Top(output logic y); - Child #(.ENABLE(0)) child(.y(y)); - endmodule - "#, - ); - assert!( - error.contains("undriven net declaration `w`"), - "unexpected error: {error}" - ); -} - #[test] fn applies_unsigned_coercion_to_mixed_signed_constant_comparisons() { let source = r#" @@ -984,23 +961,6 @@ fn applies_unsigned_coercion_to_mixed_signed_constant_comparisons() { assert_eq!(sim.get(sim.signal("y")), 0u8.into()); } -#[test] -fn does_not_count_child_inputs_as_net_drivers() { - let error = cranelift_build_error( - r#" - module Sink(input logic a, output logic y); assign y = a; endmodule - module Top(output logic y); - wire w; - Sink sink(.a(w), .y(y)); - endmodule - "#, - ); - assert!( - error.contains("undriven net declaration `w`"), - "unexpected error: {error}" - ); -} - #[test] fn rejects_top_level_localparam_overrides() { let source = r#" @@ -1412,8 +1372,7 @@ fn rejects_runtime_selected_child_outputs_to_nets() { "#, ); assert!( - error.contains("undriven net declaration `values`") - || error.contains("systemverilog output port lvalue connection"), + error.contains("systemverilog output port lvalue connection"), "unexpected error: {error}" ); } @@ -5630,12 +5589,6 @@ fn rejects_constructs_that_are_not_yet_lowered() { module Top(input logic a, b, output logic y); and (y, a, b); endmodule "#, ), - ( - "undriven net declaration `w`", - r#" - module Top(output logic y); wire w; assign y = (w === 1'bz); endmodule - "#, - ), ( "unknown or duplicate systemverilog child port connection", r#" diff --git a/crates/celox/tests/frontends/systemverilog/types.rs b/crates/celox/tests/frontends/systemverilog/types.rs index c9aa52725b6..c13f8dbd4dc 100644 --- a/crates/celox/tests/frontends/systemverilog/types.rs +++ b/crates/celox/tests/frontends/systemverilog/types.rs @@ -64,3 +64,12 @@ sv_backends! { @case "types::preserves_integer_atom_state_kinds"; } } + +sv_backends! { + fn undriven_internal_nets_are_high_impedance(sim) { + @case "types::undriven_internal_nets_are_high_impedance"; + } + fn undriven_internal_nets_convert_to_two_state_zero(sim) { + @case "types::undriven_internal_nets_convert_to_two_state_zero"; + } +}