pub struct TypedAst {Show 29 fields
pub parameter_default_prologues: BTreeMap<StmtId, usize>,
pub closure_this: BTreeMap<ExprId, Type>,
pub closure_names: BTreeMap<ExprId, Ident>,
pub nested_function_names: BTreeMap<ExprId, Ident>,
pub placeholder_closures: BTreeSet<ExprId>,
pub authored_arguments: BTreeMap<(u32, u32, u32), Vec<ExprId>>,
pub authored_parameter_types: BTreeMap<(u32, u32, u32), Type>,
pub parameter_inputs: BTreeSet<ExprId>,
pub parameter_initializations: BTreeSet<StmtId>,
pub runtime_source_types: BTreeMap<ExprId, Type>,
pub runtime_chain_types: BTreeMap<ExprId, Vec<Type>>,
pub spread_mask_fields: BTreeMap<ExprId, BTreeMap<String, Type>>,
pub spread_omitted_fields: BTreeMap<ExprId, BTreeSet<String>>,
pub exhaustive_switches: BTreeSet<ExprId>,
pub package_name: String,
pub globals: Vec<TypedGlobal>,
pub rebindable_globals: BTreeMap<MangledName, String>,
pub functions: Vec<TypedFunction>,
pub top_level_statements: Vec<StmtId>,
pub class_declaration_points: BTreeMap<MangledName, usize>,
pub types: Vec<TypedTypeDecl>,
pub shapes: Vec<Shape>,
pub exports: Vec<ExportEntry>,
pub imported_packages: BTreeSet<String>,
pub runtime_type_tests: BTreeMap<Type, FieldNarrowingTest>,
pub runtime_class_fields: BTreeMap<Type, Type>,
pub runtime_class_parameters: BTreeMap<MangledName, Vec<String>>,
pub runtime_class_contexts: BTreeMap<Type, Vec<InstanceTypeContext>>,
pub runtime_field_guards: BTreeMap<Type, Vec<InstantiatedFieldGuard>>,
/* private fields */
}Expand description
Compiler intermediate representation, produced by type inference and consumed by checking, capture analysis, desugaring, and code generation.
§Phase input contract
Public phase APIs accept compiler-produced trees at the appropriate pipeline stage. Only continue compilation when inference and checking report no errors. Public fields support compiler transformations and inspection; they do not make arbitrary hand-built trees supported phase inputs. Transformations must preserve the compiler’s type, binding, and metadata invariants.
In particular, every embedded Type must stay within
crate::compiler_limits::MAX_TYPE_DEPTH and
crate::compiler_limits::MAX_TYPE_NODES, including types in parameters,
declarations, shapes, captures, predicates, and runtime metadata. Inference
bounds annotation resolution, inferred expression types, and substitutions
before handing the tree to later phases. Replacing a payload invalidates that
guarantee; crate::type_size::check checks a replacement type’s bounds, not
the semantic validity of the containing tree.
crate::tree_height::check_typed checks arena structure, not these payload
invariants. Clone, formatting, and destruction can recurse through payloads,
including destruction when an owning phase returns an error. Keep their
bounds valid before transferring ownership, and perform phase work and
destruction on a crate::compiler_limits::COMPILER_STACK_BYTES stack.
Fields§
§parameter_default_prologues: BTreeMap<StmtId, usize>Number of parameter-initialization statements before a wrapped body.
closure_this: BTreeMap<ExprId, Type>Receiver types for ordinary function expressions; arrows capture their receiver.
closure_names: BTreeMap<ExprId, Ident>Named function-expression bindings, scoped to their closure body.
nested_function_names: BTreeMap<ExprId, Ident>The closures nested function declarations become, by declared name, so a diagnostic about one can name it as the function it is.
placeholder_closures: BTreeSet<ExprId>Closures with empty bodies that hold a nested function’s binding until its real closure is assigned. The typechecker rejects every use before then, so they are never called: a non-void one traps if it is.
Arguments before omitted defaults and rest packing, keyed by call span.
Parameter declaration types before optional/default ABI input widening.
parameter_inputs: BTreeSet<ExprId>Synthetic reads of incoming arguments before a parameter becomes initialized.
parameter_initializations: BTreeSet<StmtId>Callee prologue statements that initialize parameters and pattern bindings.
runtime_source_types: BTreeMap<ExprId, Type>Authored expression types retained by runtime-value lowering for member selection. Physical slot types live on the lowered expressions.
runtime_chain_types: BTreeMap<ExprId, Vec<Type>>§spread_mask_fields: BTreeMap<ExprId, BTreeMap<String, Type>>For each spread source read by name, the fields its value is checked against: every field one of its object types names, with the union of the types they give it, an index signature’s value type included.
spread_omitted_fields: BTreeMap<ExprId, BTreeSet<String>>For each spread source of an object rest, the names the rest leaves out whatever their value.
exhaustive_switches: BTreeSet<ExprId>The discriminants of the switches without a default whose cases the
typechecker found match every value the discriminant can hold.
package_name: StringModule name used for mangling. Defaults to USER_PACKAGE ("main").
globals: Vec<TypedGlobal>Slot definitions only; initializers are AssignGlobal in top_level_statements.
rebindable_globals: BTreeMap<MangledName, String>The globals code can rebind after the package loads that this package
declares or imports, each with how the source names it: a module let,
its own or one another package exports, and a static field not declared
readonly, as Class.field. Every static field is a GlobalKind::Const
global, so globals alone cannot tell.
functions: Vec<TypedFunction>Top-level function declarations. Hoisted — codegen doesn’t depend on source order.
top_level_statements: Vec<StmtId>Source-order _start body — currently one AssignGlobal per global initializer.
class_declaration_points: BTreeMap<MangledName, usize>Where each top-level class is declared: the index into
top_level_statements of the first statement that runs after it.
types: Vec<TypedTypeDecl>Type declarations (interface, enum) — no Wasm representation, no body.
Stored here so post-inference passes see member spans/types without re-exposing
the inferer’s TypeNamespace.
shapes: Vec<Shape>Distinct anonymous shapes (Object, Array, Union) reachable from the module.
Built at end of inference; consumers read this instead of re-walking the AST.
exports: Vec<ExportEntry>Public surface: one entry per export-marked declaration. Single source of
truth for visibility — TypedFunction/TypedGlobal carry no is_exported
flag. Built but not yet consumed for surface projection in single-file mode.
imported_packages: BTreeSet<String>External package names that were resolved from explicit imports in this module. This is deliberately package-level, not symbol-level: embedders use it to install only the package modules the typed program imports.
runtime_type_tests: BTreeMap<Type, FieldNarrowingTest>Concrete runtime validators resolved while inference still has access to interface declarations and generic substitutions. Codegen consults this for narrowed reads instead of re-deriving type structure.
runtime_class_fields: BTreeMap<Type, Type>Substituted data fields for generic-class runtime validation.
runtime_class_parameters: BTreeMap<MangledName, Vec<String>>§runtime_class_contexts: BTreeMap<Type, Vec<InstanceTypeContext>>§runtime_field_guards: BTreeMap<Type, Vec<InstantiatedFieldGuard>>Implementations§
Source§impl TypedAst
impl TypedAst
pub fn new() -> Self
pub fn with_package(package_name: impl Into<String>) -> Self
Sourcepub fn try_push_expr(&mut self, expr: TypedExpr) -> Result<ExprId, ArenaError>
pub fn try_push_expr(&mut self, expr: TypedExpr) -> Result<ExprId, ArenaError>
Checked allocation; failure leaves the arena unchanged.
Sourcepub fn try_push_stmt(&mut self, stmt: TypedStmt) -> Result<StmtId, ArenaError>
pub fn try_push_stmt(&mut self, stmt: TypedStmt) -> Result<StmtId, ArenaError>
Checked allocation; failure leaves the arena unchanged.
pub fn try_expr(&self, id: ExprId) -> Result<&TypedExpr, ArenaError>
pub fn try_stmt(&self, id: StmtId) -> Result<&TypedStmt, ArenaError>
pub fn try_expr_mut(&mut self, id: ExprId) -> Result<&mut TypedExpr, ArenaError>
pub fn try_stmt_mut(&mut self, id: StmtId) -> Result<&mut TypedStmt, ArenaError>
Sourcepub fn expr_ids(
&self,
) -> Result<impl DoubleEndedIterator<Item = ExprId> + use<>, ArenaError>
pub fn expr_ids( &self, ) -> Result<impl DoubleEndedIterator<Item = ExprId> + use<>, ArenaError>
Snapshot of allocated expression IDs, usable while appending new nodes.
Sourcepub fn stmt_ids(
&self,
) -> Result<impl DoubleEndedIterator<Item = StmtId> + use<>, ArenaError>
pub fn stmt_ids( &self, ) -> Result<impl DoubleEndedIterator<Item = StmtId> + use<>, ArenaError>
Snapshot of allocated statement IDs, usable while appending new nodes.
Sourcepub fn class_body_roots(&self) -> Vec<StmtId>
pub fn class_body_roots(&self) -> Vec<StmtId>
Body StmtIds of every class constructor + method — additional codegen
roots alongside functions (the string/bigint/closure/box collection
passes must walk these too).
Sourcepub fn class_field_initializers(&self) -> Vec<ExprId>
pub fn class_field_initializers(&self) -> Vec<ExprId>
Field-initializer expressions across all classes — expr roots that live
outside any statement body, so analysis/erasure passes must visit them too.
pub fn source_type(&self, id: ExprId) -> Result<&Type, ArenaError>
Sourcepub fn exprs_len(&self) -> usize
pub fn exprs_len(&self) -> usize
Used by post-inference passes to iterate just-pushed IDs (e.g. GenericParam erasure).
pub fn stmts_len(&self) -> usize
Sourcepub fn is_effect_free(&self, id: ExprId) -> Result<bool, ArenaError>
pub fn is_effect_free(&self, id: ExprId) -> Result<bool, ArenaError>
Whether evaluating id can be skipped without changing what the program
does. Deliberately a short whitelist of leaves: everything else — a call,
a field read that may hit an accessor, an operator that may throw — says
false, so a caller that folds an expression’s value away and relies on
this to decide whether to keep the computation errs toward keeping it.