From effa03ce80eff6ca3525ded1c1d25a032eaa85b2 Mon Sep 17 00:00:00 2001 From: tignear Date: Sat, 24 Oct 2026 11:44:48 +0900 Subject: [PATCH] perf(sv): skip scope discovery for literal query operands Preliminary typing of each literal array-pattern element rediscovered all visible declarations. Publishing intermediate dimension snapshots repeatedly copied and dropped unrelated expression trees, causing Taxi frontend runs to exceed their 120-second limit. Reuse the existing query-context projection for literals, including grouped literals, before scope types are complete. Literals do not require lexical name resolution; other operands retain the existing discovery path. Add an owning-crate regression comparing literal query results against forced discovery and asserting that the shortcut performs no declaration discovery. Validation: - Full SystemVerilog suite: 4,366 passed, 20 existing ignored, across all five backends. Analyzer: 796 passed, 3 existing ignored; frontend: 5 passed; doctests: 2 passed. - Clippy for affected crates/all targets with -D warnings, formatting, and diff checks passed. Shared cases and external adapters are unchanged. - Replayed the same 25 Taxi configurations using original RTL/parameters, release frontend binaries, two workers and 120-second limits. Timeouts decrease from 17 to zero; all 25 reach existing unpacked-parameter forwarding errors: 18 GT_TX_DIFFCTRL and 7 STAT_PREFIX_STR. Elapsed times are 2.142-21.296 seconds (median 10.245). These are frontend error results, not full FPGA-core or cocotb test passes. All 188 resolved SV sources match the earlier upstream hashes. - Synthetic source-to-scheduling probe with 256 declarations and 256 literal array elements: baseline completed samples take 38.929 and 42.647 seconds (a third times out at 60 seconds); patched samples take 0.038-0.042 seconds. Three repetitions alternate old/new order on a shared machine; these measurements do not establish a universal speedup or linear complexity. This change builds on real-valued parameter overrides from #1839. Remaining unpacked-array parameter forwarding errors are separate follow-up work. Change-Id: I00f31b062932d07ebdbe89b7fc3a7080e2aa2308 --- .../src/ast/dimensions/query_binding.rs | 11 +++- .../src/ast/dimensions/tests.rs | 56 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs b/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs index d3fe2977483..353055ff483 100644 --- a/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs @@ -26,7 +26,16 @@ pub(in crate::ast) fn query_context_for_operand( tree: &AnalysisContext<'_>, context: &PackedDimensions, ) -> Converted { - if context.scope_types_complete { + // Literals carry their type in their spelling and cannot reference lexical + // declarations. Pattern elements otherwise rediscover the whole scope for + // each literal while the surrounding declaration is still being bound. + let operand = expression_binding::ungroup(root, tree.declarations()); + if context.scope_types_complete + || matches!( + tree.declarations().expression(operand).kind, + ExprKind::Literal(_) + ) + { return Ok(query_context(context)); } Ok(query_context(&query_operand_dimensions_id( diff --git a/crates/celox-sv-analyzer/src/ast/dimensions/tests.rs b/crates/celox-sv-analyzer/src/ast/dimensions/tests.rs index 10c9d8a9e4f..f29dadcf3e5 100644 --- a/crates/celox-sv-analyzer/src/ast/dimensions/tests.rs +++ b/crates/celox-sv-analyzer/src/ast/dimensions/tests.rs @@ -517,3 +517,59 @@ fn recursive_generate_dimension_discovery_uses_explicit_specialization() { ); } } + +#[test] +fn preliminary_literal_queries_do_not_discover_scope_declarations() { + let tree = crate::source_tree::parse_scope_fixture( + r#"module Top; + logic [7:0] unrelated [0:31]; + localparam A = $bits(123); + localparam B = $bits((8'shff)); + localparam C = $bits(4'bx); + localparam D = $bits("ab"); + localparam E = $bits('1); + endmodule"#, + Path::new("literal_query.sv"), + ) + .unwrap(); + let tree = AnalysisContext::unspecialized(&tree); + let input = PackedDimensions::default(); + let calls = native_calls(&tree); + assert_eq!(calls.len(), 5); + // Keep the discovery path as an independent reference for the result. + let discovered = calls + .iter() + .map(|call| { + let celox_sv_syntax::ExprKind::Call { arguments, .. } = + &tree.declarations().expression(*call).kind + else { + unreachable!() + }; + let context = + query_operand_dimensions_id(arguments[0].value.unwrap(), &tree, &input).unwrap(); + query_number( + *call, + &tree, + &HashMap::default(), + &HashMap::default(), + Some(&context), + ) + }) + .collect::>(); + SYNTAX_TYPE_DISCOVERIES.with(|count| count.set(0)); + let direct = calls + .iter() + .map(|call| { + query_number( + *call, + &tree, + &HashMap::default(), + &HashMap::default(), + Some(&input), + ) + }) + .collect::>(); + assert_eq!(&direct[..4], &[Some(32), Some(8), Some(4), Some(16)]); + assert_eq!(direct, discovered); + assert_eq!(SYNTAX_TYPE_DISCOVERIES.with(|count| count.get()), 0); +}