Skip to content

feat(sim): fail runs on reports and drain runtime events in TypeScript - #1876

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

A TypeScript Simulation could not see what the design reported. $display output, $error and failed assertions stayed in the event buffer, and only $fatal reached TypeScript, as an error of the run. This adds both halves of #89's fail-fast on top of the structured reports of the previous change.

Simulation::set_fail_on.

  • run_until, run_until_bounded and step stop after the time step of the first report of at least the given severity.
  • Simulation::failure returns that report, as is_stopped does for $stop. The next run clears it and continues.
  • While it is set, the events of each step are taken from the event buffer after the step, with the time of that step. Reports then carry an exact time, and the buffer cannot overwrite them before the host drains. drain_runtime_events returns them first.
  • A step watches one time slot. A slot that only settles host writes is watched on its own, so a report it causes stops the run before later slots run.
  • Combinational logic left dirty by host writes that wake no process settles at the current time and is watched before the run moves to a later time or ends (watch_settle). Otherwise the later slot, or the settle at the run's end, issued its reports unwatched and with a later time.
  • Events lost to a full event buffer (Missed) may have held a failure, so they are one: failure() is a report of the fail_on severity, missed N runtime events.
  • Runs with it set take a separate loop. Runs without it keep the loop they had, with one check per run.

NAPI. NativeSimulationHandle has:

  • drainRuntimeEvents(): objects with kind (display, write, report, finish, stop, missed) and, for a report, severity, message, time, scope, file, line and assertion;
  • setFailOn(severity | null).

runUntil, runUntilBounded and step throw failOn: <rendered report> when they stop at a failure. The bare Simulator handle wraps only a backend, and the WASM addon has no timed simulation, so neither has these.

TypeScript.

  • Simulation.drainRuntimeEvents() returns a RuntimeEvent union. A Report has absent fields omitted.
  • Simulation.setFailOn() sets the severity.
  • Severity, Report, AssertionSite and RuntimeEvent are exported.

callgrind, whole native program at 200,000 cycles minus at 20,000 cycles, 64 always_ff counters on a clock, without failOn. Both binaries are built in the same worktree:

previous change (base) this change
instructions 1,015,380,290 1,015,380,043

Equal. The first version checked the setting in every step and drained through the lazy comb path. That cost +0.96%, all from codegen around the drain:

  • an extra caller of the comb evaluation made LLVM outline eval_comb_capturing_events from eval_comb_checked (+10.8M);
  • the step loop got longer.

The watched loop is now separate, and it drains through drain_settled_runtime_events_with_context, which does not evaluate comb: a step leaves comb settled.

  • New Rust test sv_reports::*::fail_on_stops_runs_at_the_time_of_a_report on the interpreter, cranelift, native and wasm backends:
    • with Error, $warning at 1 and $error at 2 stop the run at 2;
    • failure() is the $error;
    • the drained reports have times 1 and 2;
    • the next run reaches the target and shows the later $display.
  • New fail_on_stops_at_reports_of_host_writes: a host write at 2 that wakes always @(posedge a) $error, with a $display at 5, stops run_until(10) and step() at 2 with the report at 2. Without the change both reach 5.
  • New fail_on_stops_at_reports_of_settles_without_steps: an always_comb $error that a host write at 2 enables, with nothing scheduled and with an initial #5 $display, stops run_until(10) and step() at 2 with the report at 2, and the next run reaches 10. Without the change the run went on to 5 or 10.
  • New fail_on_stops_at_missed_events: 2,000 $displays at 1 stop the run at 1 with a missed failure. Without the change it runs on.
  • New packages/celox/src/runtime-events-addon.test.ts (Veryl through the addon):
    • drainRuntimeEvents returns $display output and an $assert_continue report in order, then nothing;
    • setFailOn("error") makes runUntil throw at the time of the report, which the drained report carries, and the next runUntil continues;
    • an unknown severity is rejected.
  • vitest run --testTimeout 60000 in packages/celox with a debug addon: 435 passed. With the default 5 s timeout, e2e.test.ts > several threads simulate exactly like one times out on the debug addon; CI builds it in release.
  • tsc -p tsconfig.test.json and biome check.
  • cargo nextest run -p celox -p celox-napi -p celox-vpi --features celox/systemverilog: 13,586 passed.
  • cargo clippy with CI's features and -D warnings, cargo fmt --check.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-25T04:28:32.475116Z
