Skip to content

Feat/gc drop finalizer parity#43

Open
Flamki wants to merge 1 commit intoboa-dev:mainfrom
Flamki:feat/gc-drop-finalizer-parity
Open

Feat/gc drop finalizer parity#43
Flamki wants to merge 1 commit intoboa-dev:mainfrom
Flamki:feat/gc-drop-finalizer-parity

Conversation

@Flamki
Copy link
Contributor

@Flamki Flamki commented Mar 9, 2026

This PR tightens mark-sweep teardown/finalization semantics with minimal scope.

What changed

  • Added a typed-erased finalizer hook to the GC vtable (FinalizeFn) so GcBox<T> finalizers can be dispatched correctly from erased pointers.
  • Updated collector teardown (sweep_all_queues) to run finalize_fn before drop_fn for:
    • root_queue
    • pending_root_queue
    • ephemeron_queue
    • pending_ephemeron_queue
  • Updated dead-root sweep path to use the new vtable finalizer dispatch.
  • Updated ephemeron finalizer hook to use Trace::run_finalizer(...).
  • Added regression tests:
    • collector_drop_runs_finalizers_for_live_gc_values
    • collector_drop_runs_ephemeron_value_finalizers_for_live_values

Why

Previous teardown behavior reliably dropped live tracked allocations, but finalizer execution for erased GC values was incomplete/inconsistent. This patch keeps the PR focused to mark-sweep internals and guarantees finalizers are run during collector teardown where safe.

Scope

  • mark-sweep internals + tests only
  • no public API changes
  • no allocator policy/threshold changes

Validation

  • cargo fmt --all -- --check
  • cargo test --workspace
  • cargo clippy --workspace --all-features --all-targets
  • cargo clippy --workspace --no-default-features --all-targets
  • cargo doc -v --document-private-items --all-features

@Flamki Flamki force-pushed the feat/gc-drop-finalizer-parity branch from 7cabb2f to 503ee7d Compare March 9, 2026 12:05
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