Function naga::proc::index::access_needs_check
source · pub fn access_needs_check(
base: Handle<Expression>,
index: GuardedIndex,
module: &Module,
expressions: &Arena<Expression>,
info: &FunctionInfo,
) -> Option<IndexableLength>
Expand description
Determine whether index
is statically known to be in bounds for base
.
If we can’t be sure that the index is in bounds, return the limit within which valid indices must fall.
The return value is one of the following:
-
Some(Known(n))
indicates thatn
is the largest valid index. -
Some(Computed(global))
indicates that the largest valid index is one less than the length of the array that is the last member of the struct held inglobal
. -
None
indicates that the index need not be checked, either because it is statically known to be in bounds, or because the applicable policy isUnchecked
.
This function only handles subscriptable types: arrays, vectors, and matrices. It does not handle struct member indices; those never require run-time checks, so it’s best to deal with them further up the call chain.