LightBoundsErrors
LightBoundsErrors is a Julia package providing a subtype of Exception, LightBoundsError, that is suitable as a replacement for BoundsError. Meant to be depended on by AbstractArray implementations and similar indexable types.
The advantage over BoundsError is that LightBoundsError does not store the array (or other indexable collection). Thus throwing LightBoundsError does not escape the array, unlike throwing BoundsError. This implies that LightBoundsError makes it possible for the Julia compiler to eliminate more heap allocations. Some of these benefits will only be realized as the compiler becomes capable of interprocedural escape analysis. Intraprocedural escape analysis is already here, but its success heavily depends on inlining behavior.
LightBoundsErrors.LightBoundsErrorLightBoundsErrors.checkbounds_lightboundserrorLightBoundsErrors.throw_lightboundserror
LightBoundsErrors.LightBoundsError — Type
LightBoundsErrorA subtype of Exception similar to BoundsError, but more friendly to the compiler optimizer.
Use throw_lightboundserror to throw LightBoundsError unconditionally.
Use checkbounds_lightboundserror to throw LightBoundsError conditionally.
LightBoundsErrors.checkbounds_lightboundserror — Method
checkbounds_lightboundserror(x, requested_indices...)Throw LightBoundsError if !checkbounds(Bool, x, requested_indices...). Otherwise, return nothing.
See also:
Example usage
julia> checkbounds_lightboundserror(rand(2, 2), 2, 3)
ERROR: LightBoundsError: out-of-bounds indexing: `collection[2, 3]`, where:
* `typeof(collection) == Matrix{Float64}`
* `axes(collection) == (Base.OneTo(2), Base.OneTo(2))`LightBoundsErrors.throw_lightboundserror — Method
throw_lightboundserror(x, requested_indices...)Throw LightBoundsError for the given indexable collection and indices.
See also:
Example usage
julia> throw_lightboundserror(rand(2, 2), 7)
ERROR: LightBoundsError: out-of-bounds indexing: `collection[7]`, where:
* `typeof(collection) == Matrix{Float64}`
* `axes(collection) == (Base.OneTo(2), Base.OneTo(2))`