Repository navigation
Give a struct copy's slice field its own header - #218
Conversation
A copy of a struct kept the original's cell for a slice field, so the copy
and the original shared the slice header as well as the array:
b := a
b.Items = nil // set a.Items to nil too
b.Items = append(b.Items, x) // grew a.Items too
Go copies the header: the two share the array, so an element write shows
in both, but each has its own length. The Go copy of a struct
(__go_value_clone) now gives an unnamed slice field a cell of its own
holding a copy of the GoSlice header, which shares the array. This also
fixes value receivers that append to a slice field, range values, and
values read out of maps and slices, which are all Go copies. Map, pointer
and defined slice fields keep their handles, as before.
Also: map[K]T{k: v} for a struct variable v did not compile (E0507, a
move out of v's cell). The map now stores Go's copy of v.
Fixtures: struct_copy_slice_field and its goroutine variant cover
assignment, nil and append on the copy, shared element writes, appends
within capacity from both sides, range values, a value receiver that
appends, map values and copies made in goroutines. Both match Go.
71 other snapshots change, each a struct with a slice field. Each was
built and run, and all match Go. The ratchet is unchanged;
TestGoValueCopyCallForType and
TestStructValueCloneBuildsLargeStructWithStatements now expect the new
cell.
Not covered: an interface field or a func field of the copy still shares
the original's cell (DEV-55).
Agent: claude-chat
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TkCXVghVg3khqYkpQSWyEM
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Caution Review failedThe pull request is closed.
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. |
|
Sorry @tylerlaprade, this account has used its review budget of 1,500,000 diff characters for the last 7 days. You can request another review in 1 day and 13 hours by commenting |
…ce-field Fixtures whose generated code the merged translator changes: fprintln_writers fprintln_writers_plain Agent: claude-chat Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TkCXVghVg3khqYkpQSWyEM
Covers the slice-field case of DEV-55.
A copy of a struct kept the original's cell for a slice field. So the copy and the original shared the slice header as well as the array:
Go copies the header. The two slices share the array, so an element write shows in both while they share it, but each has its own length. Now the Go copy of a struct (
__go_value_clone) gives an unnamed slice field a cell of its own, holding a copy of theGoSliceheader that shares the array. Everything that is a Go copy is fixed this way:Map, pointer and defined-slice fields keep their handles, as before.
Also:
map[K]T{k: v}for a struct variablevdid not compile (E0507, a move out ofv's cell). The map now stores Go's copy ofv.Fixtures.
struct_copy_slice_fieldandstruct_copy_slice_field_goroutinescover:nilandappendon the copyBoth match Go. 73 other snapshots change, each a struct with a slice field. Each was built and run, and all match Go. The ratchet is unchanged.
TestGoValueCopyCallForTypeandTestStructValueCloneBuildsLargeStructWithStatementspinned the shared cell and now expect the new one.Not covered. An interface or func field of the copy still shares the original's cell. Those are the rest of DEV-55.
— agent: claude-chat
Generated by Claude Code
Summary by Sourcery
Match Go’s struct-copy semantics by giving unnamed slice fields their own headers while retaining shared backing arrays.
New Features:
Bug Fixes:
Enhancements:
Tests: