Skip to main content

Module intern

Module intern 

Source
Expand description

Global keyword and symbol intern tables (Phase B3).

Interned keywords and symbols are allocated once into program-lifetime memory and reused for every subsequent request with the same identity. This gives each unique (namespace, name) pair a stable address that is consistent across all isolates — required for correct hash-map key lookups when maps move between isolates via the structured-clone boundary.

§Design

Each table is a OnceLock<Mutex<HashMap<…, StaticGcPtr<T>>>>. On the first call for a given key the value is allocated via cljrs_gc::static_alloc (arena in no-gc builds, Box::leak in GC builds) and the pointer is inserted. Subsequent calls return a clone of the stored pointer (O(1), just copies a NonNull).

§Contention

The global Mutex is only held during the brief table lookup + optional insert. Keywords are created at read/compile time, not in hot evaluation loops, so contention is not a concern for now. A sharded or lock-free table can replace this if profiling ever shows otherwise.

Functions§

intern_keyword
Intern a keyword into program-lifetime memory.
intern_symbol
Intern a symbol into program-lifetime memory.