Skip to main content

WeakSet

Trait WeakSet 

Source
pub trait WeakSet {
    // Required method
    fn clear_reclaimed(&self) -> usize;
}
Expand description

A set the collector keeps valid without keeping alive (ADR-106).

A RootSet answers “what must survive”. This answers the other question: “what names storage, but has no say in whether that storage survives”. Such a set is never traced, so it retains nothing; instead it is scanned once per collection, immediately after the sweep, and every entry naming reclaimed storage is turned into an absence rather than left as a dangling reference.

The one implementor that matters is RuntimeRoots, whose weak arm is the crash debugger’s per-call value slots. Those deliberately outlive the shadow slots that root them — ADR-044 decision 2 nulls a shadow slot the moment its local dies, while the debugger must keep rendering the value — so between the death and the fault the debugger names something the collector is free to reclaim, and, since swept storage is reusable, free to reissue as an object of another type.

Weak, not strong, is the whole point. Rooting those slots strongly is a two-line change and it is the set-merge ADR-044 exists to refuse: it makes the GC root set the over-approximate one again and fails a_dead_local_stops_being_reachable_from_its_frame by construction.

The timing is as load-bearing as the weakness; see Heap::collect and ADR-106 decision 2. “Reclaimed” is only observable in the window between the sweep that reclaimed a block and the next allocation that reissues it, so the clear has to happen inside the collection. A filter applied later — at the snapshot, at the render — cannot distinguish a block that died from one that died and came back.

Required Methods§

Source

fn clear_reclaimed(&self) -> usize

Mark every entry of this set whose object the just-finished sweep reclaimed, and answer how many were marked.

The count is for tests and for the measurement ADR-106 records; nothing on the collection path reads it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl WeakSet for ()

A no-weak-set impl, so in-crate tests can collect against a bare RootScope. Mirrors impl RootSet for ().

Implementors§