feat(compress): move window overflow rebase to Rust

The overflow-correction policy and scalar correction arithmetic were already
Rust-owned, but the stateful window rebase still lived in the C
ZSTD_window_correctOverflow() inline. That left pointer advancement, limit
clamping, and the correction counter as an untracked production C algorithm
on every compression path that protects matchfinder indices.

Replace that inline with a five-pointer projection. C continues to compute the
private source index and choose the correction context, while Rust now owns
the rebasing transition: it advances the regular and dictionary bases, clamps
both limits with the original wrapping U32 behavior, checks the correction
invariants in debug builds, and increments the overflow-correction counter.
The C/Rust projection has explicit layout assertions, and the Rust fixture
covers the pointer, limit, and counter updates together.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 -C tests invalidDictionaries
- ulimit -v 41943040; make -j1 -C tests test
- git diff --check
This commit is contained in:
2026-07-21 16:55:33 +02:00
parent 02d3579da3
commit 8aa7156943
3 changed files with 153 additions and 80 deletions
+11 -2
View File
@@ -6412,8 +6412,17 @@ static U32 ZSTD_rust_overflowCorrect_correct(void* context, const void* src)
state->params->cParams.chainLog,
state->params->cParams.strategy);
U32 const maxDist = (U32)1 << state->params->cParams.windowLog;
return ZSTD_window_correctOverflow(
&state->matchState->window, cycleLog, maxDist, src);
ZSTD_rust_windowOverflowState windowState = {
&state->matchState->window.base,
&state->matchState->window.dictBase,
&state->matchState->window.dictLimit,
&state->matchState->window.lowLimit,
&state->matchState->window.nbOverflowCorrections,
};
U32 const curr = (U32)((BYTE const*)src - state->matchState->window.base);
return ZSTD_rust_windowCorrectOverflowState(
&windowState, curr, cycleLog, maxDist,
ZSTD_WINDOW_OVERFLOW_CORRECT_FREQUENTLY);
}
static void ZSTD_rust_overflowCorrect_markTablesDirty(void* context)