Skip to main content

TypeLowering

Struct TypeLowering 

Source
pub struct TypeLowering<'a> { /* private fields */ }
Expand description

Type lowering context. Converts AST type nodes into interned TypeIds.

Implementations§

Source§

impl<'a> TypeLowering<'a>

Source

pub fn new(arena: &'a NodeArena, interner: &'a dyn QueryDatabase) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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 the NodeArena it belongs to.
Source

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.

Source

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.

Source

pub fn seed_type_params(&self, params: &[(Atom, TypeId)])

Source

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.

Source

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.

Source

pub fn import_type_params<'b, I>(&self, bindings: I)
where I: Iterator<Item = (&'b String, &'b TypeId)>,

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.

Source

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.

Source

pub fn lower_interface_declarations(&self, declarations: &[NodeIndex]) -> TypeId

Source

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.

Source

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. Array) so that the actual type parameters from the interface definition are used rather than synthesizing fresh ones that may have different TypeIds.

Source

pub fn lower_type_alias_declaration( &self, alias: &TypeAliasData, ) -> (TypeId, Vec<TypeParamInfo>)

Source

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 index
  • return_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.

Auto Trait Implementations§

§

impl<'a> Freeze for TypeLowering<'a>

§

impl<'a> !RefUnwindSafe for TypeLowering<'a>

§

impl<'a> !Send for TypeLowering<'a>

§

impl<'a> !Sync for TypeLowering<'a>

§

impl<'a> Unpin for TypeLowering<'a>

§

impl<'a> UnsafeUnpin for TypeLowering<'a>

§

impl<'a> !UnwindSafe for TypeLowering<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more