Skip to main content

DefinitionStore

Struct DefinitionStore 

Source
pub struct DefinitionStore { /* private fields */ }
Expand description

Thread-safe storage for type definitions.

Uses DashMap for concurrent access from multiple checking threads.

§Usage

let store = DefinitionStore::new();

// Register a type alias
let def_id = store.register(DefinitionInfo::type_alias(
    interner.intern_string("Foo"),
    vec![],
    TypeId::NUMBER,
));

// Look up later
let info = store.get(def_id).expect("definition exists");

Implementations§

Source§

impl DefinitionStore

Source

pub fn new() -> Self

Create a new definition store.

Source

pub fn register(&self, info: DefinitionInfo) -> DefId

Register a new definition and return its DefId.

Source

pub fn get(&self, id: DefId) -> Option<DefinitionInfo>

Get definition info by DefId.

Source

pub fn get_symbol_id(&self, id: DefId) -> Option<u32>

Get the binder SymbolId for a DefId.

Returns the SymbolId (as raw u32) that this DefId was created from. This is available across checker contexts because it’s stored directly in the DefinitionInfo (which is shared via DefinitionStore).

Source

pub fn contains(&self, id: DefId) -> bool

Check if a DefId exists.

Source

pub fn get_kind(&self, id: DefId) -> Option<DefKind>

Get the kind of a definition.

Source

pub fn get_type_params(&self, id: DefId) -> Option<Vec<TypeParamInfo>>

Get type parameters for a definition.

Source

pub fn get_body(&self, id: DefId) -> Option<TypeId>

Get the body TypeId for a definition.

Source

pub fn get_instance_shape(&self, id: DefId) -> Option<Arc<ObjectShape>>

Get the instance shape for a class/interface.

Source

pub fn get_static_shape(&self, id: DefId) -> Option<Arc<ObjectShape>>

Get the static shape for a class.

Source

pub fn get_extends(&self, id: DefId) -> Option<DefId>

Get parent class DefId for a class.

Source

pub fn get_implements(&self, id: DefId) -> Option<Vec<DefId>>

Get implemented interfaces for a class/interface.

Source

pub fn set_body(&self, id: DefId, body: TypeId)

Update the body TypeId for a definition (for lazy evaluation).

Source

pub fn set_instance_shape(&self, id: DefId, shape: Arc<ObjectShape>)

Update the instance shape for a type definition.

This is used by checker code when a concrete object-like shape is computed for an interface/class definition and should be recorded for diagnostics.

Source

pub fn len(&self) -> usize

Number of definitions.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn clear(&self)

Clear all definitions (for testing).

Source

pub fn get_exports(&self, id: DefId) -> Option<Vec<(Atom, DefId)>>

Get exports for a namespace/module DefId.

Source

pub fn get_enum_members( &self, id: DefId, ) -> Option<Vec<(Atom, EnumMemberValue)>>

Get enum members for an enum DefId.

Source

pub fn get_name(&self, id: DefId) -> Option<Atom>

Get the name of a definition.

Source

pub fn set_exports(&self, id: DefId, exports: Vec<(Atom, DefId)>)

Update exports for a definition (for lazy population).

Source

pub fn add_export(&self, id: DefId, name: Atom, export_def: DefId)

Add an export to an existing definition.

Source

pub fn set_enum_members(&self, id: DefId, members: Vec<(Atom, EnumMemberValue)>)

Update enum members for a definition (for lazy population).

Source

pub fn all_ids(&self) -> Vec<DefId>

Get all DefIds (for debugging/testing).

Source

pub fn find_def_by_shape(&self, shape: &ObjectShape) -> Option<DefId>

Find a DefId by its instance shape.

This is used by the TypeFormatter to preserve interface names in error messages. When an Object type matches an interface’s instance shape, we use the interface name instead of expanding the object literal.

Trait Implementations§

Source§

impl Debug for DefinitionStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DefinitionStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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