pub enum TypeResolution {
    Handle(Handle<Type>),
    Value(TypeInner),
}
Expand description

The result of computing an expression’s type.

This is the (Rust) type returned by ResolveContext::resolve to represent the (Naga) type it ascribes to some expression.

You might expect such a function to simply return a Handle<Type>. However, we want type resolution to be a read-only process, and that would limit the possible results to types already present in the expression’s associated UniqueArena<Type>. Naga IR does have certain expressions whose types are not certain to be present.

So instead, type resolution returns a TypeResolution enum: either a Handle, referencing some type in the arena, or a Value, holding a free-floating TypeInner. This extends the range to cover anything that can be represented with a TypeInner referring to the existing arena.

What sorts of expressions can have types not available in the arena?

  • An Access or AccessIndex expression applied to a Vector or Matrix must have a Scalar or Vector type. But since Vector and Matrix represent their element and column types implicitly, not via a handle, there may not be a suitable type in the expression’s associated arena. Instead, resolving such an expression returns a TypeResolution::Value(TypeInner::X { ... }), where X is Scalar or Vector.

  • Similarly, the type of an Access or AccessIndex expression applied to a pointer to a vector or matrix must produce a pointer to a scalar or vector type. These cannot be represented with a TypeInner::Pointer, since the Pointer’s base must point into the arena, and as before, we cannot assume that a suitable scalar or vector type is there. So we take things one step further and provide TypeInner::ValuePointer, specifically for the case of pointers to scalars or vectors. This type fits in a TypeInner and is exactly equivalent to a Pointer to a Vector or Scalar.

So, for example, the type of an Access expression applied to a value of type:

TypeInner::Matrix { columns, rows, width }

might be:

TypeResolution::Value(TypeInner::Vector {
    size: rows,
    kind: ScalarKind::Float,
    width,
})

and the type of an access to a pointer of address space space to such a matrix might be:

TypeResolution::Value(TypeInner::ValuePointer {
    size: Some(rows),
    kind: ScalarKind::Float,
    width,
    space,
})

Variants§

§

Handle(Handle<Type>)

A type stored in the associated arena.

§

Value(TypeInner)

A free-floating TypeInner, representing a type that may not be available in the associated arena. However, the TypeInner itself may contain Handle<Type> values referring to types from the arena.

The inner type must only be one of the following variants:

  • TypeInner::Pointer
  • TypeInner::ValuePointer
  • TypeInner::Matrix (generated by matrix multiplication)
  • TypeInner::Vector
  • TypeInner::Scalar

Implementations§

source§

impl TypeResolution

source

pub fn to_wgsl(&self, gctx: &GlobalCtx<'_>) -> String

source§

impl TypeResolution

source

pub const fn handle(&self) -> Option<Handle<Type>>

source

pub fn inner_with<'a>(&'a self, arena: &'a UniqueArena<Type>) -> &'a TypeInner

Trait Implementations§

source§

impl Clone for TypeResolution

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TypeResolution

source§

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

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

impl<'de> Deserialize<'de> for TypeResolution

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for TypeResolution

source§

fn eq(&self, other: &TypeResolution) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for TypeResolution

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for TypeResolution

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,