Skip to content

feat(sv)!: execute final procedures at simulation termination - #2088

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/fix/sv-tests-preprocessing/execute-final-procedures-simulation-termination--75200be6
Oct 26, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/fix/sv-tests-preprocessing/execute-final-procedures-simulation-termination--75200be6

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

SystemVerilog final procedures were rejected, so testbenches could not inspect their last state or report results at termination. Preserve them as terminal process kernels and run them once on $finish, $fatal, or explicit Simulation::finish(). The batch CLI and sv-tests driver finish on quiescence; bounded host runs remain resumable. Program finals also run after implicit termination.

Keep final execution sequential and at zero simulation time. Resume $stop inside final at its cursor, stop immediately at $finish inside final, preserve the initiating fatal error, and prevent queued HDL events or deferred assertions from executing after termination. Validate function-statement restrictions, including omitted argument defaults. Route fatal errors from explicit waveform dumps and end-of-run waveform evaluation through the same terminal phase. Finalize immediate fatal errors raised by lazy runtime-event draining before collecting reports. Settle and execute final procedures before capturing saved state, and reject saving if final execution stops. Keep differential scheduling synchronized on these host-triggered termination paths. Document the lifecycle and restrictions.

Validation:

  • 18 final API tests cover two/four-state Interpreter, Cranelift, WASM, Native and Tiered execution, differential scheduling, checkpoints and native-image roundtrip.
  • CI follow-up: default-feature library 150, enabled-feature library 229, VCD 36, reference-adapter 7, the unsupported-construct regression and JS boundary 9 tests pass. Formatting and Clippy pass. Fatal errors terminate execution while preserving the original diagnostic and waveform; tests no longer require recovery from $fatal.
  • P2 regression coverage: all four added tests fail before the fix and pass after it. Related library, checkpoint, observer, runtime API, state-file, deferred-assertion and VCD tests pass (1,281 tests; 34 existing ignores). Rebuilt the debug NAPI addon; 28 JS checkpoint/runtime-event/timing tests, formatting and Clippy pass.
  • Direct portable fixtures: Icarus 13.0 passes all three; Verilator 5.052 passes state/hierarchy but continues after $finish inside final, contrary to 9.2.3. Keep immediate-termination expectations. These fixtures use owning-crate API tests because the shared timed emitter has its own final checker with unspecified relative ordering.
  • Focused sv-tests rerun: 70 additional passing cases per mode out of 108 previously blocked by final; update exactly 140 measured expectations. Full release-driver conformance remains in CI as requested.

BREAKING CHANGE: ProcessSlots and ProcessRefs use ProcessKind instead of is_initializer; fatal errors have a distinct Fatal variant; SimulationState::finish is fallible; native image format advances to version 39.

@tignear

tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(sv)!: execute final procedures at simulation termination #2088 👈
2 feat(sv)!: execute fork branches as dynamic process activations #2112
3 feat(sv)!: support wait fork and disable fork process control #2116

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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 🔄 Running since 2026-10-26T04:51:18.436331Z 7c6f1e5 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.

@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.

Base automatically changed from stack/tignear/fix/sv-tests-preprocessing/read-heap-strings-formatted-scans--982978c1 to master October 25, 2026 22:46
@tignear
tignear force-pushed the stack/tignear/fix/sv-tests-preprocessing/execute-final-procedures-simulation-termination--75200be6 branch from 150baf1 to 1f0b1aa Compare October 26, 2026 04:18
@tignear

tignear commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 150baf1 2026-10-26 04:16 UTC
2 content 150baf1 → 1f0b1aa Fix four CI regressions and missing fatal finalization through dump/try_dump and end-of-run waveform evaluation; validate default/feature libraries, VCD, reference adapter, final API and JS 2026-10-26 04:16 UTC
3 content 1f0b1aa → 7c6f1e5 Fix both P2 findings: finalize fatal errors during lazy event drain; capture saved state after final execution and reject stopped final procedures. 2026-10-26 04:50 UTC

@tignear

tignear commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@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: 1f0b1aa16d

