Avoid invalidated tag slices in codec validation - #10741
Conversation
Greptile SummaryThe PR replaces borrowed tag slices and temporary argument copies with stable indexed type-store traversal in derived parse and encode validation.
Confidence Score: 4/5The PR appears safe to merge, with the non-blocking caveat that the encode-side traversal change should receive equivalent regression coverage. The indexed access APIs preserve stable ranges and values across type-store reallocations, addressing the invalid borrowed-slice path; the remaining concern is limited to incomplete test coverage of the parallel encode implementation. Files Needing Attention: src/check/Check.zig, src/check/test/issue_10695_test.zig
|
| Filename | Overview |
|---|---|
| src/check/Check.zig | Safely converts parse and encode tag-union validation to index-based traversal; the encode-side change lacks matching regression coverage. |
| src/check/test/issue_10695_test.zig | Adds a focused parse regression that checks the reported repeated-alias scenario completes without compiler errors. |
| src/check/mod.zig | Registers the new issue regression test with the check test suite. |
Reviews (1): Last reviewed commit: "Avoid invalidated tag slices in codec va..." | Re-trigger Greptile
| for (0..tag_union.tags.count) |tag_offset| { | ||
| const tag_args_range = self.types.getTagAt(tag_union.tags, @intCast(tag_offset)).args; | ||
| for (0..tag_args_range.count) |tag_arg_offset| { | ||
| const tag_arg = self.types.getVarAt(tag_args_range, @intCast(tag_arg_offset)); |
There was a problem hiding this comment.
Encode traversal lacks regression coverage
The encode tag-union traversal now uses the same indexed access strategy, but the regression source invokes only Json.parse. Add an encode case with recursive or repeatedly aliased tag-union fields so an encode-specific traversal regression does not pass undetected.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Derived parser validation held a borrowed tag-range slice across recursive type-store growth, so reallocation could corrupt the next tag's argument range and crash. Traverse tag and argument spans through stable indexed store access in both derived parse and encode validation, which also removes temporary per-tag allocations. Fixes #10695.