diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e2eace94df0..9b1fde462a1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -175,16 +175,16 @@ jobs:
cargo doc --locked --no-deps "${args[@]}"
- uses: pnpm/action-setup@v6
- if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true'
+ if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true' || needs.changes.outputs.scripts == 'true'
- uses: actions/setup-node@v7
- if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true'
+ if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true' || needs.changes.outputs.scripts == 'true'
with:
node-version: 24
cache: pnpm
- name: Install dependencies
- if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true'
+ if: needs.changes.result != 'success' || needs.changes.outputs.javascript == 'true' || needs.changes.outputs.scripts == 'true'
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Biome check
diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml
index 39d0763b605..1ea1124d822 100644
--- a/.github/workflows/pr-title.yml
+++ b/.github/workflows/pr-title.yml
@@ -12,6 +12,11 @@ permissions:
jobs:
conventional-title:
name: Conventional Commit title
+ # Edits can arrive after closure. Do not allocate a runner for those events.
+ # Keep all open-PR edits: a skipped required check could mask a prior failure.
+ if: >-
+ github.event_name == 'merge_group' ||
+ github.event.pull_request.state == 'open'
runs-on: ubuntu-latest
steps:
- name: Check out the trusted title validator
diff --git a/crates/celox-design/src/lib.rs b/crates/celox-design/src/lib.rs
index f1b9fbe01c7..50e687c8a08 100644
--- a/crates/celox-design/src/lib.rs
+++ b/crates/celox-design/src/lib.rs
@@ -457,6 +457,9 @@ pub struct ProcessSlots {
pub is_initializer: bool,
/// This kernel originated from an edge procedure and must execute in Simulation.
pub requires_timed_simulation: bool,
+ /// Every delay the kernel suspends for is a constant of at least one
+ /// time unit.
+ pub const_delays: bool,
pub resume: A,
pub status: A,
pub delay: A,
@@ -467,6 +470,7 @@ impl ProcessSlots {
ProcessSlots {
is_initializer: self.is_initializer,
requires_timed_simulation: self.requires_timed_simulation,
+ const_delays: self.const_delays,
resume: map(self.resume),
status: map(self.status),
delay: map(self.delay),
diff --git a/crates/celox-frontend-core/src/process.rs b/crates/celox-frontend-core/src/process.rs
index a34363cb372..8f8c1373831 100644
--- a/crates/celox-frontend-core/src/process.rs
+++ b/crates/celox-frontend-core/src/process.rs
@@ -72,12 +72,21 @@ impl ProcessKernelBuilder {
let start = builder.current_block();
Self {
builder,
- slots,
+ slots: ProcessSlots {
+ const_delays: true,
+ ..slots
+ },
resume_blocks: vec![start],
wait_site: None,
}
}
+ /// The kernel's control slots, with [`ProcessSlots::const_delays`] set
+ /// for the delays lowered so far.
+ pub fn slots(&self) -> ProcessSlots {
+ self.slots
+ }
+
/// The SIR builder positioned where the process continues. After
/// [`Self::finish`] no block is open until the caller switches to one.
pub fn builder(&mut self) -> &mut SIRBuilder {
@@ -135,8 +144,15 @@ impl ProcessKernelBuilder {
/// Suspend for the number of time units in `amount`, an unsigned
/// two-state register of [`PROCESS_DELAY_WIDTH`] bits, and continue at
/// a new resume point. A zero delay resumes after the nonblocking
- /// assignments of the time are published.
- pub fn delay(&mut self, amount: RegisterId) -> Result<(), ProcessKernelError> {
+ /// assignments of the time are published. `constant` is the amount's
+ /// value when the frontend knows it, which it records in
+ /// [`ProcessSlots::const_delays`].
+ pub fn delay(
+ &mut self,
+ amount: RegisterId,
+ constant: Option,
+ ) -> Result<(), ProcessKernelError> {
+ self.note_delay(constant);
self.store(self.slots.delay, PROCESS_DELAY_WIDTH, amount);
self.suspend(ProcessStatus::Delay)
}
@@ -144,11 +160,20 @@ impl ProcessKernelBuilder {
/// A delay with the scheduling of IEEE 1800-2023: a zero delay resumes
/// in the inactive region of the same time (4.4.2.3), before
/// nonblocking assignments are published.
- pub fn inactive_delay(&mut self, amount: RegisterId) -> Result<(), ProcessKernelError> {
+ pub fn inactive_delay(
+ &mut self,
+ amount: RegisterId,
+ constant: Option,
+ ) -> Result<(), ProcessKernelError> {
+ self.note_delay(constant);
self.store(self.slots.delay, PROCESS_DELAY_WIDTH, amount);
self.suspend(ProcessStatus::InactiveDelay)
}
+ fn note_delay(&mut self, constant: Option) {
+ self.slots.const_delays &= constant.is_some_and(|amount| amount > 0);
+ }
+
/// Return to the runtime, which charges its time-slot budget and
/// resumes the process at once. Frontends place this in loops without
/// timing controls so that a runaway process is reported, not hung in.
diff --git a/crates/celox-frontend-core/src/sdk.rs b/crates/celox-frontend-core/src/sdk.rs
index 2a5196e29ef..f3da9a7af9f 100644
--- a/crates/celox-frontend-core/src/sdk.rs
+++ b/crates/celox-frontend-core/src/sdk.rs
@@ -481,6 +481,23 @@ fn coerce_sir_register(
Ok(current)
}
+/// The value of expression `id` as a delay amount, if it is a two-state
+/// constant whose coercion to [`PROCESS_DELAY_WIDTH`] bits keeps its value.
+fn constant_delay(artifact: &FrontendArtifact, id: ExprId) -> Option {
+ let expression = artifact.expression(id)?;
+ let ExprNode::Constant(value) = expression.node() else {
+ return None;
+ };
+ let value_type = expression.value_type();
+ let negative = value_type.is_signed()
+ && value_type.width() > 0
+ && value.payload().bit(value_type.width() as u64 - 1);
+ if value.mask().bits() != 0 || negative {
+ return None;
+ }
+ u64::try_from(value.payload()).ok()
+}
+
fn coerce_sir_expression(
artifact: &FrontendArtifact,
id: ExprId,
@@ -1319,6 +1336,7 @@ fn lower_statements(
return Ok(false);
}
Statement::Delay { amount } | Statement::InactiveDelay { amount } => {
+ let constant = constant_delay(artifact, *amount);
let amount = coerce_sir_expression(
artifact,
*amount,
@@ -1327,9 +1345,9 @@ fn lower_statements(
&mut cache,
)?;
if matches!(statement, Statement::Delay { .. }) {
- kernel.delay(amount)?;
+ kernel.delay(amount, constant)?;
} else {
- kernel.inactive_delay(amount)?;
+ kernel.inactive_delay(amount, constant)?;
}
}
Statement::WaitEvent { terms } => {
@@ -1713,6 +1731,7 @@ fn lower_processes(
let slots = ProcessSlots {
is_initializer: false,
requires_timed_simulation: false,
+ const_delays: false,
resume: lowering
.hidden
.declare(name("resume"), PROCESS_RESUME_WIDTH, false),
@@ -1728,6 +1747,7 @@ fn lower_processes(
lowering.process_nba_sites = 0;
let mut kernel = ProcessKernelBuilder::new(slots);
lower_statements(&mut lowering, &mut kernel, process.body())?;
+ let slots = kernel.slots();
let kernel = kernel.build();
candidates.extend(crate::watch::multi_store_candidates(&kernel, |address| {
stable_signal(address, artifact.signals().len())
diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs
index b27b2f92fac..a47776dccb1 100644
--- a/crates/celox-frontend-sv/src/lowering.rs
+++ b/crates/celox-frontend-sv/src/lowering.rs
@@ -4080,6 +4080,7 @@ fn lower_initial_processes(
ProcessSlots {
is_initializer: process.is_initializer(),
requires_timed_simulation: process.is_scheduled_edge(),
+ const_delays: false,
resume: declare("resume", PROCESS_RESUME_WIDTH),
status: declare("status", PROCESS_STATUS_WIDTH),
delay: declare("delay", PROCESS_DELAY_WIDTH),
@@ -4124,7 +4125,7 @@ fn lower_initial_processes(
}));
Ok(SymbolicProcess {
kernel: kernel.unit,
- slots,
+ slots: kernel.slots,
origin: process_origin(process),
})
})
diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs
index e0bdd559d5d..2fa115443d4 100644
--- a/crates/celox-frontend-sv/src/lowering/ff.rs
+++ b/crates/celox-frontend-sv/src/lowering/ff.rs
@@ -4285,10 +4285,12 @@ impl Ff<'_, '_> {
self.exec_block(body)?;
let mut kernel = self.kernel.take().expect("lowering a process kernel");
std::mem::swap(&mut self.b, kernel.builder());
+ let slots = kernel.slots();
let mut unit = kernel.build();
prune_unreachable_blocks(&mut unit);
Ok(KernelUnit {
unit,
+ slots,
wait_sites: self.wait_sites,
nba_sites: self.nba_sites,
host_request_sites: self.host_request_sites,
@@ -4431,6 +4433,9 @@ impl Ff<'_, '_> {
ticks_per_unit: u64,
ticks_per_precision: u64,
) -> Result<(), sv::AnalyzerError> {
+ // Only integral constants are recorded; a real delay counts as
+ // variable.
+ let mut constant = None;
let (mut delay, ticks_per_step) = match self.m.expr_float_precision(amount) {
Some(precision) => (
self.real_delay(amount, precision, ticks_per_unit / ticks_per_precision)?,
@@ -4438,6 +4443,13 @@ impl Ff<'_, '_> {
),
None => {
let signed = self.expr_signed(amount);
+ constant = self
+ .eval_const(amount)?
+ .filter(|(value, width)| {
+ !(signed && *width > 0 && value.bit(*width as u64 - 1))
+ })
+ .and_then(|(value, _)| u64::try_from(&value).ok())
+ .and_then(|value| value.checked_mul(ticks_per_unit));
let mut arena = SLTNodeArena::new();
let node = self.expr_slt(amount, None, &mut arena)?;
let original = self.lower_slt(&arena, node)?;
@@ -4486,7 +4498,7 @@ impl Ff<'_, '_> {
));
delay = product;
}
- self.with_kernel(|kernel| kernel.inactive_delay(delay))
+ self.with_kernel(|kernel| kernel.inactive_delay(delay, constant))
.map_err(kernel_error)
}
@@ -4846,6 +4858,7 @@ impl Ff<'_, '_> {
/// The kernel of a process and its wait and nonblocking assignment sites.
pub(super) struct KernelUnit {
pub unit: ExecutionUnit,
+ pub slots: ProcessSlots,
pub wait_sites: Vec>,
pub nba_sites: Vec>,
pub host_request_sites: Vec>,
diff --git a/crates/celox-runtime/src/lib.rs b/crates/celox-runtime/src/lib.rs
index 2d2b872cc15..d8f0ad79b9b 100644
--- a/crates/celox-runtime/src/lib.rs
+++ b/crates/celox-runtime/src/lib.rs
@@ -35,8 +35,8 @@ pub use reflection::{
};
pub use schedule::{ResolvedSchedule, host_watch};
pub use simulation::{
- EventInfo, HostBoundary, ScheduleParts, SimulationExecutor, SimulationSnapshot,
- SimulationState, UnitExecutor,
+ EventInfo, HostBoundary, KernelSchedule, ScheduleKey, ScheduleParts, SchedulerMode,
+ SchedulerStats, SimulationExecutor, SimulationSnapshot, SimulationState, UnitExecutor,
};
pub use state_file::{
BaselineRecord, NbaRecord, ProcessRecord, ScheduleRecord, ScheduledEvent, StateDifference,
diff --git a/crates/celox-runtime/src/simulation/mod.rs b/crates/celox-runtime/src/simulation/mod.rs
index 5a6766970e6..07724e56eed 100644
--- a/crates/celox-runtime/src/simulation/mod.rs
+++ b/crates/celox-runtime/src/simulation/mod.rs
@@ -8,6 +8,7 @@ mod nba;
mod persist;
mod process;
mod round;
+mod stats;
mod time;
mod wait;
@@ -19,7 +20,8 @@ use celox_design::CounterKind;
pub(crate) use batch::{edge_level, event_level};
pub use host::{HostBoundary, HostWatch, SimulationExecutor, UnitExecutor};
pub use nba::NbaUpdate;
-pub use persist::{ScheduleParts, SimulationSnapshot};
+pub use persist::{ScheduleKey, ScheduleParts, SimulationSnapshot};
+pub use stats::{KernelSchedule, SchedulerMode, SchedulerStats};
pub use wait::{Baseline, Waiter, Waiters};
use self::round::Round;
@@ -118,6 +120,8 @@ pub struct SimulationState {
return_budget: u64,
/// Rounds and process-phase passes the current time slot has run.
slot_passes: u64,
+ /// The loop that runs time slots, and the slots each loop ran.
+ stats: SchedulerStats,
}
impl SimulationState {
@@ -169,7 +173,12 @@ impl SimulationState {
round_budget: SLOT_ROUND_BUDGET,
return_budget: SLOT_RETURN_BUDGET,
slot_passes: 0,
+ stats: SchedulerStats::default(),
};
+ state.stats.kernels = vec![
+ KernelSchedule::Reference("the design has no compiled scheduler");
+ state.model.processes.len()
+ ];
state.synchronize_event_values(backend);
state
}
@@ -215,6 +224,52 @@ impl SimulationState {
}
}
+ /// Run every time slot with work up to and including `end`, then move
+ /// to `end`. A target before the current time changes nothing. Returns
+ /// whether the simulation is at `end` afterwards; it is not when a
+ /// process stopped it (`$stop`) or finished it on the way.
+ pub fn run_until(&mut self, executor: &mut E, end: u64) -> Result
+ where
+ E: SimulationExecutor,
+ {
+ if end < self.scheduler.time {
+ // Time only moves forward. Moving the timestamp back while the
+ // design keeps the state it reached would leave the two
+ // describing different moments, so an earlier target is a no-op.
+ return Ok(false);
+ }
+ while let Some(next_time) = self.next_event_time() {
+ if next_time > end {
+ break;
+ }
+ self.step_until(executor, end)?;
+ if self.stopped {
+ return Ok(false);
+ }
+ }
+ if self.finished {
+ return Ok(false);
+ }
+ self.advance_time(executor.backend_mut(), end);
+ Ok(true)
+ }
+
+ /// Select the loop that runs time slots.
+ pub fn set_scheduler_mode(&mut self, mode: SchedulerMode) {
+ self.stats.mode = mode;
+ }
+
+ /// The loop that runs time slots, what it ran and how each process
+ /// kernel is scheduled.
+ pub fn scheduler_stats(&self) -> &SchedulerStats {
+ &self.stats
+ }
+
+ /// Count a step checked against a shadow simulation.
+ pub fn note_checked_step(&mut self) {
+ self.stats.checked_steps += 1;
+ }
+
/// Complete a boundary reached from an entry point that returns runtime
/// errors rather than scheduler control halts.
fn finish_timed_boundary(
diff --git a/crates/celox-runtime/src/simulation/persist.rs b/crates/celox-runtime/src/simulation/persist.rs
index c7d8a0d81cb..696d04ec5e1 100644
--- a/crates/celox-runtime/src/simulation/persist.rs
+++ b/crates/celox-runtime/src/simulation/persist.rs
@@ -240,3 +240,86 @@ impl SimulationSnapshot {
self.time
}
}
+
+impl SimulationState {
+ /// The scheduling state in a form that compares equal between two
+ /// simulations of the same design exactly when they would continue
+ /// alike: events by id rather than handle, queues in order, and only the
+ /// waiting processes' waits.
+ #[doc(hidden)]
+ pub fn schedule_key(&self) -> ScheduleKey {
+ let mut events: Vec<_> = self
+ .scheduler
+ .event_queue
+ .iter()
+ .map(|event| {
+ (
+ event.time,
+ event.event_ref.id(),
+ event.signal,
+ event.next_val,
+ event.periodic,
+ )
+ })
+ .collect();
+ events.sort_unstable();
+ let mut process_wakeups: Vec<_> = self
+ .process_wakeups
+ .iter()
+ .map(|Reverse(wakeup)| *wakeup)
+ .collect();
+ process_wakeups.sort_unstable();
+ let state = &self.process_state;
+ ScheduleKey {
+ time: self.scheduler.time,
+ clocks: self
+ .scheduler
+ .clocks
+ .iter()
+ .map(|clock| clock.as_ref().map(|clock| clock.period))
+ .collect(),
+ events,
+ high_events: self.last_clock_values.iter().collect(),
+ unknown_events: self.last_clock_unknown.iter().collect(),
+ process_wakeups,
+ waiters: state
+ .waiters
+ .iter()
+ .map(|(process, waiter)| (process, waiter.clone()))
+ .collect(),
+ ready: state.ready.iter().copied().collect(),
+ inactive: state.inactive.iter().copied().collect(),
+ nba_queue: state.nba_queue.clone(),
+ domain_counters: state.domain_counters.clone(),
+ declarations_pending: self.declarations_pending,
+ host_pending: self.host_pending,
+ finished: self.finished,
+ stopped: self.stopped,
+ suspended: self.suspended.is_some(),
+ }
+ }
+}
+
+/// See [`SimulationState::schedule_key`].
+#[doc(hidden)]
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct ScheduleKey {
+ pub time: u64,
+ pub clocks: Vec