Skip to content
Closed
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
4 changes: 4 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fail-fast = false
slow-timeout = { period = "60s", terminate-after = 10 }
failure-output = "immediate-final"

[profile.ci.junit]
path = "junit.xml"
store-success-output = false

[[profile.ci.overrides]]
# Deep per-bit graphs consume substantial compiler memory and CPU. Reserve the
# pool so these regressions retain the same timeout without competing builds.
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ jobs:
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.rust == 'true') }}
runs-on: ubuntu-latest
env:
CELOX_CI_REPORT_DIR: work/ci-reports/rust
HAS_MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN != '' }}
steps:
- uses: actions/checkout@v7
with:
Expand All @@ -220,8 +223,12 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
key: vtest-v1
save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

- name: Initialize Rust test reports
run: node scripts/ci-rust-reports.mjs reset

- uses: actions/setup-python@v7
if: needs.changes.outputs.rust_vpi_e2e != 'false'
with:
Expand All @@ -236,6 +243,10 @@ jobs:
with:
tool: cargo-nextest@0.9.144

- name: Build the optimized vtest executor
if: needs.changes.outputs.rust_full != 'false' || contains(format(' {0} ', needs.changes.outputs.rust_packages), ' celox ')
run: node scripts/run-vtest.mjs --prepare-ci

# Enable the frontend and suite features together so common integration
# tests run once, rather than once per Cargo feature combination.
# nextest schedules tests from all binaries on one pool; `cargo test`
Expand All @@ -244,19 +255,42 @@ jobs:
# (scripts/ci-rust-scope.mjs); merge groups and the daily run keep the
# Celox workspace. lydite-checks.yml owns Lydite tests at its own cadence.
- name: Run workspace tests with CI features
id: workspace-tests
if: needs.changes.outputs.rust_full != 'false'
run: >-
cargo nextest run --locked --workspace --exclude 'lydite*' --profile ci
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases

- name: Run the tests this pull request can affect
id: scoped-tests
if: needs.changes.outputs.rust_full == 'false' && needs.changes.outputs.rust_packages != ''
env:
BUILDS: ${{ needs.changes.outputs.rust_builds }}
FILTER: ${{ needs.changes.outputs.rust_filter }}
run: |
node scripts/run-ci-rust-scope.mjs test

- name: Collect Rust test reports
if: success() || failure()
run: node scripts/ci-rust-reports.mjs collect

