refactor(mt): move active parameter transition policy to Rust
ZSTDMT_updateCParams_whileCompressing already delegated parameter derivation to Rust, but C still owned the transition publication order and independently updated compressionLevel. Return a Rust-owned scalar result that carries the requested level with the derived compression parameters, while preserving the active frame window and all private MT context state in C.\n\nThe new projection and result have explicit C/Rust layout assertions. Focused Rust tests exercise unknown-size and explicit-size hints, LDM and override inputs, saved-window restoration, requested-level forwarding, and the exported ABI wrapper.\n\nTest Plan:\n- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo fmt/clippy gates passed before staging\n- git diff --cached --check\n- Full capped native and original-test verification follows after the batch is committed.
This commit is contained in:
@@ -25,8 +25,9 @@
|
||||
#include "zstd_ldm.h"
|
||||
#include "zstdmt_compress.h"
|
||||
|
||||
/* The Rust parameter leaf receives only this scalar snapshot. Keep the
|
||||
* private ZSTDMT_CCtx and ZSTD_CCtx_params layouts in this translation unit. */
|
||||
/* The Rust MT parameter-update policy receives only this scalar snapshot.
|
||||
* Keep the private ZSTDMT_CCtx and ZSTD_CCtx_params layouts in this
|
||||
* translation unit. */
|
||||
typedef struct {
|
||||
int compressionLevel;
|
||||
int cctxSrcSizeHint;
|
||||
@@ -65,7 +66,18 @@ typedef char ZSTDMT_rust_cparams_update_projection_layout[
|
||||
== (sizeof(void*) == 8 ? 80 : 72))
|
||||
? 1 : -1];
|
||||
|
||||
ZSTD_compressionParameters ZSTD_rust_params_updateCParamsWhileCompressing(
|
||||
typedef struct {
|
||||
int compressionLevel;
|
||||
ZSTD_compressionParameters cParams;
|
||||
} ZSTDMT_RustCParamsUpdateResult;
|
||||
typedef char ZSTDMT_rust_cparams_update_result_layout[
|
||||
(offsetof(ZSTDMT_RustCParamsUpdateResult, compressionLevel) == 0
|
||||
&& offsetof(ZSTDMT_RustCParamsUpdateResult, cParams) == sizeof(int)
|
||||
&& sizeof(ZSTDMT_RustCParamsUpdateResult)
|
||||
== sizeof(int) + sizeof(ZSTD_compressionParameters))
|
||||
? 1 : -1];
|
||||
|
||||
ZSTDMT_RustCParamsUpdateResult ZSTDMT_rust_updateCParamsWhileCompressing(
|
||||
ZSTDMT_RustCParamsUpdateProjection projection);
|
||||
|
||||
/* Defined in zstd_compress.c so all C translation units use the same
|
||||
@@ -2571,10 +2583,8 @@ static size_t ZSTDMT_resize(ZSTDMT_CCtx* mtctx, unsigned nbWorkers)
|
||||
void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams)
|
||||
{
|
||||
U32 const saved_wlog = mtctx->params.cParams.windowLog; /* Do not modify windowLog while compressing */
|
||||
int const compressionLevel = cctxParams->compressionLevel;
|
||||
DEBUGLOG(5, "ZSTDMT_updateCParams_whileCompressing (level:%i)",
|
||||
compressionLevel);
|
||||
mtctx->params.compressionLevel = compressionLevel;
|
||||
cctxParams->compressionLevel);
|
||||
{ ZSTDMT_RustCParamsUpdateProjection const projection = {
|
||||
cctxParams->compressionLevel,
|
||||
cctxParams->srcSizeHint,
|
||||
@@ -2588,8 +2598,10 @@ void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_p
|
||||
ZSTD_getCParamsExclusionMask(),
|
||||
saved_wlog
|
||||
};
|
||||
mtctx->params.cParams =
|
||||
ZSTD_rust_params_updateCParamsWhileCompressing(projection);
|
||||
ZSTDMT_RustCParamsUpdateResult const result =
|
||||
ZSTDMT_rust_updateCParamsWhileCompressing(projection);
|
||||
mtctx->params.compressionLevel = result.compressionLevel;
|
||||
mtctx->params.cParams = result.cParams;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user