Struct Typifier
pub struct Typifier { /* private fields */ }unstable-wgpu-26 only.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§
§impl Typifier
impl Typifier
pub const fn new() -> Typifier
pub fn reset(&mut self)
pub fn get<'a>( &'a self, expr_handle: Handle<Expression>, types: &'a UniqueArena<Type>, ) -> &'a TypeInner
pub fn register_type(
&self,
expr_handle: Handle<Expression>,
types: &mut UniqueArena<Type>,
) -> Handle<Type>
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.
pub fn grow(
&mut self,
expr_handle: Handle<Expression>,
expressions: &Arena<Expression>,
ctx: &ResolveContext<'_>,
) -> Result<(), ResolveError>
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.
pub fn invalidate(
&mut self,
expr_handle: Handle<Expression>,
expressions: &Arena<Expression>,
ctx: &ResolveContext<'_>,
) -> Result<(), ResolveError>
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§
§impl Index<Handle<Expression>> for Typifier
impl Index<Handle<Expression>> for Typifier
§type Output = TypeResolution
type Output = TypeResolution
§fn index(
&self,
handle: Handle<Expression>,
) -> &<Typifier as Index<Handle<Expression>>>::Output
fn index( &self, handle: Handle<Expression>, ) -> &<Typifier as Index<Handle<Expression>>>::Output
container[index]) operation. Read moreAuto Trait Implementations§
impl Freeze for Typifier
impl RefUnwindSafe for Typifier
impl Send for Typifier
impl Sync for Typifier
impl Unpin for Typifier
impl UnwindSafe for Typifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.