Skip to content

Conversation

@algebraic-dev
Copy link
Member

@algebraic-dev algebraic-dev commented Jan 24, 2026

This PR introduces the Body type class, the ChunkStream and Full types that are used to represent streaming bodies of Requests and Responses.

This contains the same code as #10478, divided into separate pieces to facilitate easier review.

The pieces of this feature are:

@algebraic-dev algebraic-dev self-assigned this Jan 24, 2026
@algebraic-dev algebraic-dev requested a review from TwoFX as a code owner January 24, 2026 22:50
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 25, 2026
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0a0323734b2d10c3f9355659f8e44b67bd36f644 --onto 4c1e4a77b4952098ea043f9b8c2d155c20b24523. You can force Mathlib CI using the force-mathlib-ci label. (2026-01-25 00:53:54)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 0a0323734b2d10c3f9355659f8e44b67bd36f644 --onto e9a1c9ef63d8e53803c16077f03e2dacd4a890bd. You can force reference manual CI using the force-manual-ci label. (2026-01-25 00:53:55)

-/
def size? (_ : Empty) : Async (Option Body.Length) :=
pure (some (.fixed 0))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says "Returns none" but the implementation returns some (.fixed 0).

c[0]'(Nat.le_of_eq h)
else
c.data.foldl (· ++ ·) (.emptyWithCapacity c.size)
c.foldl (· ++ ·) (.emptyWithCapacity c.size)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After let c := c.data.toArray, the name c is shadowed. Now c.size in .emptyWithCapacity c.size is the number of ByteArrays in the queue, not the total byte count. The original code used the struct's size field (total bytes) for pre-allocation.

Should this be something like:

def toByteArray (cb : ChunkedBuffer) : ByteArray :=
  let arr := cb.data.toArray
  if h : 1 = arr.size then
    arr[0]'(Nat.le_of_eq h)
  else
    arr.foldl (· ++ ·) (.emptyWithCapacity cb.size)

-/
@[inline]
def append (buffer : ChunkedBuffer) (data : ChunkedBuffer) : ChunkedBuffer :=
{ data := buffer.data.enqueueAll data.data.toArray.toList.reverse, size := buffer.size + data.size }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .reverse here is correct but non-obvious—I initially thought it was a bug. Queue.enqueueAll prepends to eList, so reversing is needed to maintain FIFO order after the internal reversal during toArray/dequeue?.

Would a brief comment help future readers? Something like:

-- Queue.enqueueAll prepends to eList, so reverse to maintain FIFO order

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants