fix(arrow/array): silence copylocks warning in numeric_generic.go#823
Open
zeroshade wants to merge 1 commit into
Open
fix(arrow/array): silence copylocks warning in numeric_generic.go#823zeroshade wants to merge 1 commit into
zeroshade wants to merge 1 commit into
Conversation
The newNumericData helper returned numericArray[T] by value, copying the embedded array struct's atomic.Int64 refcount and triggering 'go vet' copylocks warnings on the return statement and at every NewXData call site that embedded the result into a wrapper struct literal. Replace newNumericData with initNumericArray, which initializes an already-allocated *numericArray[T] in place. The 15 NewXData constructors now allocate the concrete wrapper struct on the heap first and pass a pointer to its embedded numericArray field, so the atomic refcount is never copied. This mirrors the existing pattern used by NewStringData, NewBinaryData, and newDecimalData in the same package. The change is purely internal: numericArray[T] is unexported and the public NewXData signatures and behavior are unchanged. Fixes apache#821
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.
Rationale for this change
go vet ./arrow/array/reports:The
newNumericDatahelper instantiated anumericArray[T]zero value, mutated it, and returned it by value. Returning this value copies the embeddedarraystruct, which contains anatomic.Int64refcount with anoCopymarker. The 15New<T>Datacallers then copy the value a second time when embedding it into their wrapper struct literal (e.g.return &Int64{numericArray: newNumericData[int64](data)}).In practice the refcount value is only copied during single-threaded construction before the resulting
*Typepointer is shared, so no race exists today (this is acknowledged in the original commit that introducedatomic.Int64— #326). However, the warning is permanent noise ingo vetoutput, masks any future real copylocks regressions in this code path, and signals a fragile pattern that one careless refactor would turn into a real bug.What changes are included in this PR?
newNumericData[T](data) numericArray[T]withinitNumericArray[T](a *numericArray[T], data). The helper now initializes an already-allocatednumericArray[T]in place — no value return, no copy.New<T>Dataconstructors (NewInt64Data,NewUint64Data,NewInt32Data,NewUint32Data,NewInt16Data,NewUint16Data,NewInt8Data,NewUint8Data,NewFloat32Data,NewFloat64Data,NewDate32Data,NewDate64Data,NewTime32Data,NewTime64Data,NewDurationData) to allocate the concrete wrapper on the heap first, then pass a pointer to the embeddednumericArrayfield via Go field promotion.This mirrors the existing idiom already used by
NewStringData,NewBinaryData, andnewDecimalDatain this same package.Are these changes tested?
go vet ./arrow/array/is clean fornumeric_generic.go(an unrelatedextension.go:100warning involvingreflect.ValueOfremains and is out of scope for this issue).go test ./arrow/...passes (15 packages).go test ./parquet/pqarrow/...passes (excluding pre-existing tests that requirePARQUET_TEST_DATA).Are there any user-facing changes?
No.
numericArray[T]is unexported and the publicNew<T>Datasignatures and runtime behavior are unchanged. The number of heap allocations per constructor is the same as before — fields are now constructed directly inside the heap-allocated wrapper rather than copied into it.Closes #821