We couldn’t complete this review. Comment @codex review to try again.
305f5a5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear

tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(sim): fail runs on reports and drain runtime events in TypeScript #1876 👈
2 fix(sv)!: defer the actions of deferred assertions in processes #1877
3 feat(sv)!: defer assertions of combinational processes, module items and covers #1878
4 feat(sv): support $sampled in processes #1879
5 feat(sv): support $past and the value change functions in clocked processes #1880
6 fix(sv)!: give reports the time they are issued at #1881
7 feat(sv): sample static locals and combinational logic, and infer more clocks of $past #1882

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 693f32a7e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/simulation.rs Resolved
Comment thread crates/celox/src/simulation.rs Resolved
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/report-severity-location-assertion-severity-tasks--4abb3cc4 branch from 2da588a to 1a9cabc Compare October 24, 2026 11:06
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7 branch from 693f32a to 3df1b35 Compare October 24, 2026 11:06
@tignear

tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 693f32a 2026-10-24 11:03 UTC
2 content 693f32a → 3df1b35 Review: watch each slot of host-write settling on its own, and count missed events as a failure 2026-10-24 11:03 UTC
3 rebase 3df1b35 → 7b255b9 (rebase only) 2026-10-24 12:11 UTC
4 content 7b255b9 → 0eb27bd 2026-10-24 18:21 UTC
5 rebase 0eb27bd → bac33ca (rebase only) 2026-10-24 21:36 UTC
6 content bac33ca → 305f5a5 2026-10-25 04:27 UTC

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3df1b35b52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/simulation.rs Resolved
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/report-severity-location-assertion-severity-tasks--4abb3cc4 branch from 1a9cabc to e96ed5a Compare October 24, 2026 12:12
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7 branch from 3df1b35 to 7b255b9 Compare October 24, 2026 12:12
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/report-severity-location-assertion-severity-tasks--4abb3cc4 branch from e96ed5a to 960a5f3 Compare October 24, 2026 18:24
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7 branch 2 times, most recently from 0eb27bd to bac33ca Compare October 24, 2026 21:38
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/report-severity-location-assertion-severity-tasks--4abb3cc4 branch from 960a5f3 to a8d379a Compare October 24, 2026 21:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bac33ca55d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/simulation.rs Resolved
Base automatically changed from stack/tignear/feat/sva-stage1/report-severity-location-assertion-severity-tasks--4abb3cc4 to master October 24, 2026 23:40
A TypeScript `Simulation` could not see what the design reported. `$display` output, `$error` and failed assertions stayed in the event buffer, and only `$fatal` reached TypeScript, as an error of the run. This adds both halves of #89's fail-fast on top of the structured reports of the previous change.

**`Simulation::set_fail_on`.**
- `run_until`, `run_until_bounded` and `step` stop after the time step of the first report of at least the given severity.
- `Simulation::failure` returns that report, as `is_stopped` does for `$stop`. The next run clears it and continues.
- While it is set, the events of each step are taken from the event buffer after the step, with the time of that step. Reports then carry an exact `time`, and the buffer cannot overwrite them before the host drains. `drain_runtime_events` returns them first.
- A step watches one time slot. A slot that only settles host writes is watched on its own, so a report it causes stops the run before later slots run.
- Combinational logic left dirty by host writes that wake no process settles at the current time and is watched before the run moves to a later time or ends (`watch_settle`). Otherwise the later slot, or the settle at the run's end, issued its reports unwatched and with a later time.
- Events lost to a full event buffer (`Missed`) may have held a failure, so they are one: `failure()` is a report of the `fail_on` severity, `missed N runtime events`.
- Runs with it set take a separate loop. Runs without it keep the loop they had, with one check per run.

