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
18 changes: 17 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Lint
# rustfmt and clippy in one job: formatting takes a second once the toolchain
# is installed. Clippy lints the library and binary with every feature; tests,
# examples and benches are not linted (the panic-prevention lints in Cargo.toml
# would need thousands of changes there). wasm.yml lints the wasm targets.
# would need thousands of changes there). A separate job lints the browser
# library on wasm32, including code that native builds do not compile.

on:
push:
Expand Down Expand Up @@ -34,3 +35,18 @@ jobs:

- name: Run clippy
run: cargo clippy --all-features -- -D warnings

wasm-clippy:
name: Clippy (wasm32 browser library)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: clippy

- name: Run clippy
run: cargo clippy --target wasm32-unknown-unknown --features browser --lib -- -D warnings
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- **IndexedDB flushes are atomic, settle on abort, and refuse later writes after a failure (#894)**, backported from v3 for the next v2.x patch. A synchronous exception while queueing pages aborts the whole batch; an abort with no request error rejects instead of hanging, and repeated request errors cannot throw from a consumed callback. The failed operation reports `STG-048` naming the IndexedDB write and browser exception (page-preparation errors retain their own code). Subsequent transact/retract, checkpoint and import calls report `STG-046` without changing memory. Overlapping flushes run in order; a checkpoint waits for earlier writes even when it has no dirty pages. Queries, rules and export remain available, including rejected work already applied in memory; export is not a durability acknowledgement. Discard the failed handle and reopen to recover the successful prefix before the failure. A failed import leaves IndexedDB unchanged. Format v7, the IndexedDB schema, public methods, healthy write volume and read-only open behavior are unchanged. Native v2.x behavior is unchanged; the two error codes retain their v3 meanings.

### CI

- Lint the browser library on `wasm32-unknown-unknown` with warnings denied in `lint.yml`, alongside the existing native gate. Gate unused native internals and clean up browser-only lints without changing behavior, the public API or format v7.

### Documentation

- Fix the Rust Quick Start (#884): register recursive rule clauses in separate `execute()` calls and define the keyword entity IDs used by prepared queries. Clarify the entity ID in the prepared-query error example.
Expand Down
4 changes: 4 additions & 0 deletions src/browser/indexeddb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ impl IndexedDbBackend {
let open_request = idb_factory.open_with_u32(db_name, 1)?;

// Create the object store if this is a fresh database (version upgrade).
// Preserve the callback's existing trap on unexpected upgrade failures.
#[allow(clippy::unwrap_used)]
let on_upgrade: Closure<dyn FnMut(web_sys::Event)> =
Closure::once(move |event: web_sys::Event| {
let target = event.target().unwrap();
Expand Down Expand Up @@ -205,6 +207,8 @@ impl IndexedDbBackend {
let mut pages = HashMap::with_capacity(keys_arr.length() as usize);
for i in 0..keys_arr.length() {
let key = keys_arr.get(i);
// Preserve v2's truncating, saturating conversion of numeric IndexedDB keys.
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let page_id = key
.as_f64()
.ok_or_else(|| JsValue::from_str("page_id is not a number"))?
Expand Down
6 changes: 4 additions & 2 deletions src/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ impl BrowserDb {
#[wasm_bindgen(js_name = exportGraph)]
pub fn export_graph(&self) -> Result<js_sys::Uint8Array, JsValue> {
let inner = self.inner.borrow();
// page_count_raw returns the HashMap's usize length widened to u64; this round-trips.
#[allow(clippy::cast_possible_truncation)]
let page_count = inner
.pfs
.with_backend(|b| b.page_count_raw())
Expand Down Expand Up @@ -243,7 +245,7 @@ impl BrowserDb {
pub async fn import_graph(&self, data: js_sys::Uint8Array) -> Result<(), JsValue> {
self.inner.borrow().refuse_failed_flush()?;
let bytes = data.to_vec();
if bytes.len() % crate::storage::PAGE_SIZE != 0 {
if !bytes.len().is_multiple_of(crate::storage::PAGE_SIZE) {
return Err(JsValue::from_str(
"import data length is not a multiple of PAGE_SIZE",
));
Expand Down Expand Up @@ -362,7 +364,7 @@ impl BrowserDb {
f.tx_id = tx_id;
f.tx_count = tx_count;
if f.asserted && f.valid_from == VALID_FROM_USE_TX_TIME {
f.valid_from = tx_id as i64;
f.valid_from = tx_id.cast_signed();
}
f
})
Expand Down
7 changes: 5 additions & 2 deletions src/graph/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};
use uuid::Uuid;

// ============================================================================
Expand All @@ -20,10 +19,14 @@ pub(crate) fn tx_id_now() -> TxId {
// On WASM browser targets, `std::time::SystemTime::now()` panics.
// Use `js_sys::Date::now()` which returns milliseconds since the Unix
// epoch as an f64 (same precision as `Date.now()` in JavaScript).
js_sys::Date::now() as u64
// Preserve the existing truncating, saturating conversion (including NaN → 0).
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let ms = js_sys::Date::now() as u64;
ms
}
#[cfg(not(all(target_arch = "wasm32", feature = "browser")))]
{
use std::time::{SystemTime, UNIX_EPOCH};
u64::try_from(
SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub(crate) mod query;
pub mod repl;
pub(crate) mod storage;
pub(crate) mod temporal;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod wal;

#[cfg(all(target_arch = "wasm32", feature = "browser"))]
Expand Down
3 changes: 0 additions & 3 deletions src/storage/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ pub use memory::MemoryBackend;
#[cfg(not(target_arch = "wasm32"))]
#[allow(unused_imports)]
pub use file::FileBackend;

#[cfg(all(target_arch = "wasm32", feature = "browser"))]
pub use crate::browser::buffer::BrowserBufferBackend;
1 change: 1 addition & 0 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod backend;
pub mod btree;
pub mod btree_v6;
pub mod cache;
#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod dir_sync;
pub mod index;
pub mod packed_pages;
Expand Down
7 changes: 7 additions & 0 deletions src/storage/persistent_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ impl<B: StorageBackend + 'static> PersistentFactStorage<B> {
/// The `last_checkpointed_tx_count` recorded in the on-disk header.
///
/// Used by WAL replay to skip entries already present in the main file.
#[cfg(not(target_arch = "wasm32"))]
pub fn last_checkpointed_tx_count(&self) -> u64 {
self.last_checkpointed_tx_count
}
Expand All @@ -1078,11 +1079,13 @@ impl<B: StorageBackend + 'static> PersistentFactStorage<B> {
///
/// Used by checkpoint to ensure save() always writes even if no new
/// facts have been added since the last save.
#[cfg(not(target_arch = "wasm32"))]
pub fn force_dirty(&mut self) {
self.mark_dirty();
}

/// Check if storage has unsaved changes
#[cfg(not(target_arch = "wasm32"))]
pub fn is_dirty(&self) -> bool {
self.dirty
}
Expand All @@ -1104,6 +1107,8 @@ impl<B: StorageBackend + 'static> PersistentFactStorage<B> {
where
F: FnOnce(&B) -> R,
{
// Preserve the existing panic on poison; recovering would expose suspect state.
#[allow(clippy::unwrap_used)]
let guard = self.backend.lock().unwrap();
f(&*guard)
}
Expand All @@ -1116,6 +1121,8 @@ impl<B: StorageBackend + 'static> PersistentFactStorage<B> {
where
F: FnOnce(&mut B) -> R,
{
// Preserve the existing panic on poison; recovering would expose suspect state.
#[allow(clippy::unwrap_used)]
let mut guard = self.backend.lock().unwrap();
f(&mut *guard)
}
Expand Down
Loading