pub struct TypeLowering<'a> { /* private fields */ }Expand description
Type lowering context.
Converts AST type nodes into interned TypeIds.
Implementations§
Source§impl<'a> TypeLowering<'a>
impl<'a> TypeLowering<'a>
pub fn new(arena: &'a NodeArena, interner: &'a dyn QueryDatabase) -> Self
Sourcepub fn with_resolver(
arena: &'a NodeArena,
interner: &'a dyn QueryDatabase,
resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
) -> Self
pub fn with_resolver( arena: &'a NodeArena, interner: &'a dyn QueryDatabase, resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, ) -> Self
Create a TypeLowering with a symbol resolver.
The resolver converts identifier names to actual SymbolIds from the binder.
Sourcepub fn with_resolvers(
arena: &'a NodeArena,
interner: &'a dyn QueryDatabase,
type_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
) -> Self
pub fn with_resolvers( arena: &'a NodeArena, interner: &'a dyn QueryDatabase, type_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, ) -> Self
Create a TypeLowering with separate type/value resolvers.
Sourcepub fn with_def_id_resolver(
arena: &'a NodeArena,
interner: &'a dyn QueryDatabase,
def_id_resolver: &'a dyn Fn(NodeIndex) -> Option<DefId>,
value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
) -> Self
pub fn with_def_id_resolver( arena: &'a NodeArena, interner: &'a dyn QueryDatabase, def_id_resolver: &'a dyn Fn(NodeIndex) -> Option<DefId>, value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, ) -> Self
Create a TypeLowering with a DefId resolver (Phase 1 migration).
This is the migration path from SymbolRef to DefId for type identity.
The DefId resolver resolves identifier nodes to Solver-owned DefIds
instead of Binder-owned SymbolIds.
Sourcepub fn with_hybrid_resolver(
arena: &'a NodeArena,
interner: &'a dyn QueryDatabase,
type_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
def_id_resolver: &'a dyn Fn(NodeIndex) -> Option<DefId>,
value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>,
) -> Self
pub fn with_hybrid_resolver( arena: &'a NodeArena, interner: &'a dyn QueryDatabase, type_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, def_id_resolver: &'a dyn Fn(NodeIndex) -> Option<DefId>, value_resolver: &'a dyn Fn(NodeIndex) -> Option<u32>, ) -> Self
Create a TypeLowering with both type and DefId resolvers (Phase 2 migration).
This allows TypeLowering to prefer DefId when available, but fall back
to SymbolId for types that don’t have a DefId yet.
Sourcepub fn with_arena<'b>(&'b self, arena: &'b NodeArena) -> TypeLowering<'b>where
'a: 'b,
pub fn with_arena<'b>(&'b self, arena: &'b NodeArena) -> TypeLowering<'b>where
'a: 'b,
Create a new TypeLowering sharing the same context/state but using a different arena.
This is used for lowering merged interface declarations that span multiple lib files.
Sourcepub fn lower_merged_interface_declarations(
&self,
declarations: &[(NodeIndex, &NodeArena)],
) -> (TypeId, Vec<TypeParamInfo>)
pub fn lower_merged_interface_declarations( &self, declarations: &[(NodeIndex, &NodeArena)], ) -> (TypeId, Vec<TypeParamInfo>)
Lower interface declarations that may span multiple arenas (lib files).
For merged interfaces like Array which is declared in es5.d.ts, es2015.d.ts, etc.,
each declaration may be in a different NodeArena. This method handles looking up
each declaration in its correct arena.
§Arguments
declarations- List of (NodeIndex, &NodeArena) pairs. Each declaration must be paired with theNodeArenait belongs to.
Sourcepub fn collect_merged_interface_type_parameters(
&self,
declarations: &[(NodeIndex, &NodeArena)],
) -> Vec<TypeParamInfo>
pub fn collect_merged_interface_type_parameters( &self, declarations: &[(NodeIndex, &NodeArena)], ) -> Vec<TypeParamInfo>
Collect type parameters from merged interface declarations without lowering members.
This is a lightweight path used when callers only need generic parameter metadata (names/constraints/defaults) and not the full interface body.
Sourcepub fn collect_type_alias_type_parameters(
&self,
alias: &TypeAliasData,
) -> Vec<TypeParamInfo>
pub fn collect_type_alias_type_parameters( &self, alias: &TypeAliasData, ) -> Vec<TypeParamInfo>
Collect type parameters for a type alias declaration without lowering the alias body.
pub fn seed_type_params(&self, params: &[(Atom, TypeId)])
Sourcepub fn with_type_param_bindings(self, bindings: Vec<(Atom, TypeId)>) -> Self
pub fn with_type_param_bindings(self, bindings: Vec<(Atom, TypeId)>) -> Self
Initialize with existing type parameter bindings.
These are added to a new scope that persists for the lifetime of the TypeLowering.
Sourcepub fn with_name_def_id_resolver(
self,
resolver: &'a dyn Fn(&str) -> Option<DefId>,
) -> Self
pub fn with_name_def_id_resolver( self, resolver: &'a dyn Fn(&str) -> Option<DefId>, ) -> Self
Set the name-based DefId resolver for cross-arena resolution.
Sourcepub fn import_type_params<'b, I>(&self, bindings: I)
pub fn import_type_params<'b, I>(&self, bindings: I)
Import type parameter bindings from an external scope (e.g., checker’s type parameter scope).
This allows TypeLowering to access type parameters that were defined outside of it.
Sourcepub fn lower_type(&self, node_idx: NodeIndex) -> TypeId
pub fn lower_type(&self, node_idx: NodeIndex) -> TypeId
Lower a type node to a TypeId.
This is the main entry point for type synthesis.
pub fn lower_interface_declarations(&self, declarations: &[NodeIndex]) -> TypeId
Sourcepub fn lower_interface_declarations_with_symbol(
&self,
declarations: &[NodeIndex],
sym_id: SymbolId,
) -> TypeId
pub fn lower_interface_declarations_with_symbol( &self, declarations: &[NodeIndex], sym_id: SymbolId, ) -> TypeId
Lower interface declarations and stamp the resulting type with a SymbolId.
This is used by the type checker to preserve symbol information for import generation.
The SymbolId allows UsageAnalyzer to trace which imported interfaces are used in exported APIs.
Sourcepub fn lower_interface_declarations_with_params(
&self,
declarations: &[NodeIndex],
) -> (TypeId, Vec<TypeParamInfo>)
pub fn lower_interface_declarations_with_params( &self, declarations: &[NodeIndex], ) -> (TypeId, Vec<TypeParamInfo>)
Lower interface declarations and also return the collected type parameters.
This is needed when registering generic lib types (e.g. ArrayTypeIds.
pub fn lower_type_alias_declaration( &self, alias: &TypeAliasData, ) -> (TypeId, Vec<TypeParamInfo>)
Sourcepub fn lower_signature_from_declaration(
&self,
node_idx: NodeIndex,
return_type_override: Option<TypeId>,
) -> TypeId
pub fn lower_signature_from_declaration( &self, node_idx: NodeIndex, return_type_override: Option<TypeId>, ) -> TypeId
Lower a function-like declaration (Method, Constructor, Function) to a TypeId.
This is used for overload compatibility checking where we need the structural type
of a specific declaration node, which might not be cached in the node_types map.
§Arguments
node_idx- The declaration node indexreturn_type_override- Optional return type to use instead of the annotation. (Useful for implementation signatures where return type is inferred from body)
§Returns
The TypeId of the function shape, or TypeId::ERROR if lowering fails.