Skip to content

fix: generate Reset that compiles, keeps locks and frees memory - #11

Merged
darxnet merged 5 commits into
mainfrom
fix/backfill-2026-11
Nov 12, 2026
Merged

darxnet merged 5 commits into
mainfrom
fix/backfill-2026-11

Conversation

@darxnet

@darxnet darxnet commented Nov 12, 2026

Copy link
Copy Markdown
Owner

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

  • fix: set interface fields to nil even when they have Reset
  • fix: never copy a lock in bulk mode
  • fix: reset only sync/atomic types through Store, zero atomic.Value
  • fix: clear pointer-bearing slices up to their capacity
  • fix: leave blank fields out, set unsafe.Pointer fields to nil

Behaviour changes

  • A type holding a lock (also inside values kept by reset:"-", call= or Reset()) now always gets field-by-field Reset instead of copying the lock in bulk mode.
  • Slices whose elements hold pointers are cleared up to their capacity.
  • Interface fields are set to nil even when the interface has a Reset method.

Known and not fixed here: generic structs still produce non-compiling code.

Testing

go vet, golangci-lint run and go test -race ./... pass locally.

darxnet and others added 5 commits November 12, 2026 13:07
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

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@darxnet
darxnet merged commit dcc723e into main Nov 12, 2026
9 checks passed
@darxnet
darxnet deleted the fix/backfill-2026-11 branch November 12, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant