Skip to content

Conversation

@ensi321
Copy link
Contributor

@ensi321 ensi321 commented Oct 21, 2025

  • Fix chunk index calculation for vector/list of basic type when getting and setting element
  • Use toValuePacked when getting basic type
  • Correctly set/get a single bit in BoolType().tree

@gemini-code-assist
Copy link

Summary of Changes

Hello @ensi321, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the handling of basic type vectors and lists within the TreeView component, specifically addressing how elements are indexed, retrieved, and stored. The changes ensure that operations on packed basic types, such as booleans, are performed with correct chunk and bit-level precision, leading to more robust and accurate data management.

Highlights

  • Chunk Index Calculation: Introduced new helper functions (elementsPerChunk, chunkIndex, elementOffset) to correctly calculate chunk indices and offsets for basic type vectors and lists when accessing or modifying elements.
  • Basic Type Element Access: The getElement function now correctly uses toValuePacked along with the newly calculated elementOffset to retrieve values for basic types, ensuring proper packing and unpacking.
  • Boolean Type Bit Manipulation: Fixed the BoolType().tree implementation to accurately set and get individual bits within a 32-byte hash, resolving an issue where it was incorrectly treating each byte as a separate boolean value instead of packing bits.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly refactors the handling of basic type vectors and lists in TreeView by introducing helper functions to calculate chunk and element offsets, and fixes the packing logic for BoolType. The overall approach is sound. I've found one critical typo that would prevent compilation and a couple of minor suggestions to simplify the code in bool.zig. While not part of this PR's changes, please also note that UintType.tree.fromValuePacked appears to have a bug in its offset calculation that is surfaced by the changes in tree_view.zig and should be fixed in a follow-up.

if (ST.kind != .vector and ST.kind != .list) {
@compileError("chunkIndex is only available for vector or list types");
}
return if (comptime isBasicType(ST.element)) index / elementsPerChunk() else index;

Choose a reason for hiding this comment

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

critical

There seems to be a typo here. ST.element should be ST.Element to match the field name in the SSZ type definitions and for consistency with the elementOffset function. This will cause a compilation error.

            return if (comptime isBasicType(ST.Element)) index / elementsPerChunk() else index;

Comment on lines +76 to +78
const offset = index % 256;
const byte_index = offset / 8;
const bit_index = offset % 8;

Choose a reason for hiding this comment

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

medium

The index parameter passed to this function is the result of elementOffset, which is already calculated as index % 256. Therefore, const offset = index % 256; is redundant. You can remove the offset variable and directly use index to calculate byte_index and bit_index for simplification.

                const byte_index = index / 8;
                const bit_index = index % 8;

Comment on lines +88 to +90
const offset = index % 256;
const byte_index = offset / 8;
const bit_index = offset % 8;

Choose a reason for hiding this comment

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

medium

Similar to toValuePacked, the index parameter here is already the offset within the chunk (< 256), so calculating index % 256 is redundant. You can simplify the code by removing the offset variable.

                const byte_index = index / 8;
                const bit_index = index % 8;

@ensi321 ensi321 marked this pull request as draft October 30, 2025 13:37
@GrapeBaBa
Copy link
Contributor

@ensi321 Can I take a look at this if you are busy on other work?

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.

3 participants