Skip to content

mark_sweep: add Gc::new_cyclic_in parity semantics and tests#71

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

mark_sweep: add Gc::new_cyclic_in parity semantics and tests#71
Flamki wants to merge 1 commit intoboa-dev:mainfrom
Flamki:feat/gc-new-cyclic-parity

Conversation

@Flamki
Copy link
Copy Markdown
Contributor

@Flamki Flamki commented Mar 29, 2026

Part of #63

This PR adds Gc::new_cyclic_in parity support for both mark-sweep collectors, following Boa semantics where weak.upgrade() returns None inside the construction closure until the object is fully initialized.

What changed

  • Added Gc::new_cyclic_in in:
    • mark_sweep::pointers::Gc
    • mark_sweep_arena2::pointers::Gc
  • Added empty ephemeron allocation path used by cyclic bootstrap:
    • alloc_empty_ephemeron_node in mark-sweep collector APIs
    • matching arena2 collector allocation helper
  • Added internal helpers to support deferred key binding:
    • WeakGcBox::new_empty
    • Ephemeron::<K, ()>::new_empty
    • Ephemeron::<K, ()>::set_key
    • WeakGc::from_raw + WeakGc::set_key (crate-visible)
  • Added parity tests in both collectors:
    • new_cyclic_closure_cannot_upgrade_before_init

Why

Gc::new_cyclic is still listed as a parity gap in #63.
This closes that gap while keeping scope limited to mark-sweep internals and tests.

Scope

  • API parity + tests only
  • no allocator policy tuning
  • no integration path changes

Validation

  • cargo fmt --all -- --check
  • cargo test --workspace -q
  • cargo clippy --workspace --all-features --all-targets -q

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