naga::proc

Enum TypeResolution

Source
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.

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 PartialEq for TypeResolution

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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

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.