feat(compress): project hash salt entropy into Rust

The row-matchfinder reset path only used its C callback to read the private
hashSaltEntropy scalar and invoke Rust. Replace that callback slot with the
existing 32-bit scalar, keep the ABI offsets pointer-sized on 32-bit and
64-bit targets, and update the salt directly in Rust at the row-table reset
point. Preserve the C workspace callbacks and verify the real salt transition
in the reset-policy test.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests
- ulimit -v 41943040; make -j1
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
2026-07-21 19:45:07 +02:00
parent 5f965b7025
commit 8597c9c4aa
2 changed files with 30 additions and 26 deletions
+8 -12
View File
@@ -1241,7 +1241,6 @@ int ZSTD_rust_simpleCompressStream2Policy(
ZSTD_rust_simpleCompress2Level_f simpleCompress2Level);
int ZSTD_rust_simpleCompressStream2Level(const void* cctx, size_t srcSize);
U32 ZSTD_rust_limitNextToUpdate(U32 curr, U32 nextToUpdate);
void ZSTD_rust_advanceHashSaltInPlace(U64* hashSalt, U64 hashSaltEntropy);
void ZSTD_rust_reduceIndex(U32* hashTable, U32 hashSize,
U32* chainTable, U32 chainSize,
U32* hashTable3, U32 hashSize3,
@@ -1286,7 +1285,6 @@ typedef char ZSTD_rust_overflow_correct_state_layout[
? 1 : -1];
void ZSTD_rust_copyCDictTableIntoCCtx(U32* dst, U32 const* src,
size_t tableSize, int tagged);
U64 ZSTD_rust_advanceHashSalt(U64 hashSalt, U64 hashSaltEntropy);
int ZSTD_indexTooCloseToMax(size_t nextSrcBaseOffset);
int ZSTD_dictTooBig(size_t loadedDictSize);
@@ -1327,7 +1325,7 @@ typedef struct {
ZSTD_rust_resetMatchStateCallback_f invalidateMatchState;
ZSTD_rust_resetMatchStateCallback_f clearTables;
ZSTD_rust_resetMatchStateCallback_f cleanTables;
ZSTD_rust_resetMatchStateCallback_f advanceHashSalt;
unsigned hashSaltEntropy;
ZSTD_rust_resetMatchStateReserve_f reserve;
ZSTD_rust_resetMatchStateReserveFailed_f reserveFailed;
ZSTD_rust_resetMatchStateZero_f zero;
@@ -1341,6 +1339,12 @@ typedef char ZSTD_rust_reset_match_state_layout[
&& offsetof(ZSTD_rust_resetMatchStateState, hashLog3)
== offsetof(ZSTD_rust_resetMatchStateState, optimalSize)
+ sizeof(size_t)
&& offsetof(ZSTD_rust_resetMatchStateState, hashSaltEntropy)
== offsetof(ZSTD_rust_resetMatchStateState, cleanTables)
+ sizeof(void*)
&& offsetof(ZSTD_rust_resetMatchStateState, reserve)
== offsetof(ZSTD_rust_resetMatchStateState, hashSaltEntropy)
+ sizeof(void*)
&& offsetof(ZSTD_rust_resetMatchStateState, setPointer)
== offsetof(ZSTD_rust_resetMatchStateState, cParamsOut)
+ sizeof(void*)
@@ -4994,14 +4998,6 @@ static void ZSTD_rust_resetMatchState_cleanTables(void* opaque)
ZSTD_cwksp_clean_tables(context->ws);
}
static void ZSTD_rust_resetMatchState_advanceHashSalt(void* opaque)
{
ZSTD_rust_resetMatchStateContext* const context =
(ZSTD_rust_resetMatchStateContext*)opaque;
ZSTD_rust_advanceHashSaltInPlace(
&context->ms->hashSalt, (U64)context->ms->hashSaltEntropy);
}
static void* ZSTD_rust_resetMatchState_reserve(
void* opaque, int reserveKind, size_t size)
{
@@ -5115,7 +5111,7 @@ ZSTD_reset_matchState(ZSTD_MatchState_t* ms,
state.invalidateMatchState = ZSTD_rust_resetMatchState_invalidate;
state.clearTables = ZSTD_rust_resetMatchState_clearTables;
state.cleanTables = ZSTD_rust_resetMatchState_cleanTables;
state.advanceHashSalt = ZSTD_rust_resetMatchState_advanceHashSalt;
state.hashSaltEntropy = ms->hashSaltEntropy;
state.reserve = ZSTD_rust_resetMatchState_reserve;
state.reserveFailed = ZSTD_rust_resetMatchState_reserveFailed;
state.zero = ZSTD_rust_resetMatchState_zero;