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 thatnis 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. -
Noneindicates 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.
This function assumes that any relevant overrides have fully-evaluated
constants as their values (as arranged by process_overrides, for
example).
§Panics
-
If
baseis not an indexable type, panic. -
If
baseis an override-sized array, but the override’s value is not a fully-evaluated constant expression, panic.