common: convert O(1) debug asserts to unconditional throws - #4493
Open
jhale wants to merge 2 commits into
Open
Conversation
local_range, MPI::distribute_data and sort_by_perm validated cheap, O(1) preconditions (positive size/shape1, size relationships) only via assert, which compiles out under NDEBUG. Bad arguments then caused a division by zero or an out-of-bounds read in Release builds instead of a diagnostic. Per AGENTS.md, an O(1) check should be an unconditional throw rather than assert-only, so convert these to std::invalid_argument and add Catch2 coverage. MPI::index_owner and math::det/inv/pinv were also surveyed but are called per-element inside hot loops (mesh partitioning, per-quadrature -point Jacobian computation), so they are intentionally left as assert-only per the "no exceptions in hot loops" rule. IndexMap.cpp is excluded from this pass as it is being hardened separately. AI assistance: I used Claude to draft this PR. I reviewed, edited, tested, and take responsibility for the final contribution.
jhale
added this pull request to stack #4494
September 13, 2026 10:16
jhale
commented
Sep 13, 2026
|
|
||
| using namespace dolfinx; | ||
|
|
||
| TEST_CASE("local_range bad arguments", "[local_range]") |
Member
Author
There was a problem hiding this comment.
Certainly over testing, will remove.
jhale
removed this pull request from stack #4494
September 13, 2026 12:37
jhale
added this pull request to stack #4498
September 13, 2026 12:38
jhale
removed this pull request from stack #4498
September 13, 2026 12:38
jhale
added this pull request to stack #4499
September 13, 2026 12:38
garth-wells
approved these changes
Sep 13, 2026
The added CHECK_THROWS_AS cases only verified that a one-line if (cond) throw fires, which doesn't exercise any meaningful logic and adds little confidence beyond what's already clear on inspection. AI assistance: I used Claude to draft this PR. I reviewed, edited, tested, and take responsibility for the final contribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
local_range, MPI::distribute_data and sort_by_perm validated cheap,
O(1) preconditions (positive size/shape1, size relationships) only via
assert, which compiles out under NDEBUG. Bad arguments then caused a
division by zero or an out-of-bounds read in Release builds instead of
a diagnostic. Per AGENTS.md, an O(1) check should be an unconditional
throw rather than assert-only, so convert these to
std::invalid_argument and add Catch2 coverage.
MPI::index_owner and math::det/inv/pinv were also surveyed but are
called per-element inside hot loops (mesh partitioning, per-quadrature
-point Jacobian computation), so they are intentionally left as
assert-only per the "no exceptions in hot loops" rule. IndexMap.cpp is
excluded from this pass as it is being hardened separately.
AI assistance: I used Claude to draft this PR. I reviewed, edited,
tested, and take responsibility for the final contribution.
Stack created with GitHub Stacks CLI • Give Feedback 💬