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.
- 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
ResolvedTypeis more ergonomic than repeated map lookups).
- Only a small subset of the type graph is needed — the interner allocates shells for all top-level exports at construction time.
TypeKeyidentity must be preserved for output naming or cross-referencing (keys are not carried in the resolved graph).- Startup cost is a concern —
ArenaInterner.createwalks and shells the entire export map eagerly, deferring only nested type resolution.
Types and nested modules
| Type/Module | Description |
|
Functions for constructing and walking an ArenaInterner. |
|
|
Lazily-resolved object graph view of a |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pairing of raw input data ( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A single segment of a fully qualified TypeScript name. Tagged either as
|
|
|
Bit flags describing structural anomalies in a single segment of a fully qualified TypeScript name (e.g. embedded quotation marks, slashes, or periods). |
|
|
The resolved (lazy-graph) form of a top-level TypeScript export declaration.
Holds direct references into the resolved type graph rather than |
|
|
The resolved (lazy-graph) form of a structural TypeScript type. Each case
directly references its dependencies (rather than carrying |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Active patterns
| Active pattern |
Description
|
Full Usage:
(|Resolve|) value
Parameters:
LazyContainer<'a, 'T>
Returns: 'T
Modifiers: inline Type parameters: 'a, 'T |
Active pattern for ergonomic forcing of a LazyContainer:
matching
|