-
Notifications
You must be signed in to change notification settings - Fork 2
Add tagged union format support #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Implement UnionAsTaggedOptions with configurable tag field and value types - Add packUnionAsTagged and unpackUnionAsTagged functions - Support field_name, field_name_prefix, and field_index tag value formats - Extract unpackStructFromMapBody to share code between struct and union unpacking - Refactor integer overflow testing with expectIntOrOverflow helper - Add comprehensive tests for tagged union serialization and deserialization
|
@claude review this |
|
Claude finished @lalinsky's task —— View job Code Review for Tagged Union Format SupportTodo List:
📋 Review SummaryThis PR successfully implements a tagged union format as an alternative to the existing map-based format. The implementation is well-structured and follows Zig idioms. Overall this is high-quality code with comprehensive test coverage. ✅ Strengths
🔍 Detailed Analysissrc/int.zig Changes (✅ Good)
src/struct.zig Changes (✅ Good)
src/union.zig Changes (✅ Excellent)New Tagged Format Implementation:
Key Features:
🐛 Potential Issues & Suggestions1. Buffer Size Limitations
|
|
@claude what do you mean by const-folding field counts at compile time? |
|
Claude finished @lalinsky's task —— View job Todo List:
Const-folding Field Counts ExplanationGood question! By "const-folding field counts at compile time," I'm referring to a Zig optimization technique where the compiler can compute values at compile time rather than runtime. Current ImplementationLooking at your code, there are several places where field counts are computed at runtime: In const field_count = if (field_type_info == .@"struct") field_type_info.@"struct".fields.len else 0;In struct unpacking (src/struct.zig:165): var fields_seen = std.bit_set.StaticBitSet(fields.len).initEmpty();The Optimization OpportunitySince Zig has powerful compile-time evaluation ( Current approach (runtime computation): const field_count = if (field_type_info == .@"struct") field_type_info.@"struct".fields.len else 0;
try packMapHeader(writer, field_count + 1);Const-folded approach (compile-time computation): const field_count = comptime blk: {
if (field_type_info == .@"struct") {
break :blk field_type_info.@"struct".fields.len;
} else {
break :blk 0;
}
};
try packMapHeader(writer, field_count + 1);Why This Matters
Practical ImpactIn your case, this optimization would be most beneficial in the However, I should note that this is a micro-optimization. Your current code is already quite efficient, and the performance gain would be minimal. The Zig compiler is already quite good at optimizing simple expressions like The suggestion was more about demonstrating awareness of Zig's compile-time capabilities rather than pointing out a significant performance issue in your code. |
Summary
UnionAsTaggedOptionswith configurable tag field name and tag value typesTest plan
Fixes #3