naga::proc::index

Function access_needs_check

Source
pub fn access_needs_check(
    base: Handle<Expression>,
    index: GuardedIndex,
    module: &Module,
    function: &Function,
    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 that n 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 in global.

  • None indicates that the index need not be checked, either because it is statically known to be in bounds, or because the applicable policy is Unchecked.

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.