Skip to content

(refac!): Default acquire!Array, remove unsafe_* API#33

Merged
mgyoo86 merged 5 commits intomasterfrom
feat/v0.3.0-api-refactor
Mar 13, 2026
Merged

(refac!): Default acquire!Array, remove unsafe_* API#33
mgyoo86 merged 5 commits intomasterfrom
feat/v0.3.0-api-refactor

Conversation

@mgyoo86
Copy link
Member

@mgyoo86 mgyoo86 commented Mar 13, 2026

Summary

Flip the default return type of acquire! from views (SubArray/ReshapedArray) to native Array{T,N}, remove the entire unsafe_* API surface, and introduce acquire_view! as the explicit view API.

Breaking change — all unsafe_acquire!, unsafe_zeros!, unsafe_ones!, unsafe_similar! are removed with no deprecation period.

Motivation

On Julia 1.11+, Array became a mutable struct enabling setfield!-based wrapper reuse with zero allocation — the same guarantee views had. This eliminated the original reason views were the default (zero-alloc advantage). With Array now zero-alloc too, it's the more natural default:

  • Works with FFI/ccall (Ptr{T}) without conversion
  • Satisfies ::Array{T,N} type constraints directly
  • BLAS/LAPACK compatible (same as views)
  • No user confusion about "why is my array a SubArray?"

The unsafe_* prefix was misleading — these functions were never unsafe in the memory-safety sense. Removing them simplifies the API from 8 acquire functions to 3.

New API Surface

Function Returns Notes
acquire!(pool, T, dims...) Array{T,N} Default (was view)
acquire_view!(pool, T, dims...) SubArray/ReshapedArray Old acquire! behavior
acquire_array!(pool, T, dims...) Array{T,N} Alias for acquire!
zeros!, ones!, similar! Array{T,N} Was view
trues!, falses! BitArray{N} Unchanged
reshape! Array{T,N} Unchanged

Removed: unsafe_acquire!, unsafe_zeros!, unsafe_ones!, unsafe_similar!
Bit sentinel: acquire!(pool, Bit, ...) still returns BitVector/BitArray{N} (unchanged)
CUDA: No behavioral change — CuArray returned for both acquire! and acquire_view!

Migration Guide

# Before (v0.2.x)
v = acquire!(pool, Float64, 100)          # SubArray{Float64,1}
a = unsafe_acquire!(pool, Float64, 100)   # Array{Float64,1}
z = unsafe_zeros!(pool, Float64, 10, 10)  # Array{Float64,2}

# After (v0.3.0)
v = acquire!(pool, Float64, 100)          # Array{Float64,1} ← now Array!
v = acquire_view!(pool, Float64, 100)     # SubArray{Float64,1} ← explicit opt-in
z = zeros!(pool, Float64, 10, 10)         # Array{Float64,2} ← always Array now

Search-and-replace for upgrading:

  • unsafe_acquire!acquire! (or just delete — acquire! already returns Array)
  • unsafe_zeros!zeros!
  • unsafe_ones!ones!
  • unsafe_similar!similar!

mgyoo86 added 4 commits March 13, 2026 11:16
BREAKING CHANGE: `acquire!` now returns `Array{T,N}` instead of `SubArray`.

New API surface:
- `acquire!(pool, T, dims...)` → Array{T,N} (was SubArray)
- `acquire_array!(pool, T, dims...)` → alias for acquire!
- `acquire_view!(pool, T, dims...)` → SubArray (was old acquire!)
- `zeros!`, `ones!`, `similar!` → Array (was SubArray)

Removed (no deprecation):
- `unsafe_acquire!`, `unsafe_zeros!`, `unsafe_ones!`, `unsafe_similar!`

Motivation: Julia 1.11+ setfield!-based Array wrapper reuse makes
zero-alloc Array returns possible, eliminating the need for the
unsafe_ prefix and making Array the natural default.
…ility

Array structural invalidation via setfield!(:size) requires Julia 1.11+.
After the acquire! → Array default change, these tests need version gating
since legacy path uses N-way cache (C struct Array, no setfield!).

- Gate size(v)==(0,) assertions with @static if VERSION >= v"1.11-"
- Remove redundant duplicate test blocks (now identical post-refactor)
- Merge legacy 5-way N-way cache tests (eviction expected with CACHE_WAYS=4)
…ve unsafe_*)

- Replace all unsafe_acquire!/unsafe_zeros!/unsafe_ones!/unsafe_similar! references
- Update return type descriptions: acquire! now returns Array, not views
- Add acquire_view! as the new view API (was old acquire! behavior)
- Update acquire_array! as alias for acquire!
- Update API tables, code examples, and comparison sections across all docs
…acy acquire_view!

- safe_prod docstring: generalize "unsafe_wrap" → "array creation operations"
- legacy acquire_view!: add _set_pending_callsite! for borrow tracking parity with modern path
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 84.21053% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.53%. Comparing base (c194b0d) to head (6568cd9).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/bitarray.jl 25.00% 6 Missing ⚠️
src/legacy/bitarray.jl 64.70% 6 Missing ⚠️
src/debug.jl 40.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
- Coverage   97.02%   96.53%   -0.50%     
==========================================
  Files          14       14              
  Lines        2658     2566      -92     
