Skip to content

Conversation

@DavePearce
Copy link
Collaborator

@DavePearce DavePearce commented Nov 26, 2025

This adds support for encoding constant arrays, rather than just zero arrays.


Note

Introduce ConstantArray and its encoding (replacing zero-array), switch encoding operand to 24-bit uint32, and make Pad return MutArray with callers updated.

  • Arrays:
    • Constant arrays: Add ConstantArray (replaces zero-array usage) with NewConstantArray, validation in Append/Set/Pad, and propagation across builders when bitwidth==0.
    • Pad API: MutArray.Pad now returns MutArray[T]; update implementations (BitArray, SmallArray, StaticArray, PoolArray) and usage in trace/ArrayColumn.pad.
  • Encoding:
    • Rename ENCODING_ZEROENCODING_CONSTANT; implement encode_constant/decode_constant.
    • Widen instruction operand to 24-bit uint32 (Encoding.Operand/Set), adjust bitwidth handling and pool encodings to use uint32.
  • Legacy Reader:
    • For 16-bit columns with max==0, emit ConstantArray of zeros (bitwidth 0); minor variable additions to support this.

Written by Cursor Bugbot for commit ffcbff4. This will update automatically on new commits. Configure here.

This adds support for encoding constant arrays, rather than just zero
arrays.
@DavePearce DavePearce linked an issue Nov 26, 2025 that may be closed by this pull request
}

func encode_zero[T word.DynamicWord[T]](array *ZeroArray[T]) []byte {
func encode_constant[T word.DynamicWord[T]](array *ConstantArray[T]) []byte {
Copy link

Choose a reason for hiding this comment

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

Bug: Constant value lost during array encoding

The encode_constant function only encodes the array length but discards the constant value. During decoding, decode_constant attempts to retrieve the value from the operand field (which contains bitwidth, always 0 for constant arrays), causing all constant arrays to be decoded with value 0 regardless of their original value. The constant value must be encoded and later decoded to preserve non-zero constants.

Additional Locations (1)

Fix in Cursor Fix in Web

encoding.Bytes = encode_zero(array.(*ZeroArray[T]))
encoding.Set(ENCODING_ZERO, bitwidth)
encoding.Bytes = encode_constant(array.(*ConstantArray[T]))
encoding.Set(ENCODING_CONSTANT, 0)
Copy link

Choose a reason for hiding this comment

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

Bug: Constant value lost during encode/decode cycle

When encoding a ConstantArray, the operand is hardcoded to 0 and the actual constant value is never stored. During decode, encoding.Operand() returns 0, so any non-zero constant array will be incorrectly reconstructed as a zero array. The encode_constant function must encode the constant value (via the operand field) so it can be retrieved during decoding.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

feat: further optimise ltv2 file format

2 participants