- name: Retain Rust test reports
if: (success() || failure()) && hashFiles('work/ci-reports/rust/*.xml') != ''
uses: actions/upload-artifact@v7
with:
name: rust-test-results
path: work/ci-reports/rust/*.xml
retention-days: 14

- name: Upload Rust test results to Mergify
if: (success() || failure()) && env.HAS_MERGIFY_TOKEN == 'true' && hashFiles('work/ci-reports/rust/*.xml') != ''
uses: mergifyio/gha-mergify-ci@392d123d84a27960993927aec1f2cbb059fb95c1 # v27
with:
token: ${{ secrets.MERGIFY_TOKEN }}
report_path: work/ci-reports/rust/*.xml
job_name: rust-tests
test_step_outcome: ${{ steps.workspace-tests.outcome != 'skipped' && steps.workspace-tests.outcome || steps.scoped-tests.outcome }}

# nextest does not run documentation tests.
- name: Run workspace documentation tests with CI features
if: needs.changes.outputs.rust_full != 'false'
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/rust-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- ".github/actions/setup-rust/**"
- ".github/workflows/rust-cache.yml"
- ".github/workflows/ci.yml"
- "scripts/run-vtest.mjs"
workflow_dispatch:

permissions:
Expand All @@ -39,14 +40,19 @@ jobs:
- uses: ./.github/actions/setup-rust
- uses: Swatinem/rust-cache@v2
id: cache
with:
key: vtest-v1
- name: Install cargo-nextest
if: steps.cache.outputs.cache-hit != 'true'
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest@0.9.144
- name: Build the optimized vtest executor to populate dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: node scripts/run-vtest.mjs --prepare-ci
- name: Build test targets to populate dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: >-
cargo nextest list --locked --workspace --message-format json
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus
--features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/runtime-cases
> /dev/null
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ GCC-style optimization level presets with per-pass overrides.
| `PartialForward` | Partial store-load forwarding in combinational blocks |
| `IdentityStoreBypass` | Detects identity copies and registers address aliases |
| `TailCallSplit` | Splits large functions into tail-call chains (enabled even at O0) |
| `DerivedEdgeUnits` | Runs edges of gated/divided clocks in generated units instead of the Rust plan walk (not a SIR transform; costs build time, `-sir:derived_edge_units` to opt out) |

### Cranelift Backend Optimization

Expand Down
47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,53 @@ Use the actual affected case or group as the filter. For SystemVerilog cases,
use the `verify-sv-verilator` and `verify-sv-icarus` binaries. Missing tools,
empty selections, compilation failures, and simulator errors are not passes.

For repeated local vtest runs, use the optimized shared executor:

```sh
node scripts/run-vtest.mjs --test counter
node scripts/run-vtest.mjs --test systemverilog -E 'test(operators::)'
```

This builds `vtest-exec` with the `vtest` Cargo profile (`opt-level = 1`,
development assertions and overflow checks enabled), then runs the existing
Celox test registrations with nextest. Both builds enable `systemverilog` and
`celox-test-suite/runtime-cases`. Cases execute in the shared binary, while
Rust API tests execute normally. Existing test names, filters, backend omissions,
ignored cases and nextest's parallel scheduling/timeouts are preserved. Additional
arguments are passed to `cargo nextest run`; use `--run-ignored all` to include
ignored registrations deliberately.

With `runtime-cases`, `.vtest` bodies are read from disk instead of embedded in
Rust binaries, so edits to an existing case do not require recompilation. Adding
a test registration or changing Rust still requires a build. The first run builds
both the optimized executor and ordinary test binaries; the executor profile has
its own Cargo cache. Ordinary Cargo test commands retain the embedded, in-process
path. CI's Rust Tests job prepares the executor once and uses it for both full
workspace runs and scoped runs that include Celox. Scopes without Celox skip that
build. The default-branch cache warmer builds both executor and test dependencies
under the same cache key; vtest preparation failures fail the test job.

The CI nextest profile also emits JUnit results. The Rust Tests job preserves
each scoped invocation separately under `work/ci-reports/rust/`, retains the XML
as the `rust-test-results` artifact for 14 days, and uploads it to Mergify CI
Insights when the repository's `MERGIFY_TOKEN` secret is available. The secret
must be a Mergify application key with `ci` scope, and CI Insights must be enabled
for the repository. Tests keep their normal failure status; reporting does not
enable retries or quarantine. Forks without the secret still run tests and retain
the artifact. `cargo test`/doctest invocations are not part of this nextest report.

For debugging a single case after building, the executor also accepts
`<veryl|sv> <group::case> <backend>` directly, for example:

```sh
target/vtest/examples/vtest-exec veryl counter::test_counter_n4_basic native
```

Direct invocations do not apply registration-level ignores. `CELOX_VTEST_ROOT`
can point to an alternative corpus root containing `veryl/cases` and `sv/cases`;
otherwise the executor uses the suite's source directory from its build checkout.
The script sets that root and `CELOX_VTEST_RUNNER` for its test invocation only.

External results are reused locally by default, including between worktrees,
when the case, verifier and tool fingerprints match. New/changed cases and
prior failures run again; `--fresh` forces execution. A Celox implementation
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ incremental = true
[profile.bench]
debug = true

# Optimize the shared vtest executor while keeping development checks enabled.
# External dependencies retain the dev profile's package-specific optimization.
[profile.vtest]
inherits = "dev"
opt-level = 1

# Profile for wasm-pack builds. LTO is disabled to avoid a known issue
# where proc-macro dependencies (syn) get incorrectly compiled for the
# wasm32 target under full LTO.
Expand Down
17 changes: 17 additions & 0 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,22 @@ pub struct RuntimeSchema<A> {
/// scheduler itself once one is generated. Present when the design has
/// process kernels.
pub scheduler: Option<SchedulerSchema<A>>,
/// Generated units that run an edge of an event with every derived
/// clock domain it reaches, for the events that have them.
pub derived_edges: Vec<DerivedEdgeUnits<A>>,
}

/// The process units that run the edges of one event together with its
/// derived clock domains, the signal having already moved. Each reads
/// [`SchedulerSlots::dirty`] to know whether combinational logic must
/// settle before the domains evaluate.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct DerivedEdgeUnits<A> {
/// The canonical event.
pub event: A,
/// Indices among the process units of the rising and the falling edge.
pub rising: usize,
pub falling: usize,
}

/// Width of [`SchedulerSlots::limit`], [`SchedulerSlots::now`],
Expand Down Expand Up @@ -1084,6 +1100,7 @@ impl<A> Default for RuntimeSchema<A> {
active_commits: Vec::new(),
time_slots: Vec::new(),
scheduler: None,
derived_edges: Vec::new(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
active_commits,
time_slots,
scheduler,
derived_edges: Vec::new(),
},
};

Expand Down
62 changes: 62 additions & 0 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,66 @@ fn shared_edge_memories(
memories
}

/// The unpacked arrays that only edge-triggered processes of `module` drive.
/// A process that writes one of them only by nonblocking assignments, at
/// least one of them at a run-time element, publishes just the elements it
/// wrote (see `Ff::lower_process`) instead of seeding and committing the
/// whole array on every edge.
///
/// This uses the drivers within `module`. The sparse commit copies back
/// only the 64-bit chunks the process wrote, so a write from another scope
/// that lands between the evaluation and the commit of the process can be
/// lost only within those chunks, where a whole-array commit loses it
/// everywhere. A writer outside `module` (a hierarchical reference) that
/// must not lose such writes has to be excluded here.
fn edge_only_memories(
module: &sv::ir::Module,
constants: &HashMap<String, i128>,
parameter_types: &HashMap<String, (usize, bool)>,
) -> HashSet<String> {
let first_ff = module.comb_processes().len();
let end_ff = first_ff + module.ff_processes().len();
// Only an array a nonblocking assignment of an edge process writes can
// qualify; the driver scan is for those.
let mut nonblocking = HashSet::default();
for process in module.ff_processes() {
for stmt in process.body() {
stmt.walk(&mut |stmt| match stmt {
sv::ir::Stmt::Assign {
lhs,
nonblocking: true,
..
} => {
nonblocking.insert(lhs.name());
}
sv::ir::Stmt::AssignConcat {
parts,
nonblocking: true,
..
} => nonblocking.extend(parts.iter().map(sv::ir::LValue::name)),
_ => {}
});
}
}
module
.signals()
.iter()
.filter(|s| {
!s.is_net()
&& !s.r#type().unpacked_ranges().is_empty()
&& nonblocking.contains(s.name())
})
.filter(|signal| {
let drivers = local_driver_ranges(module, signal.name(), constants, parameter_types);
!drivers.is_empty()
&& drivers
.iter()
.all(|(id, _)| (first_ff..end_ff).contains(id))
})
.map(|signal| signal.name().to_string())
.collect()
}

fn validate_variable_driver_ranges(
module: &sv::ir::Module,
constants: &HashMap<String, i128>,
Expand Down Expand Up @@ -8429,6 +8489,7 @@ fn lower_ff_processes(
}
}

let edge_memories = edge_only_memories(module, pm.constants, pm.parameter_types);
let random_seeds = process_random_seeds(module);
for ((index, process), events) in module.ff_processes().iter().enumerate().zip(process_events) {
let mut events = events
Expand All @@ -8455,6 +8516,7 @@ fn lower_ff_processes(
staged,
} = ff::Ff::new(pm, random_seeds[&(0, index)])
.with_sparse_memories(shared_memories)
.with_sparse_candidates(&edge_memories)
.lower_process(process.body())?;
repeated_writes.extend(repeated_ff_writes(&eval_only, &staged));
// A process without writes still runs for its runtime events and
Expand Down
Loading
Loading