Logo Xantham

ArenaInterner Module

Lazy resolved type graph for use in generators.

The wire format produced by the decoder (DecodedResult) represents the TypeScript type graph as a pair of flat maps keyed by TypeKey: one for structural types (TsType) and one for export declarations (TsExportDeclaration). References between types are expressed as TypeKey values that must be resolved against those maps. While correct, this representation is inconvenient for generators: maps must be threaded through every rendering function, and every type dereference requires an explicit lookup.

ArenaInterner pre-resolves this key graph into a lazy object graph. Each TypeKey reference becomes a Lazy<ResolvedType> — following a reference is simply forcing a lazy value, with no map access needed at call sites. Results are memoised in a dictionary keyed by TypeKey, so types that share the same key resolve to the same object instance. Combined with [<ReferenceEquality>] on all record types, this enables identity-based sharing detection in generators (e.g. recognising that two members reference the same TypeParameter) without carrying keys around.

Cycles in the type graph (e.g. recursive interfaces, self-referential type aliases) are broken naturally by the lazy boundaries around all TypeKey dereferences. Construction of a node never forces any of its outgoing lazy references, so re-entrant calls to resolve cannot occur during graph initialisation. By the time a consumer forces a lazy, the referent is already in the cache.

Prefer this representation in generators over raw DecodedResult maps when:
  • Rendering functions should not need access to global maps.
  • Structural sharing or identity equality between types is meaningful to the output.
  • The generator traverses the type graph recursively (pattern matching on ResolvedType is more ergonomic than repeated map lookups).
Prefer raw DecodedResult maps when:
  • Only a small subset of the type graph is needed — the interner allocates shells for all top-level exports at construction time.
  • TypeKey identity must be preserved for output naming or cross-referencing (keys are not carried in the resolved graph).
  • Startup cost is a concern — ArenaInterner.create walks and shells the entire export map eagerly, deferring only nested type resolution.

Types and nested modules

Type/Module Description

ArenaInterner (Module)

Functions for constructing and walking an ArenaInterner.

ArenaInterner (Type)

Lazily-resolved object graph view of a DecodedResult. Following a reference forces a Lazy<ResolvedType>, materialising a node on demand. Cycles are broken by lazy boundaries (construction never forces outgoing lazies). Exports are shelled eagerly; nested types are deferred.

CallSignature

Class

ClassHeritage

ConditionalType

ConstructSignature

Constructor

EnumCase

EnumType

Function

GetAccessor

Index

IndexAccessType

IndexSignature

Interface

InterfaceHeritage

Intersection

LazyContainer<'RawData, 'LazyResult>

Pairing of raw input data (, typically a TypeKey) with a lazily computed resolved value (). Used to defer resolution of cyclic dependencies in the type graph.

LazyResolvedExport

LazyResolvedType

Member

Method

Module

Parameter

Predicate

Property

QualifiedNamePart

A single segment of a fully qualified TypeScript name. Tagged either as Normal (no anomalies) or Abnormal together with diagnostic flags indicating which anomalies the segment contains.

QualifiedNamePartDiagnostic

Bit flags describing structural anomalies in a single segment of a fully qualified TypeScript name (e.g. embedded quotation marks, slashes, or periods).

ResolvedExport

The resolved (lazy-graph) form of a top-level TypeScript export declaration. Holds direct references into the resolved type graph rather than TypeKeys.

ResolvedType

The resolved (lazy-graph) form of a structural TypeScript type. Each case directly references its dependencies (rather than carrying TypeKeys), with cycles broken by the surrounding LazyResolvedType wrappers.

SetAccessor

SubstitutionType

TemplateLiteral

Tuple

TupleElement

TupleElementType

TypeAlias

TypeLiteral

TypeParameter

TypeQuery

TypeReference

Union

Variable

Active patterns

Active pattern Description

(|Resolve|) value

Full Usage: (|Resolve|) value

Parameters:
Returns: 'T
Modifiers: inline
Type parameters: 'a, 'T

Active pattern for ergonomic forcing of a LazyContainer: matching Resolve t binds t to the materialised lazy result.

value : LazyContainer<'a, 'T>
Returns: 'T

Type something to start searching.