feat(compress): route target blocks through Rust

Project the target-sized block state into frame-chunk compression and invoke
Rust sequence-store construction followed by the existing target-block
post-build leaf. Refresh the per-block isFirstBlock snapshot to preserve the
former C adapter's behavior while leaving the split-block branch on its
existing callback path for a later seam.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo fmt --manifest-path rust/Cargo.toml --all -- --check
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --lib 'zstd_compress::tests::frame_chunk' -- --nocapture
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --lib
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; make -j1
- ulimit -v 41943040; make -j1 -C tests test-zstream ZSTREAM_TESTTIME=-T2s
- ulimit -v 41943040; make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
This commit is contained in:
2026-07-20 01:47:02 +02:00
parent 9605174324
commit 7384301955
2 changed files with 76 additions and 13 deletions
+22 -3
View File
@@ -817,6 +817,8 @@ typedef char ZSTD_rust_frame_chunk_prepare_state_layout[
? 1 : -1];
typedef struct ZSTD_rust_compressContinueBlockState_s
ZSTD_rust_compressContinueBlockState;
typedef struct ZSTD_rust_targetCBlockSizeState_s
ZSTD_rust_targetCBlockSizeState;
typedef size_t (*ZSTD_rust_frameChunkCompress_f)(void* context,
void* dst,
size_t dstCapacity,
@@ -843,6 +845,7 @@ typedef struct {
ZSTD_rust_frameChunkCompress_f compressSplit;
ZSTD_rust_frameChunkCompress_f compressInternal;
const ZSTD_rust_compressContinueBlockState* compressInternalState;
const ZSTD_rust_targetCBlockSizeState* compressTargetState;
} ZSTD_rust_frameChunkState;
size_t ZSTD_rust_compressFrameChunk(
const ZSTD_rust_frameChunkState* state,
@@ -874,8 +877,10 @@ typedef char ZSTD_rust_frame_chunk_state_layout[
== 7 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int)
&& offsetof(ZSTD_rust_frameChunkState, compressInternalState)
== 11 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int)
&& offsetof(ZSTD_rust_frameChunkState, compressTargetState)
== 12 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int)
&& sizeof(ZSTD_rust_frameChunkState)
== 12 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int))
== 13 * sizeof(void*) + sizeof(S64) + 6 * sizeof(int))
? 1 : -1];
/* The high-level continue/block entry points are Rust-owned. This projection
@@ -1244,7 +1249,7 @@ size_t ZSTD_rust_compressStreamInit(
/* The target-sized block body only needs this narrow projection of ZSTD_CCtx.
* Matchfinder/window state, sequence-store construction, and outer repeat-mode
* cleanup remain in C. */
typedef struct {
struct ZSTD_rust_targetCBlockSizeState_s {
const SeqStore_t* seqStore;
ZSTD_compressedBlockState_t** prevCBlock;
ZSTD_compressedBlockState_t** nextCBlock;
@@ -1256,7 +1261,7 @@ typedef struct {
U32 windowLog;
size_t targetCBlockSize;
int isFirstBlock;
} ZSTD_rust_targetCBlockSizeState;
};
size_t ZSTD_rust_compressBlockTargetCBlockSize(
const ZSTD_rust_targetCBlockSizeState* state,
void* dst, size_t dstCapacity,
@@ -5426,6 +5431,7 @@ typedef struct {
ZSTD_rust_buildSeqStoreState buildSeqStoreState;
ZSTD_rust_blockInternalState blockInternalState;
ZSTD_rust_compressContinueBlockState blockState;
ZSTD_rust_targetCBlockSizeState targetBlockState;
} ZSTD_rust_compressContinueContext;
static int ZSTD_rust_overflowCorrect_need(
@@ -5604,6 +5610,7 @@ static void ZSTD_compressContinue_prepare(
context->frameChunkState.compressTarget = ZSTD_rust_frameChunk_compressTarget;
context->frameChunkState.compressSplit = ZSTD_rust_frameChunk_compressSplit;
context->frameChunkState.compressInternal = NULL;
context->frameChunkState.compressTargetState = &context->targetBlockState;
ZSTD_initBuildSeqStoreState(cctx, &context->buildSeqStoreState);
context->blockInternalState.seqStore = &cctx->seqStore;
@@ -5620,6 +5627,18 @@ static void ZSTD_compressContinue_prepare(
context->blockState.buildSeqStoreState = &context->buildSeqStoreState;
context->blockState.blockInternalState = &context->blockInternalState;
context->frameChunkState.compressInternalState = &context->blockState;
context->targetBlockState.seqStore = &cctx->seqStore;
context->targetBlockState.prevCBlock = &cctx->blockState.prevCBlock;
context->targetBlockState.nextCBlock = &cctx->blockState.nextCBlock;
context->targetBlockState.tmpWorkspace = cctx->tmpWorkspace;
context->targetBlockState.tmpWkspSize = cctx->tmpWkspSize;
context->targetBlockState.strategy = (int)cctx->appliedParams.cParams.strategy;
context->targetBlockState.disableLiteralCompression =
ZSTD_literalsCompressionIsDisabled(&cctx->appliedParams);
context->targetBlockState.bmi2 = cctx->bmi2;
context->targetBlockState.windowLog = cctx->appliedParams.cParams.windowLog;
context->targetBlockState.targetCBlockSize = cctx->appliedParams.targetCBlockSize;
context->targetBlockState.isFirstBlock = cctx->isFirstBlock;
context->overflowContext.matchState = ms;
context->overflowContext.workspace = &cctx->workspace;