From 7acd965896fca9ffe62fe95206309f53b6737090 Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 02:53:34 +0900 Subject: [PATCH 1/4] fix(sv): bound recursive specialization along instance paths The global limit of 64 specializations per module rejected finite designs with many independently parameterized siblings, including the HTG9200 statistics collectors. Track the instantiation parent of newly discovered specializations and apply the existing budget to repeated module names along that chain instead. Allow 65 independent sibling specializations in pure SystemVerilog and mixed Veryl/SystemVerilog hierarchies. Parameter-changing recursion remains bounded and identical-specialization cycles retain the existing hierarchy checks. This does not resolve the remaining full-board compilation performance problem. Validation: 5,685 SystemVerilog tests passed (20 existing skips), 7 frontend unit tests passed, affected frontend/Celox clippy with warnings denied, formatting and diff checks. The new shared sibling case passed Icarus and Verilator; the existing recursive elaboration regression also passed. Change-Id: I3c2330c0973e79f5ff44f5f5e646147a65d14cc6 --- crates/celox-frontend-sv/src/lowering.rs | 48 +++++++++++-------- .../src/sv/cases/hierarchy.vtest | 22 +++++++++ .../frontends/systemverilog/hierarchy.rs | 6 +++ .../systemverilog/review_regressions.rs | 24 ++++++++++ 4 files changed, 80 insertions(+), 20 deletions(-) diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index 44a6c3b9b11..39a4d605af5 100644 --- a/crates/celox-frontend-sv/src/lowering.rs +++ b/crates/celox-frontend-sv/src/lowering.rs @@ -46,7 +46,7 @@ mod procedural; type RegionedVarAddr = RegionedVarAddrBase; type GlueBlock = GlueBlockBase; -const MAX_SV_SPECIALIZATIONS_PER_MODULE: usize = 64; +const MAX_SV_RECURSIVE_SPECIALIZATIONS: usize = 64; /// The name of a module's [`SimModule::time_slot`]. const TIME_SLOT: &str = "$time"; @@ -2268,7 +2268,7 @@ fn prepare_external_hierarchy_collecting( names.sort(); let mut module_ids = HashMap::default(); - let mut module_specialization_counts = HashMap::default(); + let mut specialization_parents = HashMap::default(); let mut queue = Vec::new(); let mut requested_roots = HashMap::default(); for name in names { @@ -2309,7 +2309,6 @@ fn prepare_external_hierarchy_collecting( } let module_id = ModuleId(module_ids.len()); module_ids.insert(key.clone(), module_id); - module_specialization_counts.insert(name.clone(), 1usize); queue.push(key); } @@ -2374,7 +2373,6 @@ fn prepare_external_hierarchy_collecting( if !module_ids.contains_key(&dependency) { let id = ModuleId(module_ids.len()); module_ids.insert(dependency.clone(), id); - module_specialization_counts.insert(name.clone(), 1); queue.push(dependency); } } @@ -2400,13 +2398,7 @@ fn prepare_external_hierarchy_collecting( continue; } if !module_ids.contains_key(&child_key) { - let specialization_count = module_specialization_counts - .entry(child_key.name.clone()) - .or_insert(0); - if *specialization_count >= MAX_SV_SPECIALIZATIONS_PER_MODULE { - return Err(sv_specialization_limit_error(child_key.name.clone()).into()); - } - *specialization_count += 1; + register_specialization_parent(&child_key, &key, &mut specialization_parents)?; let child_id = ModuleId(module_ids.len()); module_ids.insert(child_key.clone(), child_id); queue.push(child_key); @@ -2885,8 +2877,7 @@ fn schedule_sources_collecting( let root_id = ModuleId(0); let mut module_ids = HashMap::default(); module_ids.insert(root_key.clone(), root_id); - let mut module_specialization_counts = HashMap::default(); - module_specialization_counts.insert(root_key.name.clone(), 1usize); + let mut specialization_parents = HashMap::default(); let mut queue = vec![root_key.clone()]; let mut index = 0; let mut elaborated = HashMap::default(); @@ -2923,13 +2914,7 @@ fn schedule_sources_collecting( return Err(unsupported_sv_instance(child_key.name.clone()).into()); } if !module_ids.contains_key(&child_key) { - let specialization_count = module_specialization_counts - .entry(child_key.name.clone()) - .or_insert(0); - if *specialization_count >= MAX_SV_SPECIALIZATIONS_PER_MODULE { - return Err(sv_specialization_limit_error(child_key.name.clone()).into()); - } - *specialization_count += 1; + register_specialization_parent(&child_key, &key, &mut specialization_parents)?; let child_id = ModuleId(module_ids.len()); module_ids.insert(child_key.clone(), child_id); queue.push(child_key); @@ -3210,6 +3195,29 @@ fn restore_interface_member_paths(module: &mut SimModule, source: &AnalyzedSvMod } } +/// Bound parameter-changing recursion along one instantiation path. Independent +/// siblings may have any number of distinct parameter specializations. Repeated +/// identical keys are handled by the hierarchy cycle checks. +fn register_specialization_parent( + child: &LoweredSvModuleKey, + parent: &LoweredSvModuleKey, + parents: &mut HashMap, +) -> Result<(), ParserError> { + let mut ancestor = Some(parent); + let mut occurrences = 1usize; + while let Some(key) = ancestor { + if key.name == child.name { + occurrences += 1; + if occurrences > MAX_SV_RECURSIVE_SPECIALIZATIONS { + return Err(sv_specialization_limit_error(child.name.clone())); + } + } + ancestor = parents.get(key); + } + parents.insert(child.clone(), parent.clone()); + Ok(()) +} + fn sv_specialization_limit_error(name: String) -> ParserError { ParserError::unsupported( sv::SV_FRONTEND_TRACKING_ISSUE, diff --git a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest index d9a8121de40..891856da116 100644 --- a/crates/celox-test-suite/src/sv/cases/hierarchy.vtest +++ b/crates/celox-test-suite/src/sv/cases/hierarchy.vtest @@ -1738,3 +1738,25 @@ (assert_eq y (fourstate 0x55 0xa0)) (modify (set d 0x96)) (assert_eq y 0x96)) + +(case many_sibling_parameter_specializations + (source "sibling_specializations.sv" #" + module Leaf #(parameter ID=0)(input wire [7:0] x, output wire [7:0] q); + assign q=x ^ 8'(ID); + endmodule + module Top(input wire [7:0] x, output wire [7:0] first, last); + wire [7:0] lanes[65]; + for (genvar n=0; n<65; n=n+1) begin : siblings + Leaf #(.ID(n)) u(.x(x), .q(lanes[n])); + end + assign first=lanes[0]; + assign last=lanes[64]; + endmodule + "#) + (top Top) + (modify (set x 60)) + (assert_eq first 60) + (assert_eq last 124) + (modify (set x 255)) + (assert_eq first 255) + (assert_eq last 191)) diff --git a/crates/celox/tests/frontends/systemverilog/hierarchy.rs b/crates/celox/tests/frontends/systemverilog/hierarchy.rs index 1e0a3cd893c..8c893ac3d94 100644 --- a/crates/celox/tests/frontends/systemverilog/hierarchy.rs +++ b/crates/celox/tests/frontends/systemverilog/hierarchy.rs @@ -776,3 +776,9 @@ fn rejects_malformed_non_ansi_port_declarations() { assert!(error.contains(message), "{source}: {error}"); } } + +sv_backends! { + fn many_sibling_parameter_specializations(sim) { + @case "hierarchy::many_sibling_parameter_specializations"; + } +} diff --git a/crates/celox/tests/frontends/systemverilog/review_regressions.rs b/crates/celox/tests/frontends/systemverilog/review_regressions.rs index e5985594160..5c9d4afab27 100644 --- a/crates/celox/tests/frontends/systemverilog/review_regressions.rs +++ b/crates/celox/tests/frontends/systemverilog/review_regressions.rs @@ -8989,3 +8989,27 @@ fn single_bit_array_driver_windows_still_reject_overlaps() { assert!(error.contains("multiple variable drivers"), "{error}"); } } + +#[test] +fn mixed_hierarchies_accept_many_sibling_specializations() { + let veryl = "module Top(x: input logic<8>, y: output logic<8>) { inst tree: $sv::Root(x, y); }"; + let sv = "module Leaf #(parameter ID=0)(input wire [7:0] x, output wire [7:0] y); + assign y=x ^ 8'(ID); endmodule + module Root(input wire [7:0] x, output wire [7:0] y); + wire [7:0] lanes[65]; + for(genvar n=0;n<65;n=n+1) begin: g + Leaf #(.ID(n)) u(.x(x),.y(lanes[n])); + end + assign y=lanes[64]; endmodule"; + let mut sim = Simulator::from_mixed_sources( + vec![(veryl, Path::new("top.veryl"))], + vec![(sv, Path::new("siblings.sv"))], + "Top", + ) + .build_cranelift() + .unwrap(); + let x = sim.signal("x"); + let y = sim.signal("y"); + sim.modify(|io| io.set(x, 60u8)).unwrap(); + assert_eq!(sim.get(y), BigUint::from(124u8)); +} From eecd74700ff7b4aa66aa3cdb08deff4f35292454 Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 02:56:44 +0900 Subject: [PATCH 2/4] perf(vpi): compile process-capable images without retrying VPI builds first compiled an untimed Simulator image and, after detecting a process, repeated frontend analysis and SIR optimization with Simulation. Compile the process-capable Simulation native image directly for both process-free and process-containing SystemVerilog DUTs. Keep the configured optimization level, diagnostics, parameter overrides and signal access settings. This removes the complete Simulator-to-Simulation retry without disabling optimization. Large VCU108 and HTG9200 native compilations remain a performance issue; this change does not claim that all Taxi configurations or runtime tests pass. Validation: 166 normal celox-vpi tests passed, all eight explicitly selected cocotb tests passed, affected VPI clippy with warnings denied, formatting and diff checks. Cocotb coverage includes a process-free flip-flop, DUT processes, edge/NBA ordering, force/release, unpacked arrays, finish and femtosecond clocks. Change-Id: I6439f16cd7cc0f3b26019b6c8bccb526b7fb1302 --- crates/celox-vpi/src/bin/celox.rs | 37 +++++++++---------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/crates/celox-vpi/src/bin/celox.rs b/crates/celox-vpi/src/bin/celox.rs index 225e09851ca..e5829c56bd8 100644 --- a/crates/celox-vpi/src/bin/celox.rs +++ b/crates/celox-vpi/src/bin/celox.rs @@ -839,35 +839,18 @@ fn compile_native_design(design: &Design) -> Result .iter() .map(|(text, path)| (text.as_str(), path.as_path())) .collect(); - let untimed = configure_sv( + // VPI advances time and dispatches callbacks even for a process-free + // DUT. Compile its process-capable image directly, rather than first + // compiling an untimed image and repeating analysis and optimization + // when that builder discovers a process. + let simulation = configure_sv( design, - celox::Simulator::from_sv_sources(refs.clone(), &design.top), + celox::Simulation::from_sv_sources(refs, &design.top), ) - .compile_native(); - let image = match untimed { - Ok(simulator) => { - report_warnings(simulator.warnings())?; - simulator.into_program_image() - } - // A design with processes runs as a timed simulation, in step - // with the VPI time callbacks. - Err(error) - if matches!( - error.kind(), - celox::SimulatorErrorKind::ProcessRequiresSimulation(_) - ) => - { - let simulation = configure_sv( - design, - celox::Simulation::from_sv_sources(refs, &design.top), - ) - .compile_native() - .map_err(|error| format!("compilation failed:\n{error}"))?; - report_warnings(simulation.warnings())?; - simulation.into_program_image() - } - Err(error) => return Err(format!("compilation failed:\n{error}")), - }; + .compile_native() + .map_err(|error| format!("compilation failed:\n{error}"))?; + report_warnings(simulation.warnings())?; + let image = simulation.into_program_image(); return Ok(image); } #[cfg(not(feature = "systemverilog"))] From b79fb2822bf4780ca67776148560b5672e6449cf Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 03:53:28 +0900 Subject: [PATCH 3/4] chore(deps): update zstd-sys to fix the wasm allocator advisory Update only zstd-sys from 2.0.16+zstd.1.5.7 to 2.1.2+zstd.1.5.7. This removes RUSTSEC-2026-0410 from the workspace dependency audit, covering the upstream wasm allocator fix without adding vendor patches or advisory exclusions. This is a partial remediation: cargo-deny still reports RUSTSEC-2026-0391, RUSTSEC-2026-0398, and RUSTSEC-2026-0403 for zstd 0.13.3 and zstd-safe 7.2.4. The latest include-flate-compress 0.3.4 and wasmtime-internal-cache 50.0.0 still require zstd ^0.13, preventing resolution to fixed zstd 0.14.3 / zstd-safe 8.2.0. Keep this PR in draft while those upstream constraints remain; the advisory gate is unchanged. No downstream minimum version is imposed by a workspace lockfile update. Security-only Cargo update automation is handled independently in #2199 so it can land without this remaining advisory failure. Validation: celox-backend-wasm library tests (7 passed); include-flate-compress compiled against the updated chain; workspace/all-target cargo check with the CI feature configuration, including native/Cranelift/Wasmtime and external-suite adapters (excluding the disabled lydite-celox bridge); cargo-deny bans/licenses/sources passed; advisories reduced from 4 to the 3 documented above. Advisory/version verification was used instead of an allocator-exhaustion exploit reproduction. Change-Id: I510c5d926178a7c3441caaf5f40740cab1c584da --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a33a7e74520..2ff45141965 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5664,9 +5664,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.16+zstd.1.5.7" +version = "2.1.2+zstd.1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +checksum = "481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3" dependencies = [ "cc", "pkg-config", From acfcf7594b184a3f88ed5b5f53a8a10f17311ac2 Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 05:18:48 +0900 Subject: [PATCH 4/4] ci(mergify): add queue priority without interrupting checks Add merge-priority for requests that should pass waiting ordinary PRs while allowing running checks to finish. Assign priority 9000 with interruption disabled, below merge-urgent's 10000 and above lightweight changes. The first matching rule makes merge-urgent win when both labels are present. Both labels use the same guarded merge-ready authorization, preserving required checks, holds, conflicts, drafts, and the dequeue latch. Document their distinct behavior and withdrawal procedure. The merge-priority repository label has been created; its queue behavior activates after this configuration is merged. Validation: mergify config validate; 38 Mergify and CI-classifier tests passed; git diff --check. No PR was queued or merged for validation. Change-Id: Ib8ed2198d9309dc9f530a37264d5418a8092c40d --- .mergify.yml | 12 ++++++++++-- CONTRIBUTING.md | 27 ++++++++++++++++----------- scripts/mergify.test.mjs | 18 ++++++++++++++++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/.mergify.yml b/.mergify.yml index 17116d77903..10d2798f7ee 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -55,6 +55,12 @@ priority_rules: priority: 10000 allow_checks_interruption: true + - name: Priority merges without interruption + conditions: + - label = merge-priority + priority: 9000 + allow_checks_interruption: false + - name: Lightweight validated changes first conditions: - check-success = Lint & Format @@ -160,7 +166,7 @@ queue_rules: # rulesets. Keep those rules enforced by GitHub; Mergify gets no bypass. pull_request_rules: - - name: Authorize emergency merge requests + - name: Authorize prioritized merge requests conditions: - or: - base ~= ^(master|develop)$ @@ -169,7 +175,9 @@ pull_request_rules: - and: - base ~= ^stack/ - 'body ~= (?m)^Depends-On: ' - - label = merge-urgent + - or: + - label = merge-urgent + - label = merge-priority - -label = release:hold - -label = dequeued - -draft diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f2133eecae7..def9181d534 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -435,20 +435,25 @@ regressions and manual scaling measurements are not made passing by blindly running every `#[ignore]` test. New exclusions need a concrete reason and evidence; an unexpected failure must not become a skip. -## Emergency merge priority +## Merge priority labels -Apply `merge-urgent` to request an emergency merge. Mergify adds `merge-ready` -and gives the PR priority 10000, ahead of the normal and lightweight priorities. -It may interrupt lower-priority queue checks to test the urgent PR first; use -this only when the urgency justifies restarting that work. Existing queue -categories and batching still apply, as do stack dependency ordering and all -required checks. This is priority, not permission to merge failing CI. +Both labels add `merge-ready` and request normal queue admission: + +| Label | Priority | Running lower-priority checks | +| --- | --- | --- | +| `merge-priority` | 9000 | Finish first; this PR goes ahead of waiting ordinary PRs | +| `merge-urgent` | 10000 | May be interrupted to test this PR first | + +Both outrank normal and lightweight priorities. If both labels are present, +`merge-urgent` wins. Reserve it for emergencies that justify restarting checks. +Existing queue categories, batching, stack dependency ordering, and all required +checks still apply. These labels do not permit merging failing CI. Drafts, conflicts, `release:hold`, and `dequeued` still block automatic admission. -After addressing a dequeue's cause, remove `dequeued` to retry. Removing -`merge-urgent` restores normal priority; remove `merge-ready` and explicitly +After addressing a dequeue's cause, remove `dequeued` to retry. Remove both +priority labels to restore normal priority; remove `merge-ready` and explicitly dequeue as usual to withdraw the merge request entirely. The generated `merge-ready` label also activates the existing release-PR freeze mechanism. -The label works after this configuration reaches the PR's base branch. Creating -or applying the label alone does not install the queue policy. +Each label's behavior works after its configuration reaches the PR's base +branch. Creating or applying a label alone does not install the queue policy. diff --git a/scripts/mergify.test.mjs b/scripts/mergify.test.mjs index a00fad46d1e..1c23ef340e9 100644 --- a/scripts/mergify.test.mjs +++ b/scripts/mergify.test.mjs @@ -198,14 +198,14 @@ test("lightweight queue priority requires actual skipped product checks and succ test("emergency labels authorize normal admission and outrank lightweight checks", () => { const priorities = queueConfig.split("priority_rules:\n")[1].split("queue_rules:\n")[0]; - const emergency = priorities.split(" - name: Lightweight validated changes first")[0]; + const emergency = priorities.split(" - name: Priority merges without interruption")[0]; assert.match(emergency, /name: Emergency merges first/); assert.match(emergency, /conditions:\n - label = merge-urgent/); assert.match(emergency, /priority: 10000/); assert.match(emergency, /allow_checks_interruption: true/); const admission = queueConfig.split("pull_request_rules:\n")[1]; const authorize = admission.split(" - name: Queue explicitly requested merges")[0]; - assert.match(authorize, /label = merge-urgent/); + assert.match(authorize, /- or:\n - label = merge-urgent\n - label = merge-priority/); assert.match(authorize, /actions:\n label:\n add:\n - merge-ready/); for (const guard of ["-label = release:hold", "-label = dequeued", "-draft", "-conflict"]) assert.ok(authorize.includes(` - ${guard}`), guard); @@ -214,3 +214,17 @@ test("emergency labels authorize normal admission and outrank lightweight checks assert.match(authorize, /Depends-On:/); assert.doesNotMatch(authorize, /queue:|merge:|remove:/); }); + + +test("priority requests pass waiting work without interrupting running checks", () => { + const rules = queueConfig.split("priority_rules:\n")[1].split("queue_rules:\n")[0] + .split(/^ - name: /m).slice(1); + assert.equal(rules.length, 3); + assert.match(rules[0], /^Emergency merges first/); + assert.match(rules[1], /^Priority merges without interruption/); + assert.match(rules[1], /conditions:\n - label = merge-priority/); + assert.match(rules[1], /priority: 9000/); + assert.match(rules[1], /allow_checks_interruption: false/); + assert.doesNotMatch(rules[1], /check-success|check-skipped/); + assert.match(rules[2], /^Lightweight validated changes first/); +});