feat(compress): move dictionary match-state publication to Rust

Replace the dictionary loader's C match-state publication callback with a live
field projection. Rust now publishes nextToUpdate, loadedDictEnd, and
forceNonContiguous at the existing orchestration point while C retains the
private match-state layout. Keep the window base indirect so a preceding
window update cannot leave Rust with a stale offset origin.

Test Plan:
- git diff --cached --check
- capped cargo check --tests
- capped cargo clippy --tests -- -A clippy::manual-bits -D warnings
- capped make -j1
- capped make -j1 -C tests test
This commit is contained in:
2026-07-21 22:44:37 +02:00
parent 6b8051b98a
commit 87b616c49b
2 changed files with 149 additions and 34 deletions
+29 -19
View File
@@ -2769,13 +2769,31 @@ typedef void (*ZSTD_rust_loadDictionaryContent_windowUpdate_f)(
void* context, int ldm, const void* src, size_t srcSize);
typedef void (*ZSTD_rust_loadDictionaryContent_setLdmLoadedDictEnd_f)(
void* context, const void* iend, int forceWindow);
typedef void (*ZSTD_rust_loadDictionaryContent_publishMatchState_f)(
void* context, const void* ip, const void* iend,
int forceWindow, int deterministicRefPrefix);
typedef void (*ZSTD_rust_loadDictionaryContent_fillLdm_f)(
void* context, const void* ip, const void* iend);
typedef void (*ZSTD_rust_loadDictionaryContent_overflowCorrect_f)(
void* context, const void* ip, const void* iend);
typedef struct {
const BYTE** base;
U32* nextToUpdate;
U32* loadedDictEnd;
int* forceNonContiguous;
} ZSTD_rust_loadDictionaryContentMatchStatePublicationState;
typedef char ZSTD_rust_load_dictionary_match_state_publication_layout[
(offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState, base)
== 0
&& offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState,
nextToUpdate)
== sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState,
loadedDictEnd)
== 2 * sizeof(void*)
&& offsetof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState,
forceNonContiguous)
== 3 * sizeof(void*)
&& sizeof(ZSTD_rust_loadDictionaryContentMatchStatePublicationState)
== 4 * sizeof(void*))
? 1 : -1];
/* The Fast dictionary-table leaf is implemented in Rust. Keep only the
* fields needed by that leaf in the ABI projection; the complete
* ZSTD_MatchState_t layout remains private to C. */
@@ -2874,7 +2892,7 @@ typedef struct {
ZSTD_rust_loadDictionaryContent_assertWindowEmpty_f assertWindowEmpty;
ZSTD_rust_loadDictionaryContent_windowUpdate_f windowUpdate;
ZSTD_rust_loadDictionaryContent_setLdmLoadedDictEnd_f setLdmLoadedDictEnd;
ZSTD_rust_loadDictionaryContent_publishMatchState_f publishMatchState;
const ZSTD_rust_loadDictionaryContentMatchStatePublicationState* publishMatchState;
ZSTD_rust_loadDictionaryContent_fillLdm_f fillLdm;
ZSTD_rust_loadDictionaryContent_overflowCorrect_f overflowCorrect;
const ZSTD_rust_loadDictionaryContentFastTableState* fastTable;
@@ -6897,20 +6915,6 @@ static void ZSTD_loadDictionaryContent_setLdmLoadedDictEnd(
: (U32)((const BYTE*)iend - context->ldmState->window.base);
}
static void ZSTD_loadDictionaryContent_publishMatchState(
void* opaque, const void* ip, const void* iend,
int forceWindow, int deterministicRefPrefix)
{
ZSTD_loadDictionaryContent_context const* const context =
(const ZSTD_loadDictionaryContent_context*)opaque;
context->matchState->nextToUpdate =
(U32)((const BYTE*)ip - context->matchState->window.base);
context->matchState->loadedDictEnd = forceWindow
? 0
: (U32)((const BYTE*)iend - context->matchState->window.base);
context->matchState->forceNonContiguous = deterministicRefPrefix;
}
static void ZSTD_loadDictionaryContent_fillLdm(
void* opaque, const void* ip, const void* iend)
{
@@ -7026,6 +7030,7 @@ static size_t ZSTD_loadDictionaryContent_callback(
int dtlm, int tfp)
{
ZSTD_loadDictionaryContent_context context;
ZSTD_rust_loadDictionaryContentMatchStatePublicationState matchStatePublication;
ZSTD_rust_loadDictionaryContentFastTableState fastTable;
ZSTD_rust_loadDictionaryContentDoubleFastTableState doubleFastTable;
ZSTD_rust_loadDictionaryContentState state;
@@ -7039,6 +7044,11 @@ static size_t ZSTD_loadDictionaryContent_callback(
context.workspace = ws;
context.params = cctxParams;
matchStatePublication.base = &ms->window.base;
matchStatePublication.nextToUpdate = &ms->nextToUpdate;
matchStatePublication.loadedDictEnd = &ms->loadedDictEnd;
matchStatePublication.forceNonContiguous = &ms->forceNonContiguous;
assert((tfp == ZSTD_tfp_forCDict && dtlm == ZSTD_dtlm_full)
|| (tfp != ZSTD_tfp_forCDict && dtlm == ZSTD_dtlm_fast));
/* These fields are mutated by the window/publish callbacks before the
@@ -7088,7 +7098,7 @@ static size_t ZSTD_loadDictionaryContent_callback(
state.assertWindowEmpty = ZSTD_loadDictionaryContent_assertWindowEmpty;
state.windowUpdate = ZSTD_loadDictionaryContent_windowUpdate;
state.setLdmLoadedDictEnd = ZSTD_loadDictionaryContent_setLdmLoadedDictEnd;
state.publishMatchState = ZSTD_loadDictionaryContent_publishMatchState;
state.publishMatchState = &matchStatePublication;
state.fillLdm = ZSTD_loadDictionaryContent_fillLdm;
state.overflowCorrect = ZSTD_loadDictionaryContent_overflowCorrect;
state.fastTable = &fastTable;