refactor(compress): remove obsolete C block adapters

Remove the unreachable C target-sized and split-block adapters now that frame chunks use the direct Rust state projections. The C sequence-store wrapper was likewise unused after those adapters disappeared.

Keep the target and split callback slots as nullable Rust test seams and return a generic error if a caller selects a callback fallback without providing one. Production frame-chunk state now leaves both slots null because the direct projections are authoritative.

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
- 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 02:13:29 +02:00
parent 93eaef18b8
commit 919d138f02
2 changed files with 22 additions and 168 deletions
+2 -154
View File
@@ -1954,17 +1954,6 @@ void ZSTD_rust_resetSeqStore(SeqStore_t* ssPtr);
void ZSTD_rust_validateSeqStore(const SeqStore_t* seqStore, U32 minMatch);
BlockSummary ZSTD_rust_get1BlockSummary(const ZSTD_Sequence* seqs,
size_t nbSeqs);
size_t ZSTD_rust_deriveBlockSplits(
U32* partitions, U32 nbSeq,
const SeqStore_t* originalSeqStore,
SeqStore_t* fullSeqStoreChunk,
SeqStore_t* firstHalfSeqStore,
SeqStore_t* secondHalfSeqStore,
const ZSTD_entropyCTables_t* prevEntropy,
ZSTD_entropyCTables_t* nextEntropy,
int strategy, int disableLiteralCompression,
ZSTD_entropyCTablesMetadata_t* entropyMetadata,
void* workspace, size_t workspaceSize);
U32 ZSTD_rust_resolveRepcodeToRawOffset(const U32 rep[ZSTD_REP_NUM],
U32 offBase, U32 ll0);
size_t ZSTD_rust_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
@@ -5109,8 +5098,6 @@ static size_t ZSTD_rust_externalSequenceProducer_transfer(
zc->appliedParams.searchForExternalRepcodes);
}
typedef enum { ZSTDbss_compress, ZSTDbss_noCompress } ZSTD_BuildSeqStore_e;
static void ZSTD_rust_buildSeqStore_skipSmallBlock(void* context, size_t srcSize)
{
ZSTD_CCtx* const zc = (ZSTD_CCtx*)context;
@@ -5267,13 +5254,6 @@ static void ZSTD_initBuildSeqStoreState(
state->clearLdmSeqStore = ZSTD_rust_buildSeqStore_clearLdmSeqStore;
}
static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
{
ZSTD_rust_buildSeqStoreState state;
ZSTD_initBuildSeqStoreState(zc, &state);
return ZSTD_rust_buildSeqStore(&state, src, srcSize);
}
/* ZSTD_sequenceBound() lives in rust/src/zstd_compress_api.rs. */
size_t ZSTD_generateSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
@@ -5338,122 +5318,6 @@ size_t ZSTD_buildBlockEntropyStats(
workspace, wkspSize);
}
/* ZSTD_compressBlock_splitBlock():
* Attempts to split a given block into multiple blocks to improve compression ratio.
*
* Returns combined size of all blocks (which includes headers), or a ZSTD error code.
*/
static size_t
ZSTD_compressBlock_splitBlock_internal(ZSTD_CCtx* zc,
void* dst, size_t dstCapacity,
const void* src, size_t blockSize,
U32 lastBlock, U32 nbSeq, int bss)
{
ZSTD_rust_splitBlockState state;
U32* const partitions = zc->blockSplitCtx.partitions; /* splits plus the terminal boundary */
size_t numSplits = 0;
if (bss == ZSTDbss_compress) {
ZSTD_rust_deriveBlockSplitsState deriveState;
deriveState.originalSeqStore = &zc->seqStore;
deriveState.fullSeqStoreChunk = &zc->blockSplitCtx.fullSeqStoreChunk;
deriveState.firstHalfSeqStore = &zc->blockSplitCtx.firstHalfSeqStore;
deriveState.secondHalfSeqStore = &zc->blockSplitCtx.secondHalfSeqStore;
deriveState.prevCBlock = &zc->blockState.prevCBlock;
deriveState.nextCBlock = &zc->blockState.nextCBlock;
deriveState.entropyMetadata = &zc->blockSplitCtx.entropyMetadata;
deriveState.workspace = zc->tmpWorkspace;
deriveState.workspaceSize = zc->tmpWkspSize;
deriveState.strategy = (int)zc->appliedParams.cParams.strategy;
deriveState.disableLiteralCompression =
ZSTD_literalsCompressionIsDisabled(&zc->appliedParams);
numSplits = ZSTD_rust_deriveBlockSplits(
partitions, nbSeq,
deriveState.originalSeqStore,
deriveState.fullSeqStoreChunk,
deriveState.firstHalfSeqStore,
deriveState.secondHalfSeqStore,
&deriveState.prevCBlock[0]->entropy,
&deriveState.nextCBlock[0]->entropy,
deriveState.strategy,
deriveState.disableLiteralCompression,
deriveState.entropyMetadata,
deriveState.workspace,
deriveState.workspaceSize);
FORWARD_IF_ERROR(numSplits, "Deriving block splits failed!");
}
DEBUGLOG(5, "ZSTD_compressBlock_splitBlock_internal (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u)",
(unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit,
(unsigned)zc->blockState.matchState.nextToUpdate);
state.seqStore = &zc->seqStore;
state.partitions = partitions;
state.nextSeqStore = &zc->blockSplitCtx.nextSeqStore;
state.currSeqStore = &zc->blockSplitCtx.currSeqStore;
state.prevCBlock = &zc->blockState.prevCBlock;
state.nextCBlock = &zc->blockState.nextCBlock;
state.tmpWorkspace = zc->tmpWorkspace;
state.tmpWkspSize = zc->tmpWkspSize;
state.seqCollector = &zc->seqCollector;
state.blockSizeMax = zc->blockSizeMax;
state.strategy = (int)zc->appliedParams.cParams.strategy;
state.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&zc->appliedParams);
state.bmi2 = zc->bmi2;
state.isFirstBlock = zc->isFirstBlock;
return ZSTD_rust_compressBlockSplitAfterBuild(
&state, dst, dstCapacity, src, blockSize, lastBlock,
numSplits, bss);
}
static size_t
ZSTD_compressBlock_splitBlock(ZSTD_CCtx* zc,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize, U32 lastBlock)
{
U32 nbSeq;
size_t cSize;
size_t const bss = ZSTD_buildSeqStore(zc, src, srcSize);
DEBUGLOG(5, "ZSTD_compressBlock_splitBlock");
assert(zc->appliedParams.postBlockSplitter == ZSTD_ps_enable);
FORWARD_IF_ERROR(bss, "ZSTD_buildSeqStore failed");
nbSeq = (U32)(zc->seqStore.sequences - zc->seqStore.sequencesStart);
cSize = ZSTD_compressBlock_splitBlock_internal(
zc, dst, dstCapacity, src, srcSize, lastBlock, nbSeq, (int)bss);
FORWARD_IF_ERROR(cSize, "Splitting blocks failed!");
return cSize;
}
static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
void* dst, size_t dstCapacity,
const void* src, size_t srcSize,
U32 lastBlock)
{
size_t cSize;
size_t const bss = ZSTD_buildSeqStore(zc, src, srcSize);
DEBUGLOG(5, "ZSTD_compressBlock_targetCBlockSize (dstCapacity=%u, dictLimit=%u, nextToUpdate=%u, srcSize=%zu)",
(unsigned)dstCapacity, (unsigned)zc->blockState.matchState.window.dictLimit, (unsigned)zc->blockState.matchState.nextToUpdate, srcSize);
FORWARD_IF_ERROR(bss, "ZSTD_buildSeqStore failed");
{ ZSTD_rust_targetCBlockSizeState state;
state.seqStore = &zc->seqStore;
state.prevCBlock = &zc->blockState.prevCBlock;
state.nextCBlock = &zc->blockState.nextCBlock;
state.tmpWorkspace = zc->tmpWorkspace;
state.tmpWkspSize = zc->tmpWkspSize;
state.strategy = (int)zc->appliedParams.cParams.strategy;
state.disableLiteralCompression = ZSTD_literalsCompressionIsDisabled(&zc->appliedParams);
state.bmi2 = zc->bmi2;
state.windowLog = zc->appliedParams.cParams.windowLog;
state.targetCBlockSize = zc->appliedParams.targetCBlockSize;
state.isFirstBlock = zc->isFirstBlock;
cSize = ZSTD_rust_compressBlockTargetCBlockSizeAfterBuild(
&state, dst, dstCapacity, src, srcSize, (int)bss, lastBlock);
}
FORWARD_IF_ERROR(cSize, "ZSTD_compressBlock_targetCBlockSize_body failed");
return cSize;
}
typedef struct {
ZSTD_MatchState_t* matchState;
ZSTD_cwksp* workspace;
@@ -5598,22 +5462,6 @@ static void ZSTD_rust_frameChunk_enforceMaxDist(void* context,
(void)blockSize;
}
static size_t ZSTD_rust_frameChunk_compressTarget(
void* context, void* dst, size_t dstCapacity,
const void* src, size_t srcSize, U32 lastBlock)
{
return ZSTD_compressBlock_targetCBlockSize(
(ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize, lastBlock);
}
static size_t ZSTD_rust_frameChunk_compressSplit(
void* context, void* dst, size_t dstCapacity,
const void* src, size_t srcSize, U32 lastBlock)
{
return ZSTD_compressBlock_splitBlock(
(ZSTD_CCtx*)context, dst, dstCapacity, src, srcSize, lastBlock);
}
static void ZSTD_compressContinue_prepare(
ZSTD_CCtx* cctx, size_t blockSizeMax, int checkBlockSize,
ZSTD_rust_compressContinueContext* context)
@@ -5660,8 +5508,8 @@ static void ZSTD_compressContinue_prepare(
context->frameChunkState.checksumFlag = cctx->appliedParams.fParams.checksumFlag;
context->frameChunkState.endingStage = (int)ZSTDcs_ending;
context->frameChunkState.prepareState = &context->frameChunkPrepareState;
context->frameChunkState.compressTarget = ZSTD_rust_frameChunk_compressTarget;
context->frameChunkState.compressSplit = ZSTD_rust_frameChunk_compressSplit;
context->frameChunkState.compressTarget = NULL;
context->frameChunkState.compressSplit = NULL;
context->frameChunkState.compressInternal = NULL;
context->frameChunkState.compressTargetState = &context->targetBlockState;
context->frameChunkState.compressSplitState = &context->splitBlockState;
+20 -14
View File
@@ -640,8 +640,8 @@ pub struct ZSTD_rust_frameChunkState {
checksum_flag: c_int,
ending_stage: c_int,
prepare_state: *const ZSTD_rust_frameChunkPrepareState,
compress_target: FrameChunkCompressFn,
compress_split: FrameChunkCompressFn,
compress_target: Option<FrameChunkCompressFn>,
compress_split: Option<FrameChunkCompressFn>,
compress_internal: Option<FrameChunkCompressFn>,
compress_internal_state: *const ZSTD_rust_compressContinueBlockState,
compress_target_state: *const ZSTD_rust_targetCBlockSizeState,
@@ -828,8 +828,11 @@ unsafe fn compress_frame_chunk_body_with(
)
}
} else {
let Some(compress_target) = state.compress_target else {
return ERROR(ZstdErrorCode::Generic);
};
unsafe {
(state.compress_target)(
compress_target(
state.callback_context,
op.cast(),
remaining_capacity,
@@ -935,8 +938,11 @@ unsafe fn compress_frame_chunk_body_with(
)
}
} else {
let Some(compress_split) = state.compress_split else {
return ERROR(ZstdErrorCode::Generic);
};
unsafe {
(state.compress_split)(
compress_split(
state.callback_context,
op.cast(),
remaining_capacity,
@@ -10612,8 +10618,8 @@ mod tests {
checksum_flag: 0,
ending_stage: ZSTD_COMPRESSION_STAGE_ENDING,
prepare_state: frame_chunk_prepare_state,
compress_target: compress_end_test_frame_target,
compress_split: compress_end_test_frame_target,
compress_target: Some(compress_end_test_frame_target),
compress_split: Some(compress_end_test_frame_target),
compress_internal: Some(compress_end_test_frame_target),
compress_internal_state: ptr::null(),
compress_target_state: ptr::null(),
@@ -11491,8 +11497,8 @@ mod tests {
checksum_flag,
ending_stage: 77,
prepare_state,
compress_target: frame_chunk_test_target,
compress_split: frame_chunk_test_split,
compress_target: Some(frame_chunk_test_target),
compress_split: Some(frame_chunk_test_split),
compress_internal: Some(frame_chunk_test_internal),
compress_internal_state: ptr::null(),
compress_target_state: ptr::null(),
@@ -11834,8 +11840,8 @@ mod tests {
checksum_flag: 0,
ending_stage: ZSTD_COMPRESSION_STAGE_ENDING,
prepare_state: frame_chunk_prepare_state,
compress_target: compress_continue_test_frame,
compress_split: compress_continue_test_frame,
compress_target: Some(compress_continue_test_frame),
compress_split: Some(compress_continue_test_frame),
compress_internal: Some(compress_continue_test_frame),
compress_internal_state: ptr::null(),
compress_target_state: ptr::null(),
@@ -12323,8 +12329,8 @@ mod tests {
checksum_flag: 0,
ending_stage: ZSTD_COMPRESSION_STAGE_ENDING,
prepare_state: frame_chunk_prepare_state,
compress_target: compress_stream_test_block,
compress_split: compress_stream_test_block,
compress_target: Some(compress_stream_test_block),
compress_split: Some(compress_stream_test_block),
compress_internal: Some(compress_stream_test_block),
compress_internal_state: ptr::null(),
compress_target_state: ptr::null(),
@@ -12351,8 +12357,8 @@ mod tests {
checksum_flag: 0,
ending_stage: ZSTD_COMPRESSION_STAGE_ENDING,
prepare_state: frame_chunk_prepare_state,
compress_target: compress_stream_test_end,
compress_split: compress_stream_test_end,
compress_target: Some(compress_stream_test_end),
compress_split: Some(compress_stream_test_end),
compress_internal: Some(compress_stream_test_end),
compress_internal_state: ptr::null(),
compress_target_state: ptr::null(),