Skip to content

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Dec 22, 2025

For the HasField VARIANT_ID and FIELD_ID constants, use i128
instead of u128. For structs and unions, set VARIANT_ID = -1 and
VARIANT_ID = -2 (respectively) instead of 0. This ensures that we will
never accidentally confuse the first (ie, 0th) variant of an enum with a
struct or union. It also paves the way for us to define methods which
only support a subset of structs/unions/enums.

Makes progress on #196, #2856


Latest Update: v7 — Compare vs v6

📚 Full Patch History

Links show the diff between the row version and the column version.

Version Base v1 v2 v3 v4 v5 v6
v7 vs Base vs v1 vs v2 vs v3 vs v4 vs v5 vs v6
v6 vs Base vs v1 vs v2 vs v3 vs v4 vs v5
v5 vs Base vs v1 vs v2 vs v3 vs v4
v4 vs Base vs v1 vs v2 vs v3
v3 vs Base vs v1 vs v2
v2 vs Base vs v1
v1 vs Base

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joshlf, 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 internal type identification mechanism within the zerocopy crate by transitioning to signed 128-bit integers for variant and field IDs. By assigning a distinct negative identifier (-1) to structs and unions, the change eliminates potential ambiguities with enum variant IDs and establishes a clearer, more robust type distinction. This enhancement not only improves the current type safety but also enables more specialized type-handling capabilities for future development.

Highlights

  • Type System Refinement: The VARIANT_ID and FIELD_ID constants used in the HasField trait have been changed from u128 (unsigned 128-bit integer) to i128 (signed 128-bit integer) across the codebase.
  • Struct/Union Identification: A new constant, STRUCT_UNION_VARIANT_ID, has been introduced and set to -1. This value is now used to uniquely identify structs and unions within the HasField trait implementations, replacing the previous use of 0.
  • Ambiguity Resolution: This change prevents accidental confusion between the 0th variant of an enum and a struct or union, as 0 can now exclusively represent the first variant of an enum, while -1 is reserved for structs and unions.
  • Future Extensibility: The modification paves the way for defining methods that specifically target and support only struct/union types, without interfering with enum-specific logic.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

@joshlf joshlf force-pushed the G03596047b3e8a9931799295d1e707540561c4e46 branch from eb73d5a to dd41efa Compare December 22, 2025 04:57
@joshlf joshlf requested a review from jswrenn December 22, 2025 04:57
Copy link
Contributor

@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 is a solid improvement to the library's design. Changing VARIANT_ID and FIELD_ID in the HasField trait to use i128 and reserving -1 as the VARIANT_ID for structs and unions is a smart move to prevent type confusion with enum variants. The changes are consistently applied throughout the codebase, including the derive macros. I've reviewed the implementation, and it appears correct and well-executed.

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.94%. Comparing base (77f1c47) to head (1c5cebf).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/util/macro_util.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2857   +/-   ##
=======================================
  Coverage   91.94%   91.94%           
=======================================
  Files          20       20           
  Lines        5824     5824           
=======================================
  Hits         5355     5355           
  Misses        469      469           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf joshlf force-pushed the G03596047b3e8a9931799295d1e707540561c4e46 branch 2 times, most recently from 5d01996 to 86b13be Compare December 22, 2025 16:27
@joshlf joshlf changed the title [project] Use -1 for struct/union VARIANT_ID [project] Distinguish structs/union/enums Dec 22, 2025
@joshlf joshlf force-pushed the G03596047b3e8a9931799295d1e707540561c4e46 branch 2 times, most recently from fd4aaf7 to 28cf083 Compare December 22, 2025 16:39
@joshlf joshlf enabled auto-merge December 22, 2025 16:40
For the `HasField` `VARIANT_ID` and `FIELD_ID` constants, use `i128`
instead of `u128`. For structs and unions, set `VARIANT_ID = -1` and
`VARIANT_ID = -2` (respectively) instead of 0. This ensures that we will
never accidentally confuse the first (ie, 0th) variant of an enum with a
struct or union. It also paves the way for us to define methods which
only support a subset of structs/unions/enums.

Makes progress on #196, #2856

gherrit-pr-id: G03596047b3e8a9931799295d1e707540561c4e46
@joshlf joshlf force-pushed the G03596047b3e8a9931799295d1e707540561c4e46 branch from 28cf083 to 1c5cebf Compare December 22, 2025 19:27
@joshlf joshlf added this pull request to the merge queue Dec 22, 2025
Merged via the queue into main with commit b99b86d Dec 22, 2025
105 of 122 checks passed
@joshlf joshlf deleted the G03596047b3e8a9931799295d1e707540561c4e46 branch December 22, 2025 20:06
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