Repository navigation
fix: generate Reset that compiles, keeps locks and frees memory - #11
Merged
Merged
Conversation
An interface whose method set includes Reset() got an unconditional r.F.Reset(): it crashed on a nil value and never set the field to nil, though README promises interfaces become nil. call= on an interface is now guarded by a nil check, like on a pointer. Adds a regression harness that compiles, vets and runs generated code in a throwaway module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bulk mode keeps a field by copying it out and back around *r = T{}.
For reset:"-", call= on a value and values with Reset() that hold a
sync or sync/atomic value (or any type go vet's copylocks treats as a
lock), that copied the lock and failed go vet. Such a field now forces
field-wise mode, as a sync field already does, with the reason in the
generated comment and a hint from Analyze.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any type spelled atomic.* got Store(0): atomic.Value panicked when it held a value of another type (and Store(nil) always panics), and the types of other packages named atomic, such as go.uber.org/atomic, got code that does not compile. sync/atomic is now recognised by import path, atomic.Value is set to its zero value, and other types are reset like any other struct. Two packages with the same name in one generated file now get distinct import names (atomic, atomic2), and a field type naming several packages imports them all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clear(s) zeroes s[:len(s)] only. When the slice had been resliced shorter before Reset, the elements in s[len:cap] still pointed at their old values and kept them alive in the pooled object. Slices whose elements hold pointers (strings, pointers, interfaces, structs with those...) are now cleared with clear(s[:cap(s)]); pointer-free slices such as []byte keep the cheaper clear(s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A blank field such as `_ [56]byte` padding got r._ = ... (or r._.Reset() for a type with Reset), and an unsafe.Pointer fell into the string case and got r.P = "": neither compiles. Blank fields are now skipped (bulk mode still zeroes them with the struct), and unsafe.Pointer is set to nil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes found in a one-off review of competitor issues over their whole history; each bug is reproduced by a regression test that failed before the fix.
Changes
Behaviour changes
reset:"-",call=orReset()) now always gets field-by-field Reset instead of copying the lock in bulk mode.Known and not fixed here: generic structs still produce non-compiling code.
Testing
go vet,golangci-lint runandgo test -race ./...pass locally.