Skip to content

Comments

throw LightBoundsError instead of BoundsError#37

Merged
jakobnissen merged 7 commits intoBioJulia:masterfrom
nsajko:LightBoundsError
Feb 20, 2026
Merged

throw LightBoundsError instead of BoundsError#37
jakobnissen merged 7 commits intoBioJulia:masterfrom
nsajko:LightBoundsError

Conversation

@nsajko
Copy link
Contributor

@nsajko nsajko commented Feb 19, 2026

Context: While BoundsError is common in the Julia world, its use is problematic for compiler optimizations. More specifically, Julia is gaining the ability to eliminate heap allocations as of recently, even for code that is not eliminated by dead code elimination or eliminated by constant folding. After the compiler gains interprocedural escape analysis capabilities, elimination of heap allocations should become applicable more often. The problem with BoundsError is that a BoundsError value holds a reference to the array that was attempted to be indexed out-of-bounds. Thus a BoundsError throw escapes the value of the array. Thus a BoundsError throw makes the elimination of the underlying heap allocation impossible, unless the throw is first eliminated by @inbounds or by other compiler optimizations.

The LightBoundsError exception from package LightBoundsErrors.jl addresses this by storing typeof(array) and axes(array) instead of storing array. The new package is already adopted as a dependency by FixedSizeArrays.jl.

Switching from BoundsError to LightBoundsError could hypothetically break a dependent of MemoryViews, in case a dependent branches on something like exception isa BoundsError while error handling.

Auto-checklist:

  • I have updated any relevant documentation and docstrings.
  • I have added unit tests, and the CodeCov bot shows tests cover my new code.
  • I have mentioned my changes in the CHANGELOG.md file.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.89%. Comparing base (ad50c1e) to head (bdbf158).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/basic.jl 72.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #37      +/-   ##
==========================================
+ Coverage   97.88%   97.89%   +0.01%     
==========================================
  Files          10       10              
  Lines         331      333       +2     
==========================================
+ Hits          324      326       +2     
  Misses          7        7              
Flag Coverage Δ
unittests 97.89% <76.92%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jakobnissen jakobnissen added the BREAKING Breaking PR label Feb 19, 2026
@jakobnissen
Copy link
Member

This is a good idea. Too bad that BoundsError was designed that way. I'm going to roll it up with #19 when releasing v0.4

@jakobnissen
Copy link
Member

LGTM. Its still a draft, but whenever you set it ready to merge, I’ll review the package for whether any APIs could use an overhaul, then release v0.4

@nsajko nsajko marked this pull request as ready for review February 19, 2026 15:20
@jakobnissen jakobnissen merged commit 2f528e2 into BioJulia:master Feb 20, 2026
11 checks passed
@nsajko nsajko deleted the LightBoundsError branch February 20, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BREAKING Breaking PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants