Enum naga::proc::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
orAccessIndex
expression applied to aVector
orMatrix
must have aScalar
orVector
type. But sinceVector
andMatrix
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 aTypeResolution::Value(TypeInner::X { ... })
, whereX
isScalar
orVector
. -
Similarly, the type of an
Access
orAccessIndex
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 aTypeInner::Pointer
, since thePointer
’sbase
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 provideTypeInner::ValuePointer
, specifically for the case of pointers to scalars or vectors. This type fits in aTypeInner
and is exactly equivalent to aPointer
to aVector
orScalar
.
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
impl TypeResolution
pub const fn handle(&self) -> Option<Handle<Type>>
pub fn inner_with<'a>(&'a self, arena: &'a UniqueArena<Type>) -> &'a TypeInner
Trait Implementations§
source§impl Clone for TypeResolution
impl Clone for TypeResolution
source§impl Debug for TypeResolution
impl Debug for TypeResolution
source§impl PartialEq for TypeResolution
impl PartialEq for TypeResolution
impl StructuralPartialEq for TypeResolution
Auto Trait Implementations§
impl Freeze for TypeResolution
impl RefUnwindSafe for TypeResolution
impl Send for TypeResolution
impl Sync for TypeResolution
impl Unpin for TypeResolution
impl UnwindSafe for TypeResolution
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)