Conversation
…sert Factory arguments were checked with assert, so a release build accepted a null holder or mismatched if_then_else branches and built a malformed node. pow, the comparisons, max, min and if_then_else in all three domains now throw invalid_expression_error; the tensor branch-shape check runs before the constant-condition folds, which previously hid the mismatch. is_same_r returns nullopt for a null holder instead of asserting, since it is noexcept and cannot report otherwise. sequence.h raised std::out_of_range and std::invalid_argument, outside the cas_error hierarchy a caller is told to catch; every throw is now invalid_expression_error with the same message. Signed-off-by: petlenz <peterlenz89.pl@gmail.com>
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.
Addresses the assert half of #483; the policy/CI-grep half stays open.
Library asserts guarding user-reachable preconditions vanish under NDEBUG, so a release build silently built malformed nodes — the class already fixed for tensors (#360/#438) and t2s invariants (#439/#474). This converts the remaining ones and moves
sequence.hinto thecas_errorhierarchy.36-assert classification (
grep -rn "assert(" include src, static_asserts excluded):scalar_std.h:77-78pow,:313comparisons,:460-461max,:487-488min,:608-610if_then_elseinvalid_expression_errorvia newdetail::require_valid(op, holders...)tensor_std.h:141-143, 169-171if_then_else null holderstensor_std.h:145-146, 173-174if_then_else branch dim/rankif_then_else(zero, X, C4)returnedC4without ever reaching the ctor. Nowvalidate_same_shaperuns before the foldstensor_to_scalar_std.h:215-217if_then_elsebasic_functions.h:21is_same_rnoexcept— returnsnulloptfor a null holderexpression_holder.h:93,103get() downcastthrow_if_invalid()already throws for null; the assert only checks the T the caller asked for after an id check upstreamvisitor_base.h:118,124,n_ary_tree.h:159,tensor_scalar_mul.h:48id()tie, unreachable by user input (typeid tiebreak from #442 guards cross-type)scalar_differentiation.h:339projection_tensor.h:45clear_space()no-op overridepositivity_propagation.h:43#ifndef NDEBUGby designtensor_to_scalar_functions.cpp:47,69,85trace/norm/det ranktensor.h:52-53sequence.h: the 7std::out_of_range/std::invalid_argumentthrows (ctor 0-index,split,split_many,permute×2,invert_perm×2) are nowinvalid_expression_errorwith unchanged messages. Nothing ininclude/,src/ortests/catches the std types specifically; the fuzz harness catchesstd::exceptiononly as its "unexpected" path (#376), which these no longer hit.Tests (each fails without the fix):
ScalarFixture.FactoriesRejectInvalidHolder,TensorShapeValidation.IfThenElseBranchesShareShape,TensorToScalar_IfThenElseRejectsInvalidHolder(dims 1–3),IndexSequenceIdentity.ErrorsDeriveFromCasError.Negative control in Release (the point of the issue), headers restored from main via
git show, rebuilt clean: the tensor branch-shape and null-holder checks "throw nothing";sequencethrowsstd::out_of_range/std::invalid_argumenton all 7 sites; the scalar case terminates the process — the null holder reaches anoexceptpath that throws — which is worse than a failed assertion. In Debug the old asserts abort instead. All pass with the fix.Suites: Debug 2411/2411, Release 2411/2411, parser-enabled 2597/2597 (gcc-14). clang-format clean. Fuzz unchanged (known rank-limit skips only).