==========================================
- Hits         2579     2477     -102     
- Misses         79       89      +10     
Files with missing lines Coverage Δ
src/AdaptiveArrayPools.jl 100.00% <ø> (ø)
src/acquire.jl 96.27% <100.00%> (ø)
src/convenience.jl 98.70% <ø> (+0.35%) ⬆️
src/legacy/acquire.jl 95.07% <100.00%> (+0.14%) ⬆️
src/legacy/state.jl 97.08% <ø> (ø)
src/legacy/types.jl 95.71% <ø> (+4.28%) ⬆️
src/macros.jl 97.97% <100.00%> (-0.14%) ⬇️
src/state.jl 97.05% <ø> (ø)
src/types.jl 89.06% <ø> (ø)
src/debug.jl 95.32% <40.00%> (-1.09%) ⬇️
... and 2 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates AdaptiveArrayPools’ public API to make acquire! (and convenience functions) return native Array{T,N} by default, removes the unsafe_* API surface, and adds acquire_view! as the explicit view-returning API, with corresponding updates across macros, CUDA extension glue, docs, and tests.

Changes:

  • Switch default acquisition to Array (acquire!, zeros!, ones!, similar!) and introduce acquire_view! for the old view behavior.
  • Remove unsafe_acquire! / unsafe_zeros! / unsafe_ones! / unsafe_similar! and retarget macro transformations to _acquire_impl! / _acquire_view_impl!.
  • Update test suite and documentation to match new return types and migration guidance.

Reviewed changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/test_zero_allocation.jl Update zero-alloc patterns for new defaults
test/test_state.jl Adjust state assertions for Array-returning acquire!
test/test_safety.jl Update safety/invalidation expectations by version
test/test_nway_cache.jl Update cache tests for Array-returning acquire!
test/test_multidimensional.jl Update multi-dim return type assertions
test/test_macro_internals.jl Update macro internals tests for new call names
test/test_macro_expansion.jl Update macro expansion expectations for view/array split
test/test_fallback_reclamation.jl Update fallback-type tests to acquire!
test/test_disabled_pooling.jl Update disabled pooling expectations for convenience funcs
test/test_debug.jl Update debug/runtime escape tests for new defaults
test/test_coverage.jl Update coverage tests for removed unsafe APIs
test/test_convenience.jl Update convenience function tests to Array-returning behavior
test/test_compile_escape.jl Update compile-time escape classification for new API
test/test_borrow_registry.jl Update borrow registry tests to acquire!
test/test_bitarray.jl Update Bit/Bool behavior tests under new defaults
test/test_basic.jl Update basic type assertions for acquire!
test/test_backend_macro_expansion.jl Update backend macro expansion tests for view API
test/test_aliases.jl Update alias/identity expectations for new API surface
test/legacy/test_nway_cache.jl Update legacy cache tests for legacy branch behavior
test/cuda/test_nway_cache.jl Update CUDA cache tests for new call names/semantics
test/cuda/test_extension.jl Update CUDA extension tests for new defaults
test/cuda/test_disabled_pool.jl Remove unsafe-disabled-pool tests; keep remaining coverage
test/cuda/test_convenience.jl Update CUDA convenience function tests to new defaults
test/cuda/test_allocation.jl Update CUDA allocation tests for new acquisition API
src/types.jl Update core type docs/notes for new acquisition semantics
src/state.jl Update invalidation comments to match new API naming
src/macros.jl Remove unsafe transforms; add _acquire_view_impl! path
src/legacy/types.jl Update legacy docs to match new API naming
src/legacy/state.jl Update legacy invalidation commentary
src/legacy/bitarray.jl Update Bit acquisition internals for new view/array split
src/legacy/acquire.jl Legacy branch: acquire! returns Array; add acquire_view!
src/debug.jl Update runtime escape detection docs/comments for new defaults
src/convenience.jl Remove unsafe convenience API; document new return types
src/bitarray.jl Update Bit acquisition internals for new view/array split
src/acquire.jl Make acquire! return Array; add acquire_view! implementations
src/AdaptiveArrayPools.jl Update exports to remove unsafe_* API surface
ext/AdaptiveArrayPoolsCUDAExt/convenience.jl Remove unsafe disabled-pool CUDA convenience methods
ext/AdaptiveArrayPoolsCUDAExt/acquire.jl Retarget CUDA impl hooks to _acquire_view_impl!
docs/src/reference/api.md Update API reference for new defaults and aliases
docs/src/features/safety.md Update safety examples to “pool-acquired array”
docs/src/features/cuda-support.md Update CUDA docs for new API split
docs/src/features/configuration.md Reframe CACHE_WAYS as affecting acquire!
docs/src/basics/safety-rules.md Update guidance: avoid resizing acquire! arrays
docs/src/basics/quick-start.md Update quick-start return type guidance
docs/src/basics/api-essentials.md Update essentials page for new APIs/return types
docs/src/architecture/type-dispatch.md Update architecture docs to Array-by-default model
docs/src/architecture/how-it-works.md Update high-level explanation for new API split
docs/src/architecture/design-docs.md Update design-docs index text for new API model
README.md Update README messaging for new defaults and removed unsafe APIs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…scape detection tests

- Remove duplicate acquire!/test_throws from test_coverage.jl (was unsafe_acquire! → acquire! rename artifact), replace with acquire_view! coverage
- Fix stale comments in debug.jl and types.jl docstring (acquire! → acquire_view! for view paths)
- Add defensive ReshapedArray{Array/BitArray} branches in _validate_pool_return (unreachable via normal API since reshape(::Array) returns Array via jl_reshape_array, but guards edge cases)
- Add escape detection tests for acquire_view! N-D (ReshapedArray{SubArray}) and reshape!(pool, ...) (Array)
- Add v0.2→v0.3 migration guide
@mgyoo86 mgyoo86 merged commit 3509731 into master Mar 13, 2026
13 of 14 checks passed
@mgyoo86 mgyoo86 deleted the feat/v0.3.0-api-refactor branch March 13, 2026 20:44
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.

2 participants