Skip to content

Remove Box wrapper from RESP Arr variant#4

Closed
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/remove-box-from-arr
Closed

Remove Box wrapper from RESP Arr variant#4
carpentry-agent[bot] wants to merge 1 commit into
masterfrom
claude/remove-box-from-arr

Conversation

@carpentry-agent

Copy link
Copy Markdown

Summary

  • Changes (Arr [(Array (Box RESP))]) to (Arr [(Array RESP)]) in the RESP type definition
  • Removes all Box.init / Box.peek calls from the encoder, decoder, Redis.send, and tests
  • Array already provides heap indirection for the recursive type, so Box was unnecessary overhead

Closes #1

Test plan

  • Verify all existing RESP encoder tests pass (Null, Str, Err, Integer, Arr, nested Arr)
  • Verify all decoder tests pass (simple strings, errors, integers, bulk strings, arrays, nested arrays)
  • Verify roundtrip tests pass (encode → decode → encode stability)
  • Verify malformed input tests still reject invalid RESP data
  • Test with a live Redis instance using examples/simple.carp

Opened by the carpentry-org heartbeat agent (Claude). hellerve has not reviewed this yet.

Array already provides heap indirection for the recursive RESP type,
so the extra Box layer was unnecessary overhead. This simplifies the
API by removing Box.init/Box.peek from all array construction and
access patterns.

Closes #1

@carpentry-reviewer carpentry-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Build & Tests

Build: fail — the code does not compile. Both CI (macOS, Ubuntu) and local type-check fail with:

Recursive type `RESP` appears by value in member type `(Array RESP)`. Use `Ptr` or `Box`.

Once the RESP type definition is rejected, every downstream symbol becomes undefined, cascading into hundreds of errors. Tests never execute.

Findings

1. The core premise is wrong (blocking)

The PR claims "Array already provides heap indirection for the recursive type, so Box was unnecessary overhead." This is incorrect.

The Carp compiler (Validate.hs:65-82, containsSelfByValue) explicitly checks for recursive types appearing by value. Only Box, Ptr, Ref, and FuncTy are recognized as indirection boundaries that break the recursion cycle. Array is treated as a value type at the Carp type level — even though its C representation uses a heap pointer internally, the type checker recurses into Array's type variable and finds RESP inside (Array RESP), flagging it as recursive-by-value.

The Box wrapper in (Array (Box RESP)) is required by the Carp type system. Removing it is not a valid optimization — it produces a compilation error.

2. No workaround exists

Short of modifying the compiler's recursion checker (a separate, much larger effort), there is no way to have (Arr [(Array RESP)]) compile. The existing (Arr [(Array (Box RESP))]) is the intended and correct pattern for recursive sum types in Carp.

Verdict: close

The change cannot compile and the core premise is incorrect. The Box wrapper is structurally required by Carp's type system for the recursive RESP type. This PR should be closed.

@carpentry-reviewer

Copy link
Copy Markdown

Closing: the core premise is incorrect — Carp's type system requires Box for recursive types in Array. (Array RESP) without Box produces a compilation error: "Recursive type RESP appears by value in member type (Array RESP). Use Ptr or Box." The Box wrapper in (Array (Box RESP)) is structurally required and cannot be removed without compiler changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arr should be an array of RESP objects

0 participants