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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ jobs:
- name: Check dependencies
run: cargo machete && cargo deny check advisories

miri:
if: ${{ github.server_url == 'https://github.com' }}
name: Miri
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6

# The existence tests drive the dense, usize-keyed count state. A pinned
# nightly keeps a new nightly from failing CI on its own; bump it on
# purpose.
- name: Install Miri
run: rustup toolchain install nightly-2026-01-20 --profile minimal --component miri --no-self-update

- name: Run the existence tests under Miri
run: |
cargo +nightly-2026-01-20 miri setup
cargo +nightly-2026-01-20 miri test -p solverforge-scoring --lib -- constraint::tests::exists

package:
if: ${{ github.server_url == 'https://github.com' }}
name: Package
Expand Down
1 change: 1 addition & 0 deletions crates/solverforge-scoring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![allow(clippy::type_complexity)]
#![warn(unreachable_pub)]
#![warn(missing_docs)]
#![forbid(unsafe_code)]

// Core modules
pub mod api;
Expand Down
37 changes: 20 additions & 17 deletions crates/solverforge-scoring/src/stream/relational/count_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//! once at construction; the event path calls one enum method per key and
//! nothing else branches.

use std::any::Any;

use super::{FastMap, RowHandle};

/// One key's count plus the epoch of its last touch, stamped against the
Expand Down Expand Up @@ -291,26 +293,27 @@ impl DenseKeys {
}

/// View a generic key as its `usize` representation. Only called inside the
/// `K == usize` arm of `KeyState::new`, where the conversion is the identity.
/// `K == usize` arm of `KeyState::new`, where the downcast is the identity and
/// monomorphizes to a plain read.
///
/// # Panics
///
/// When `K` is not `usize`.
fn dense_raw<K: 'static>(key: &K) -> usize {
debug_assert_eq!(
std::any::TypeId::of::<K>(),
std::any::TypeId::of::<usize>(),
"dense counts are usize-keyed"
);
// SAFETY: K is usize in this arm; the reference reinterprets the same
// non-null, aligned, initialized 8 bytes.
unsafe { *(key as *const K as *const usize) }
*(key as &dyn Any)
.downcast_ref::<usize>()
.expect("dense counts are usize-keyed")
}

/// Inverse of `dense_raw`, same `K == usize` arm.
///
/// # Panics
///
/// When `K` is not `usize`.
fn key_from_raw<K: 'static>(raw: usize) -> K {
debug_assert_eq!(
std::any::TypeId::of::<K>(),
std::any::TypeId::of::<usize>(),
"dense counts are usize-keyed"
);
// SAFETY: K is usize in this arm; usize is repr-transparent `K` here and
// the pointer is valid, aligned, initialized.
unsafe { std::ptr::read(&raw as *const usize as *const K) }
let mut slot = Some(raw);
(&mut slot as &mut dyn Any)
.downcast_mut::<Option<K>>()
.and_then(Option::take)
.expect("dense counts are usize-keyed")
}
Loading