Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5944,11 +5944,6 @@ impl Ff<'_, '_> {
self.urandom_state();
}
let mut kernel = ProcessKernelBuilder::new(slots);
if self.forked && self.has_deferred_assertions(body, &mut HashSet::default()) {
return Err(unsupported(
"deferred assertions in a process with fork-join",
));
}
if let Some(site) = self.deferred_flush_site(body) {
kernel.flush_deferred_at(site);
}
Expand Down
12 changes: 10 additions & 2 deletions crates/celox-runtime/src/simulation/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl<B: SimBackend> SimulationState<B> {

/// Follow ancestry through completed parents too (IEEE 1800-2023 9.6.3).
/// Remove scheduler entries before releasing IDs for reuse.
pub(super) fn disable_children(&mut self, process: usize) {
pub(super) fn disable_children(&mut self, process: usize) -> Vec<usize> {
if self.process_state.activations.is_empty() {
return;
return Vec::new();
}
let mut cancelled = vec![false; self.process_state.activations.len()];
let mut pending = vec![process];
Expand All @@ -231,6 +231,13 @@ impl<B: SimBackend> SimulationState<B> {
}
}
}
let live_cancelled = cancelled
.iter()
.enumerate()
.filter_map(|(id, &cancelled)| {
(cancelled && self.process_state.activations[id].live).then_some(id)
})
.collect();
let state = &mut self.process_state;
for (id, activation) in state.activations.iter_mut().enumerate() {
activation.pending.retain(|&child| !cancelled[child]);
Expand All @@ -252,6 +259,7 @@ impl<B: SimBackend> SimulationState<B> {
self.retire_activation(id);
}
}
live_cancelled
}

