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/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", diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index 878285ce836..77e3c065724 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-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"))] 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)); +} 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/); +});