**NAPI.** `NativeSimulationHandle` has:
- `drainRuntimeEvents()`: objects with `kind` (`display`, `write`, `report`, `finish`, `stop`, `missed`) and, for a report, `severity`, `message`, `time`, `scope`, `file`, `line` and `assertion`;
- `setFailOn(severity | null)`.

`runUntil`, `runUntilBounded` and `step` throw `failOn: <rendered report>` when they stop at a failure. The bare `Simulator` handle wraps only a backend, and the WASM addon has no timed simulation, so neither has these.

**TypeScript.**
- `Simulation.drainRuntimeEvents()` returns a `RuntimeEvent` union. A `Report` has absent fields omitted.
- `Simulation.setFailOn()` sets the severity.
- `Severity`, `Report`, `AssertionSite` and `RuntimeEvent` are exported.

callgrind, whole native program at 200,000 cycles minus at 20,000 cycles, 64 `always_ff` counters on a clock, without `failOn`. Both binaries are built in the same worktree:

| | previous change (base) | this change |
|---|---|---|
| instructions | 1,015,380,290 | 1,015,380,043 |

Equal. The first version checked the setting in every step and drained through the lazy comb path. That cost +0.96%, all from codegen around the drain:
- an extra caller of the comb evaluation made LLVM outline `eval_comb_capturing_events` from `eval_comb_checked` (+10.8M);
- the step loop got longer.

The watched loop is now separate, and it drains through `drain_settled_runtime_events_with_context`, which does not evaluate comb: a step leaves comb settled.

- New Rust test `sv_reports::*::fail_on_stops_runs_at_the_time_of_a_report` on the interpreter, cranelift, native and wasm backends:
  - with `Error`, `$warning` at 1 and `$error` at 2 stop the run at 2;
  - `failure()` is the `$error`;
  - the drained reports have times 1 and 2;
  - the next run reaches the target and shows the later `$display`.
- New `fail_on_stops_at_reports_of_host_writes`: a host write at 2 that wakes `always @(posedge a) $error`, with a `$display` at 5, stops `run_until(10)` and `step()` at 2 with the report at 2. Without the change both reach 5.
- New `fail_on_stops_at_reports_of_settles_without_steps`: an `always_comb` `$error` that a host write at 2 enables, with nothing scheduled and with an `initial #5 $display`, stops `run_until(10)` and `step()` at 2 with the report at 2, and the next run reaches 10. Without the change the run went on to 5 or 10.
- New `fail_on_stops_at_missed_events`: 2,000 `$display`s at 1 stop the run at 1 with a `missed` failure. Without the change it runs on.
- New `packages/celox/src/runtime-events-addon.test.ts` (Veryl through the addon):
  - `drainRuntimeEvents` returns `$display` output and an `$assert_continue` report in order, then nothing;
  - `setFailOn("error")` makes `runUntil` throw at the time of the report, which the drained report carries, and the next `runUntil` continues;
  - an unknown severity is rejected.
- `vitest run --testTimeout 60000` in `packages/celox` with a debug addon: 435 passed. With the default 5 s timeout, `e2e.test.ts > several threads simulate exactly like one` times out on the debug addon; CI builds it in release.
- `tsc -p tsconfig.test.json` and `biome check`.
- `cargo nextest run -p celox -p celox-napi -p celox-vpi --features celox/systemverilog`: 13,586 passed.
- `cargo clippy` with CI's features and `-D warnings`, `cargo fmt --check`.

Change-Id: I4b6716e776cfafba8386e0b35191299213b4897b
@tignear
tignear force-pushed the stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7 branch from bac33ca to 305f5a5 Compare October 25, 2026 04:28
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tignear

tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 52 minutes 59 seconds in the queue, including 25 minutes 45 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit a9830c6 into master Oct 25, 2026
24 checks passed
@mergify
mergify Bot deleted the stack/tignear/feat/sva-stage1/fail-runs-reports-drain-runtime-events-typescript--4b6716e7 branch October 25, 2026 05:54
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant