Struct naga::front::Typifier

source ·
pub struct Typifier { /* private fields */ }
Expand description

A table of types for an Arena<Expression>.

A front end can use a Typifier to get types for an arena’s expressions while it is still contributing expressions to it. At any point, you can call [typifier.grow(expr, arena, ctx)], where expr is a Handle<Expression> referring to something in arena, and the Typifier will resolve the types of all the expressions up to and including expr. Then you can write typifier[handle] to get the type of any handle at or before expr.

Note that Typifier does not build an Arena<Type> as a part of its usual operation. Ideally, a module’s type arena should only contain types actually needed by Handle<Type>s elsewhere in the module — functions, variables, Compose expressions, other types, and so on — so we don’t want every little thing that occurs as the type of some intermediate expression to show up there.

Instead, Typifier accumulates a TypeResolution for each expression, which refers to the Arena<Type> in the ResolveContext passed to grow as needed. TypeResolution is a lightweight representation for intermediate types like this; see its documentation for details.

If you do need to register a Typifier’s conclusion in an Arena<Type> (say, for a LocalVariable whose type you’ve inferred), you can use register_type to do so.

Implementations§

source§

impl Typifier

source

pub const fn new() -> Self

source

pub fn reset(&mut self)

source

pub fn get<'a>( &'a self, expr_handle: Handle<Expression>, types: &'a UniqueArena<Type> ) -> &'a TypeInner

source

pub fn register_type( &self, expr_handle: Handle<Expression>, types: &mut UniqueArena<Type> ) -> Handle<Type>

Add an expression’s type to an Arena<Type>.

Add the type of expr_handle to types, and return a Handle<Type> referring to it.

§Note

If you just need a TypeInner for expr_handle’s type, consider using typifier[expression].inner_with(types) instead. Calling TypeResolution::inner_with often lets us avoid adding anything to the arena, which can significantly reduce the number of types that end up in the final module.

source

pub fn grow( &mut self, expr_handle: Handle<Expression>, expressions: &Arena<Expression>, ctx: &ResolveContext<'_> ) -> Result<(), ResolveError>

Grow this typifier until it contains a type for expr_handle.

source

pub fn invalidate( &mut self, expr_handle: Handle<Expression>, expressions: &Arena<Expression>, ctx: &ResolveContext<'_> ) -> Result<(), ResolveError>

Recompute the type resolution for expr_handle.

If the type of expr_handle hasn’t yet been calculated, call grow to ensure it is covered.

In either case, when this returns, self[expr_handle] should be an updated type resolution for expr_handle.

Trait Implementations§

source§

impl Debug for Typifier

source§

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

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

impl Default for Typifier

source§

fn default() -> Typifier

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

impl Index<Handle<Expression>> for Typifier

§

type Output = TypeResolution

The returned type after indexing.
source§

fn index(&self, handle: Handle<Expression>) -> &Self::Output

Performs the indexing (container[index]) operation. 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, 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>,

§

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>,

§

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.