Skip to content

Conversation

@mgyoo86
Copy link
Collaborator

@mgyoo86 mgyoo86 commented Dec 9, 2025

Summary

  • Add FIXED_SLOT_FIELDS constant tuple as single source of truth for fixed slot field names
  • Add foreach_fixed_slot @generated function for type-stable, zero-allocation iteration
  • Add ComplexF32 as new fixed slot type
  • Refactor hardcoded iteration tuples in utils.jl to use foreach_fixed_slot

What's Changed

New: FIXED_SLOT_FIELDS

const FIXED_SLOT_FIELDS = (:float64, :float32, :int64, :int32, :complexf64, :complexf32, :bool)

Single source of truth for fixed slot field names. Used by foreach_fixed_slot and tests.

New: foreach_fixed_slot

foreach_fixed_slot(pool) do tp
    # Compile-time unrolled, type-stable iteration
end

Zero-allocation iteration via @generated function that reads from FIXED_SLOT_FIELDS.

Refactored (utils.jl only)

  • pool_stats, Base.show, _check_pointer_overlap: hardcoded tuple → foreach_fixed_slot

Not Changed

Adding a new fixed slot still requires updating 4 places:

  1. FIXED_SLOT_FIELDS
  2. AdaptiveArrayPool struct
  3. AdaptiveArrayPool() constructor
  4. get_typed_pool! dispatch

Benefits

  • Type stability: runtime getfield(pool, field::Symbol) → compile-time unrolling
  • Zero allocation: no allocation after warmup
  • Improved utils.jl maintainability: iteration logic syncs with FIXED_SLOT_FIELDS

Test Coverage

  • test_fixed_slots.jl: auto-verifies FIXED_SLOT_FIELDS and struct synchronization

Implement centralized iteration over fixed slot TypedPools using
@generated function with compile-time unrolling.

Changes:
- Add FIXED_SLOT_FIELDS constant for explicit slot enumeration
- Add foreach_fixed_slot() with @_inline_meta for guaranteed inlining
- Refactor checkpoint!, rewind!, empty! to use foreach_fixed_slot
- Add comprehensive test suite (52 tests) for synchronization and
  zero-allocation verification

Design decision: Use explicit FIXED_SLOT_FIELDS tuple instead of
fieldtypes() filtering to prevent accidental inclusion of future
internal TypedPool fields.
- Add ComplexF32 as new fixed slot type alongside ComplexF64
- Refactor _check_pointer_overlap to use foreach_fixed_slot
- Refactor pool_stats to use foreach_fixed_slot with dynamic type extraction
- Refactor Base.show to use foreach_fixed_slot with Ref counters
- Add ComplexF32 tests for symmetry with ComplexF64 tests

This ensures FIXED_SLOT_FIELDS is the single source of truth -
no more hardcoded slot lists to maintain separately.
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.46%. Comparing base (bfd4c31) to head (9ef76f4).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   94.60%   96.46%   +1.85%     
==========================================
  Files           7        7              
  Lines         575      565      -10     
==========================================
+ Hits          544      545       +1     
+ Misses         31       20      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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 adds infrastructure to improve maintainability and performance when working with fixed slot types in the AdaptiveArrayPool. The main contribution is the introduction of FIXED_SLOT_FIELDS as a single source of truth and foreach_fixed_slot for type-stable, zero-allocation iteration. Additionally, ComplexF32 is added as a new fixed slot type.

Key Changes:

  • New FIXED_SLOT_FIELDS constant tuple centralizes the list of fixed slot field names
  • New foreach_fixed_slot @generated function enables compile-time unrolled iteration over fixed slots
  • ComplexF32 added as the 7th fixed slot type alongside existing Float64, Float32, Int64, Int32, ComplexF64, and Bool

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/types.jl Added FIXED_SLOT_FIELDS constant, foreach_fixed_slot @generated function, ComplexF32 fixed slot type definition and dispatch
src/state.jl Refactored checkpoint!, rewind!, and empty! to use foreach_fixed_slot instead of hardcoded iteration
src/utils.jl Refactored _check_pointer_overlap, pool_stats, and Base.show to use foreach_fixed_slot for consistent fixed slot iteration
src/acquire.jl Removed internal _acquire_impl! and _unsafe_acquire_impl! fallback methods for ::Nothing (no longer needed as macros handle pool=nothing separately)
test/test_fixed_slots.jl New comprehensive test file verifying FIXED_SLOT_FIELDS synchronization, foreach_fixed_slot behavior, type stability, and zero allocation
test/test_basic.jl Added test coverage for ComplexF32 fixed slot type
test/test_state.jl Updated checkpoint!/rewind! tests to include ComplexF32
test/test_utils.jl Updated _validate_pool_return tests to include ComplexF32
test/test_aliases.jl Added runtime coverage tests for similar-style _impl! methods called via macro transformation
test/runtests.jl Included new test_fixed_slots.jl in test suite

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

@mgyoo86 mgyoo86 merged commit 4d0f967 into master Dec 9, 2025
14 checks passed
@mgyoo86 mgyoo86 deleted the feat/const_fixed_slot branch December 9, 2025 23:40
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