ℹ️ 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 Outdated
Comment on lines +1067 to +1071
if matches!(
self.simulator.mature_deferred_assertions(),
Err(RuntimeErrorCode::Fatal { .. })
) {
let _ = self.state.finalize_terminal(&mut self.simulator);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Finalize immediate fatal reports raised while draining events

When a host modifies an input and then calls drain_runtime_events(), its lazy combinational settle can execute an immediate $fatal. This path only finalizes fatal errors from mature_deferred_assertions(); the immediate fatal is swallowed by Simulator::eval_comb_for_runtime_event_drain() and returned as a report without terminating the simulation. For example, always_comb if (fail) $fatal(1); final calls++; can report the fatal while leaving is_finished() false and calls unchanged. Handle termination raised by the lazy settle as well, including when the design has no deferred assertions.

Useful? React with 👍 / 👎.

self.host_pending = false;
self.finalizing = Some(0);
}
let result = self.run_final_procedures(executor);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture saved state after final procedures have executed

When settling dirty combinational logic during Simulation::save_state() executes $finish, the existing caller captures the file through self.simulator.save_state() before calling sync_finish_checked(). Now that finalization executes kernels, final procedures can change variables after that capture, while the subsequently exported schedule records finished = true. For example, a conditional combinational $finish followed by final result = 42; saves the old result with a terminal schedule; restoring it cannot run the skipped final updates. Settle and synchronize termination before capturing state, and recheck suspension if a final executes $stop.

Useful? React with 👍 / 👎.

@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

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

SystemVerilog final procedures were rejected, so testbenches could not inspect their last state or report results at termination. Preserve them as terminal process kernels and run them once on $finish, $fatal, or explicit Simulation::finish(). The batch CLI and sv-tests driver finish on quiescence; bounded host runs remain resumable. Program finals also run after implicit termination.

Keep final execution sequential and at zero simulation time. Resume $stop inside final at its cursor, stop immediately at $finish inside final, preserve the initiating fatal error, and prevent queued HDL events or deferred assertions from executing after termination. Validate function-statement restrictions, including omitted argument defaults. Route fatal errors from explicit waveform dumps and end-of-run waveform evaluation through the same terminal phase. Finalize immediate fatal errors raised by lazy runtime-event draining before collecting reports. Settle and execute final procedures before capturing saved state, and reject saving if final execution stops. Keep differential scheduling synchronized on these host-triggered termination paths. Document the lifecycle and restrictions.

Validation:
- 18 final API tests cover two/four-state Interpreter, Cranelift, WASM, Native and Tiered execution, differential scheduling, checkpoints and native-image roundtrip.
- CI follow-up: default-feature library 150, enabled-feature library 229, VCD 36, reference-adapter 7, the unsupported-construct regression and JS boundary 9 tests pass. Formatting and Clippy pass. Fatal errors terminate execution while preserving the original diagnostic and waveform; tests no longer require recovery from $fatal.
- P2 regression coverage: all four added tests fail before the fix and pass after it. Related library, checkpoint, observer, runtime API, state-file, deferred-assertion and VCD tests pass (1,281 tests; 34 existing ignores). Rebuilt the debug NAPI addon; 28 JS checkpoint/runtime-event/timing tests, formatting and Clippy pass.
- Direct portable fixtures: Icarus 13.0 passes all three; Verilator 5.052 passes state/hierarchy but continues after $finish inside final, contrary to 9.2.3. Keep immediate-termination expectations. These fixtures use owning-crate API tests because the shared timed emitter has its own final checker with unspecified relative ordering.
- Focused sv-tests rerun: 70 additional passing cases per mode out of 108 previously blocked by final; update exactly 140 measured expectations. Full release-driver conformance remains in CI as requested.

BREAKING CHANGE: ProcessSlots and ProcessRefs use ProcessKind instead of is_initializer; fatal errors have a distinct Fatal variant; SimulationState::finish is fallible; native image format advances to version 39.

Change-Id: I75200be6ce640d73a84562a25ff48cdae2237106
@tignear
tignear force-pushed the stack/tignear/fix/sv-tests-preprocessing/execute-final-procedures-simulation-termination--75200be6 branch from 1f0b1aa to 7c6f1e5 Compare October 26, 2026 04:51
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 26, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 38 minutes in the queue, including 33 minutes 19 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 321ccac into master Oct 26, 2026
23 checks passed
@mergify
mergify Bot deleted the stack/tignear/fix/sv-tests-preprocessing/execute-final-procedures-simulation-termination--75200be6 branch October 26, 2026 06:58
@mergify mergify Bot removed the queued Mergify queue entry label Oct 26, 2026
@mergify mergify Bot mentioned this pull request Oct 26, 2026
15 of 71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant