Add helper make_kind#51
Conversation
WalkthroughThe pull request updates the project version from "0.10.7-dev" to "0.10.8-dev", adds a new public method Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/kinda.zig (1)
47-55: Consider extracting shared tuple-creation logic.The implementation is correct with proper memory management and error handling. However, this code duplicates the tuple-creation pattern from
wrap_ret_call(lines 306-316). Both functions allocate a 3-element slice and populate it with the same structure:{"kind", module_name, resource}.Consider extracting the common logic into a private helper function to improve maintainability:
fn make_kind_tuple(env: beam.env, comptime mod_name: []const u8, resource_term: beam.term) !beam.term { var tuple_slice: []beam.term = beam.allocator.alloc(beam.term, 3) catch return beam.Error.@"Fail to allocate memory for tuple slice"; defer beam.allocator.free(tuple_slice); tuple_slice[0] = beam.make_atom(env, "kind"); tuple_slice[1] = beam.make_atom(env, mod_name); tuple_slice[2] = resource_term; return beam.make_tuple(env, tuple_slice); }Then refactor both functions:
pub fn make_kind(env: beam.env, value: T) !beam.term { - var tuple_slice: []beam.term = beam.allocator.alloc(beam.term, 3) catch return beam.Error.@"Fail to allocate memory for tuple slice"; - defer beam.allocator.free(tuple_slice); - tuple_slice[0] = beam.make_atom(env, "kind"); - tuple_slice[1] = beam.make_atom(env, module_name); const ret = resource.make(env, value) catch return beam.Error.@"Fail to make resource for return type"; - tuple_slice[2] = ret; - return beam.make_tuple(env, tuple_slice); + return make_kind_tuple(env, module_name, ret); }And similarly for
wrap_ret_callat line 313.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
build.zig(1 hunks)mix.exs(1 hunks)src/kinda.zig(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: otp25.0-ex1.18.0 / ubuntu-22.04
- GitHub Check: otp24.2-ex1.16.2 / ubuntu-22.04
- GitHub Check: otp25.0-ex1.13.0 / ubuntu-22.04
🔇 Additional comments (2)
mix.exs (1)
7-7: LGTM!The version bump is appropriate for adding the new
make_kindhelper function.build.zig (1)
9-9: LGTM!Minor formatting adjustment with no semantic impact.
Summary by CodeRabbit
New Features
Chores