reduce: name the shared key container to fix HRTB normalization - #797
Merged
frankmcsherry merged 1 commit intoJul 14, 2026
Merged
Conversation
`reduce_abelian` / `reduce_core` / `reduce_trace` equated the output cursor's key to the *input* cursor's key projection (`for<'a> Key<'a> = BatchKey<'a, Tr1>`). That higher-ranked projection-to-projection bound fails to normalize when both trace types are generic (a reduce operator generic over both traces) and keyed by a non-reference GAT such as a columnar `Ref` -- the shape the Materialize master-next port hits. The failure is `error[E0271]: expected <_ as Cursor>::Key, found <the key>` at the wrapper's call site. Introduce a named key-container parameter `KC`: the input pins it via `KeyContainer = KC` (uniquely inferable, since the input is concrete at a call site), and both cursor keys are equated to `KC::ReadItem<'a>`, leaving projection-to-named-type, which the solver does normalize. The explicit `Key<'a> = KC::ReadItem<'a>` bound on the input is stated because the solver does not derive it from `KeyContainer = KC` under `for<'a>`, and the internal `CursorTactic` needs it to equate the two cursors' keys. Key-type semantics are unchanged. This is the same technique already used for `Diff = R1/R2` in `join_core`. A wrapper generic over both traces (the `mz_reduce_abelian` shape) satisfies these bounds by forwarding `KC` and pinning `KeyContainer = KC` on both of its own traces, so `KC` stays inferable from the named output spine at its call sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
frankmcsherry
force-pushed
the
reduce-named-key-container
branch
from
July 13, 2026 23:49
26f11da to
fc64c78
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reduce_abelian/reduce_core/reduce_traceequated the output cursor's key to the input cursor's key projection(
for<'a> Key<'a> = BatchKey<'a, Tr1>). That higher-ranked projection-to-projection bound fails to normalize when both trace types are generic (a reduce operator generic over both traces) and keyed by a non-reference GAT such as a columnarRef-- the shape the Materialize master-next port hits. The failure iserror[E0271]: expected <_ as Cursor>::Key, found <the key>at the wrapper's call site.Introduce a named key-container parameter
KC: the input pins it viaKeyContainer = KC(uniquely inferable, since the input is concrete at a call site), and both cursor keys are equated toKC::ReadItem<'a>, leaving projection-to-named-type, which the solver does normalize. The explicitKey<'a> = KC::ReadItem<'a>bound on the input is stated because the solver does not derive it fromKeyContainer = KCunderfor<'a>, and the internalCursorTacticneeds it to equate the two cursors' keys. Key-type semantics are unchanged. This is the same technique already used forDiff = R1/R2injoin_core.A wrapper generic over both traces (the
mz_reduce_abelianshape) satisfies these bounds by forwardingKCand pinningKeyContainer = KCon both of its own traces, soKCstays inferable from the named output spine at its call sites.