Skip to content

[RESEARCH] Bridging Allocator trait using RefCell (Interior Mutability) #14

@Divinesoumyadip

Description

@Divinesoumyadip

Description

While researching the Garbage Collector Redesign for GSoC 2026, I have been investigating the reconciliation of our custom collection traits with the standard Rust Allocator API.

The Problem

The current allocation paths in the experimental lab, specifically in src/alloc/arena/mod.rs, rely on an exclusive &mut self signature. This creates a fundamental architectural mismatch with the standard Rust Allocator trait, which requires a shared &self reference to allow for concurrent or shared allocation requests.

The Evidence (Precedent in Boa)

We already have an established pattern for solving this within the core engine. In the boa_mempool crate (specifically around line 129), the implementation utilizes RefCell<Vec<Chunk<T>>> to wrap underlying memory pools. This allows the public MemPoolAllocator to expose a thread-safe (or at least runtime-checked) &self API while still performing the necessary mutations on the underlying chunks.

Proposed Research: The "Trace" Bridge

To address the safety concerns raised in Issue #11—specifically regarding Vec<T, GcAllocator> not automatically keeping its backing allocation alive—I am researching a GcBox<T> or Handle<T> wrapper.

The goal is to ensure that:

  1. The wrapper implements the Trace trait.
  2. During a GC sweep, the collector can reach the backing memory even if the outer collection is not GC-aware.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions