Enum naga::proc::TypeResolution[][src]

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 storage class class to such a matrix might be:

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

Variants

Handle(Handle<Type>)

Tuple Fields

A type stored in the associated arena.

Value(TypeInner)

Tuple Fields

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.