Skip to main content

TypeResolver

Trait TypeResolver 

Source
pub trait TypeResolver {
Show 21 methods // Required method fn resolve_ref( &self, symbol: SymbolRef, interner: &dyn TypeDatabase, ) -> Option<TypeId>; // Provided methods fn resolve_symbol_ref( &self, symbol: SymbolRef, interner: &dyn TypeDatabase, ) -> Option<TypeId> { ... } fn resolve_lazy( &self, _def_id: DefId, _interner: &dyn TypeDatabase, ) -> Option<TypeId> { ... } fn get_type_params(&self, _symbol: SymbolRef) -> Option<Vec<TypeParamInfo>> { ... } fn get_lazy_type_params(&self, _def_id: DefId) -> Option<Vec<TypeParamInfo>> { ... } fn def_to_symbol_id(&self, _def_id: DefId) -> Option<SymbolId> { ... } fn symbol_to_def_id(&self, _symbol: SymbolRef) -> Option<DefId> { ... } fn get_def_kind(&self, _def_id: DefId) -> Option<DefKind> { ... } fn get_boxed_type(&self, _kind: IntrinsicKind) -> Option<TypeId> { ... } fn is_boxed_def_id(&self, _def_id: DefId, _kind: IntrinsicKind) -> bool { ... } fn is_boxed_type_id(&self, _type_id: TypeId, _kind: IntrinsicKind) -> bool { ... } fn get_array_base_type(&self) -> Option<TypeId> { ... } fn get_array_base_type_params(&self) -> &[TypeParamInfo] { ... } fn get_lazy_export(&self, _def_id: DefId, _name: Atom) -> Option<TypeId> { ... } fn get_lazy_enum_member( &self, _def_id: DefId, _name: Atom, ) -> Option<TypeId> { ... } fn is_numeric_enum(&self, _def_id: DefId) -> bool { ... } fn is_enum_type( &self, _type_id: TypeId, _interner: &dyn TypeDatabase, ) -> bool { ... } fn get_enum_parent_def_id(&self, _member_def_id: DefId) -> Option<DefId> { ... } fn is_user_enum_def(&self, _def_id: DefId) -> bool { ... } fn get_base_type( &self, _type_id: TypeId, _interner: &dyn TypeDatabase, ) -> Option<TypeId> { ... } fn get_type_param_variance(&self, _def_id: DefId) -> Option<Arc<[Variance]>> { ... }
}
Expand description

Trait for resolving type references to their structural types. This allows the SubtypeChecker to lazily resolve Ref types without being tightly coupled to the binder/checker.

Required Methods§

Source

fn resolve_ref( &self, symbol: SymbolRef, interner: &dyn TypeDatabase, ) -> Option<TypeId>

Resolve a symbol reference to its structural type. Returns None if the symbol cannot be resolved.

Deprecated: use resolve_lazy with DefId instead.

Provided Methods§

Source

fn resolve_symbol_ref( &self, symbol: SymbolRef, interner: &dyn TypeDatabase, ) -> Option<TypeId>

Resolve a symbol reference to a structural type, preferring DefId-based lazy paths.

Prefers resolve_lazy via DefId when available, falling back to resolve_ref.

Source

fn resolve_lazy( &self, _def_id: DefId, _interner: &dyn TypeDatabase, ) -> Option<TypeId>

Resolve a DefId reference to its structural type.

This is the DefId equivalent of resolve_ref, used for TypeData::Lazy(DefId). DefIds are Solver-owned identifiers that decouple type references from the Binder.

Returns None by default; implementations should override to support Lazy type resolution.

Source

fn get_type_params(&self, _symbol: SymbolRef) -> Option<Vec<TypeParamInfo>>

Get type parameters for a symbol (for generic type aliases/interfaces). Returns None by default; implementations can override to support Application type expansion.

Source

fn get_lazy_type_params(&self, _def_id: DefId) -> Option<Vec<TypeParamInfo>>

Get type parameters for a DefId (for generic type aliases/interfaces).

This is the DefId equivalent of get_type_params. Returns None by default; implementations can override to support Application type expansion with Lazy types.

Source

fn def_to_symbol_id(&self, _def_id: DefId) -> Option<SymbolId>

Get the SymbolId for a DefId (bridge for InheritanceGraph).

This enables DefId-based types to use the existing O(1) InheritanceGraph by mapping DefIds back to their corresponding SymbolIds. The mapping is maintained by the Binder/Checker during type resolution.

Returns None if the DefId doesn’t have a corresponding SymbolId.

Source

fn symbol_to_def_id(&self, _symbol: SymbolRef) -> Option<DefId>

Get the DefId for a SymbolRef (Ref -> Lazy migration).

This enables migrating Ref(SymbolRef) types to Lazy(DefId) resolution logic. When a SymbolRef has a corresponding DefId, we should use resolve_lazy instead of resolve_ref for consistent type identity.

Returns None if the SymbolRef doesn’t have a corresponding DefId.

Source