pub(super) fn end_activation(&mut self, process: usize) {
Expand Down
15 changes: 15 additions & 0 deletions crates/celox-runtime/src/simulation/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub trait UnitExecutor {
Ok(self.backend_mut().run_process(index)?)
}

/// Attribute deferred assertion records to this dynamic process execution.
fn enter_deferred_assertion_process(&mut self, _process: usize) {}
/// Consume this invocation's records before another execution context runs.
fn leave_deferred_assertion_process(&mut self) {}
/// A naturally completed process retains its pending assertion reports.
fn finish_deferred_assertion_process(&mut self, _process: usize) {}
/// Disabling a live process flushes its deferred assertion reports (16.4.4).
fn cancel_deferred_assertion_process(&mut self, _process: usize) {}

/// Prepare the declaration-only state before runtime static initializers.
fn reset_declaration_startup(&mut self) -> Result<(), Halt> {
Ok(())
Expand Down Expand Up @@ -138,6 +147,12 @@ pub trait HostBoundary: UnitExecutor {
Ok(())
}

/// Active-region work has drained. Mature Observed deferred assertions
/// before entering Reactive, so a later wakeup cannot flush them (16.4.1).
fn try_observed_deferred_assertions(&mut self, _timestamp: u64) -> Result<(), Halt> {
Ok(())
}

/// Called after [`Self::try_finish_timed_step`] when the time slot
/// `timestamp` is over: no more work is due at that time. A step ends
/// before its slot does when a process waits for zero time. The
Expand Down
21 changes: 18 additions & 3 deletions crates/celox-runtime/src/simulation/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ impl<B: SimBackend> SimulationState<B> {
E: SimulationExecutor<Backend = B>,
{
{
executor.run_process(kernel)?;
executor.enter_deferred_assertion_process(process);
let result = executor.run_process(kernel);
executor.leave_deferred_assertion_process();
result?;
let status: u8 = executor
.backend()
.get_as(self.model.processes[process].status);
Expand Down Expand Up @@ -177,12 +180,19 @@ impl<B: SimBackend> SimulationState<B> {
}
Some(ProcessStatus::Done) => {
self.end_activation(process);
executor.finish_deferred_assertion_process(process);
if self.model.processes[process].program.is_some() {
self.program_kernel_ended(executor.backend())?;
}
}
Some(ProcessStatus::Exit) => {
self.exit_program(executor.backend_mut(), process)?;
let program = self.model.processes[process].program;
for (index, candidate) in self.model.processes.iter().enumerate() {
if candidate.program == program {
executor.finish_deferred_assertion_process(index);
}
}
self.program_kernel_ended(executor.backend())?;
}
Some(ProcessStatus::Finish) => return Err(Halt::Finish),
Expand All @@ -198,7 +208,9 @@ impl<B: SimBackend> SimulationState<B> {
}
Some(ProcessStatus::WaitFork) => return Ok(self.wait_for_children(process)),
Some(ProcessStatus::DisableFork) => {
self.disable_children(process);
for child in self.disable_children(process) {
executor.cancel_deferred_assertion_process(child);
}
return Ok(true);
}
Some(ProcessStatus::Local) => {
Expand All @@ -222,7 +234,10 @@ impl<B: SimBackend> SimulationState<B> {
.filter(|site| site.kind == kind)
.nth(index as usize)
.ok_or(SimulatorErrorCode::InternalError)?;
executor.host_request(request, current_time)?;
executor.enter_deferred_assertion_process(process);
let result = executor.host_request(request, current_time);
executor.leave_deferred_assertion_process();
result?;
*returns += 1;
self.charge(*returns, Some(process))?;
return Ok(true);
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-runtime/src/simulation/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl<B: SimBackend> SimulationState<B> {
loop {
let ready = self.take_ready_processes(current_time);
if ready.is_empty() && self.process_state.ready.is_empty() {
executor.try_observed_deferred_assertions(current_time)?;
// The active region set is empty: the reactive region set
// runs, and the design activity it creates runs in the active
// region set again (IEEE 1800-2023 4.5).
Expand Down Expand Up @@ -241,6 +242,9 @@ impl<B: SimBackend> SimulationState<B> {
where
E: SimulationExecutor<Backend = B>,
{
// Compiled slots without Reactive work reach this boundary directly.
// In the ordinary loop the Observed queue is already empty here.
executor.try_observed_deferred_assertions(current_time)?;
executor.try_end_time_slot(current_time)
}

Expand Down
30 changes: 30 additions & 0 deletions crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,33 @@ not exclusions or passing assertions. Pinned xezim 0.11.3 passes all six;
Verilator 5.052 passes the five two-state cases and its adapter does not support
the four-state case. Reproduce with `verify-sv-icarus --filter
fork_control::function_join_none_`.

### Deferred assertions in fork processes

`fork_deferred::` checks the process-local report queues of IEEE 1800-2023
16.4.1, their event/wait flush points (16.4.2), and cancellation (16.4.4).
Natural completion retains queued reports; a zero-delay resumption does not
flush them. Observed reports mature before Reactive program activity and
cannot subsequently be flushed, while Final reports remain flushable until
Postponed. These cases remain executable with their original assertions.

The reviewed [xezim observations](verification/sv/xezim/fork_deferred.json)
include missing sibling/parent reports, a cancelled child report surviving,
and missing reports after `#0`. The [standalone zero-delay source](verification/repros/fork_deferred_zero_delay.sv)
and [observed output](verification/repros/fork_deferred_zero_delay.json)
reproduce the latter without the suite emitter. The
[Verilator observations](verification/sv/verilator/fork_deferred.json) retain
incorrect sibling reports and internal compiler faults as mismatches and
compile errors respectively. The [Icarus observations](verification/sv/icarus/fork_deferred.json)
retain its explicit unsupported-deferred-assertion diagnostics as compile
errors; disabling assertions would not validate these cases.

The daily gate matches these exact reviewed classifications and diagnostics;
none becomes an exclusion or a pass. Reproduce with `verify-sv-xezim`,
`verify-sv-verilator`, or `verify-sv-icarus` and `--filter fork_deferred::`.

For these nine cases, xezim 0.11.3 records 2 passes and 7 mismatches;
Verilator 5.052 records 2 passes, 3 mismatches, 3 compiler faults, and
1 unsupported four-state case; Icarus 13.0 records 9 compile errors.
In the Reactive-wakeup case, xezim loses the matured Observed report,
while Verilator also emits the Final report that the wait resumption must flush.
16 changes: 15 additions & 1 deletion crates/celox-test-suite/src/script/timed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) fn validate_timed_design_with_defines(design: &Design, names: &[&str]
}
// Final procedures run in an unspecified order relative to the
// checks after run_to_finish (IEEE 1800-2023 9.2.3).
if token.text == "final" {
if token.text == "final" && !matches!(previous, "assert" | "assume" | "cover") {
return Err("final procedures are not supported in timed shared cases".into());
}
}
Expand Down Expand Up @@ -110,6 +110,20 @@ mod tests {
let source = "module Top; initial $display(\"final\"); endmodule";
assert!(validate_timed_design(&design(source)).is_ok());
}
#[test]
fn final_deferred_assertions_are_not_final_procedures() {
for assertion in ["assert", "assume", "cover"] {
let source = format!(
"module Top; initial {assertion} /* trivia */ final (1) $display(\"ok\"); endmodule"
);
assert!(validate_timed_design(&design(&source)).is_ok(), "{source}");
let source = format!(
"module Top; initial {assertion} final (1); final $display(\"done\"); endmodule"
);
assert!(validate_timed_design(&design(&source)).is_err(), "{source}");
}
}

#[test]
fn source_order_controls_macro_hidden_scale_validation() {
for directive in [
Expand Down
138 changes: 138 additions & 0 deletions crates/celox-test-suite/src/sv/cases/fork_deferred.vtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
(group fork_deferred (category sequential))

; A wait resumption flushes one child's reports, never its sibling's.
(case sibling_wait_queues_are_independent
(source "siblings.sv" #"module Top;
bit go;
task automatic worker(input bit flush_this);
assert #0 (0) else $display("observed %0d", flush_this);
assert final (0) else $display("final %0d", flush_this);
if (flush_this) wait(go); else #1;
endtask
initial begin
go=0;
fork worker(0); worker(1); join_none
#0; go=1; #2;
end
endmodule"#)
(top Top) (run_until 2)
(expect_output "observed 0\nfinal 0\n"))

(case sibling_event_queues_are_independent
(source "siblings_event.sv" #"module Top;
bit go;
task automatic worker(input bit flush_this);
assert #0 (0) else $display("observed %0d", flush_this);
assert final (0) else $display("final %0d", flush_this);
if (flush_this) @(posedge go); else #1;
endtask
initial begin
go=0;
fork worker(0); worker(1); join_none
#0; go=1; #2;
end
endmodule"#)
(top Top) (run_until 2)
(expect_output "observed 0\nfinal 0\n"))

(case child_flush_does_not_inherit_parent_reports
(source "parent.sv" #"module Top;
bit go;
initial begin
go=0;
assert #0 (1) $display("parent observed");
assert final (1) $display("parent final");
fork begin wait(go); end join_none
#0; go=1;
end
endmodule"#)
(top Top) (run_until 1)
(expect_output "parent observed\nparent final\n"))

(case disable_fork_flushes_live_children_only
(source "cancel.sv" #"module Top;
initial begin
assert #0 (1) $display("parent");
fork
begin assert #0 (0) else $display("cancelled"); #5; end
begin assert final (1) $display("completed"); end
join_none
#0; disable fork;
end
endmodule"#)
(top Top) (run_until 1)
(expect_output "parent\ncompleted\n"))

(case reused_slot_cannot_flush_completed_reports
(source "reused.sv" #"module Top;
bit go;
initial begin
go=0;
fork begin assert #0 (1) $display("completed"); end join
fork begin wait(go); end join_none
#0; go=1; #1;
end
endmodule"#)
(top Top) (run_until 1)
(expect_output "completed\n"))

(case zero_delay_is_not_a_flush_point
(source "delay.sv" #"module Top;
initial fork
begin
assert #0 (1) $display("observed");
assert final (1) $display("final");
#0;
end
join
endmodule"#)
(top Top) (run_until 1)
(expect_output "observed\nfinal\n"))

(case repeated_static_site_keeps_completed_reports
(source "repeated.sv" #"module Top(input int count);
initial begin
wait(count > 0);
for (int i=0; i<count; i++) begin
fork
automatic int copy=i;
begin assert #0 (1) $display("copy %0d", copy); end
join
end
end
endmodule"#)
(top Top) (run_until 0) (modify (set count 3)) (run_until 1)
(expect_output "copy 0\ncopy 1\ncopy 2\n"))

(case four_state_arguments_are_captured_before_child_exit
(four_state)
(source "captured.sv" #"module Top;
initial fork
begin
automatic logic [3:0] value=4'b10xz;
assert #0 (1) $display("observed %b", value);
assert final (1) $display("final %b", value);
#0; value=0;
end
join
endmodule"#)
(top Top) (run_until 1)
(expect_output "observed 10xz\nfinal 10xz\n"))

; Observed reports mature before Reactive program code can wake the child.
; The same wakeup still flushes its not-yet-matured Final report.
(case reactive_wakeup_preserves_mature_observed_only
(source "reactive.sv" #"module Top;
bit go;
Driver driver(go);
initial fork begin
assert #0 (1) $display("observed");
assert final (1) $display("final");
wait(go);
end join
endmodule
program Driver(output bit go);
initial begin go=1; #10; end
endprogram"#)
(top Top) (run_until 1)
(expect_output "observed\n"))
4 changes: 4 additions & 0 deletions crates/celox-test-suite/src/sv/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub(super) const GROUPS: &[Group] = &[
file: "src/sv/cases/containers.vtest",
text: include_str!("containers.vtest"),
},
Group {
file: "src/sv/cases/fork_deferred.vtest",
text: include_str!("fork_deferred.vtest"),
},
Group {
file: "src/sv/cases/fork_control.vtest",
text: include_str!("fork_control.vtest"),
Expand Down
Loading
Loading