fn get_def_kind(&self, _def_id: DefId) -> Option<DefKind>

Get the DefKind for a DefId (Task #32: Graph Isomorphism).

This is used by the Canonicalizer to distinguish between structural types (TypeAlias - should be canonicalized with Recursive indices) and nominal types (Interface/Class/Enum - must remain as Lazy(DefId) for nominal identity).

Returns None if the DefId doesn’t exist or the implementation doesn’t support DefKind lookup.

Source

fn get_boxed_type(&self, _kind: IntrinsicKind) -> Option<TypeId>

Get the boxed interface type for a primitive intrinsic (Rule #33). For example, IntrinsicKind::Number -> TypeId of the Number interface. This enables primitives to be subtypes of their boxed interfaces.

Source

fn is_boxed_def_id(&self, _def_id: DefId, _kind: IntrinsicKind) -> bool

Check if a DefId corresponds to a boxed type for the given intrinsic kind.

Source

fn is_boxed_type_id(&self, _type_id: TypeId, _kind: IntrinsicKind) -> bool

Check if a TypeId is any known resolved form of a boxed type.

The Object interface (and other boxed types) can have multiple TypeIds: one from resolve_lib_type_by_name and another from type_reference_symbol_type. This method checks all registered boxed DefIds and their resolved TypeIds.

Source

fn get_array_base_type(&self) -> Option<TypeId>

Get the Array interface type from lib.d.ts.

Source

fn get_array_base_type_params(&self) -> &[TypeParamInfo]

Get the type parameters for the Array interface.

Source

fn get_lazy_export(&self, _def_id: DefId, _name: Atom) -> Option<TypeId>

Get an export from a namespace/module by name.

Used for qualified name resolution: namespace.member.

Source

fn get_lazy_enum_member(&self, _def_id: DefId, _name: Atom) -> Option<TypeId>

Get enum member type by name from an enum DefId.

Used for enum member access: Enum.Member.

Source

fn is_numeric_enum(&self, _def_id: DefId) -> bool

Check if a DefId corresponds to a numeric enum (not a string enum).

Used for TypeScript’s unsound Rule #7 (Open Numeric Enums) where number types are assignable to/from numeric enums.

Source

fn is_enum_type(&self, _type_id: TypeId, _interner: &dyn TypeDatabase) -> bool

Check if a TypeId represents a full Enum type (not a specific member).

Source

fn get_enum_parent_def_id(&self, _member_def_id: DefId) -> Option<DefId>

Get the parent Enum’s DefId for an Enum Member’s DefId.

Used to check nominal relationships between enum members and their parent types.

Source

fn is_user_enum_def(&self, _def_id: DefId) -> bool

Check if a DefId represents a user-defined enum (not an intrinsic type).

Source

fn get_base_type( &self, _type_id: TypeId, _interner: &dyn TypeDatabase, ) -> Option<TypeId>

Get the base class type for a class/interface type.

Used by the Best Common Type (BCT) algorithm to find common base classes.

Source

fn get_type_param_variance(&self, _def_id: DefId) -> Option<Arc<[Variance]>>

Get the variance mask for type parameters of a generic type (Task #41).

Used by check_application_to_application_subtype to optimize generic assignability checks via variance annotations instead of full structural expansion.

Implementations on Foreign Types§

Source§

impl<T: TypeResolver + ?Sized> TypeResolver for &T

Blanket implementation of TypeResolver for references to resolver types.

This allows &dyn TypeResolver (which is Sized) to be used wherever R: TypeResolver is expected.

Source§

fn resolve_ref( &self, _symbol: SymbolRef, _interner: &dyn TypeDatabase, ) -> Option<TypeId>

Source§

fn resolve_lazy( &self, def_id: DefId, interner: &dyn TypeDatabase, ) -> Option<TypeId>

Source§

fn get_type_params(&self, symbol: SymbolRef) -> Option<Vec<TypeParamInfo>>

Source§

fn get_lazy_type_params(&self, def_id: DefId) -> Option<Vec<TypeParamInfo>>

Source§

fn symbol_to_def_id(&self, symbol: SymbolRef) -> Option<DefId>

Implementors§

Source§

impl TypeResolver for QueryCache<'_>

Implement TypeResolver for QueryCache with noop resolution.

QueryCache doesn’t have access to the Binder or type environment, so it cannot resolve symbol references or DefIds. Only resolve_ref (required) is explicitly implemented; all other resolution methods inherit the trait’s default None/false behavior. The three boxed/array methods delegate to the underlying interner.

Source§

impl TypeResolver for TypeInterner

Implement TypeResolver for TypeInterner with noop resolution.

TypeInterner doesn’t have access to the Binder or type environment, so it cannot resolve symbol references or DefIds. Only resolve_ref (required) is explicitly implemented; all other resolution methods inherit the trait’s default None/false behavior. The three boxed/array methods delegate to TypeInterner’s own inherent methods.

Source§

impl TypeResolver for NoopResolver

Source§

impl TypeResolver for TypeEnvironment