[STF] exception_policy: selecting arms decline by return, not by rethrow #11967
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 645 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.387
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11967"
general
weight: 0.35
andralex
Description
Stacked on #11889, which is stacked on #11888 (the first two commits here are those PRs' commits; only the third is new).
#11889 brought a declined arm of
|down to one unwind: the arm's ownthrow;. This PR removes that unwind for the arms that select on the exception, which is most of them in a boundary table or a typed ladder.The claim protocol. A guard (
catch_only,catch_exactly), a translator (translate) or a predicate (when) exposes two more hooks beside its exception hook:__claims(const std::exception)answers whether the hook would take the active exception:__yes,__no, or__unknownwhen the funnel pointer cannot tell (a non-std exception, or a listed non-class type). Type guards and translators answer withdynamic_cast/typeid, the same tests their hooks already ran; a predicate's claim is the predicate.__claimed(e, loc, fn)runs the hook body past its selection, so the selection is made once and a predicate is evaluated exactly once.|asks its left arm before invoking it. A__nosends the exception to the right arm by return, with the funnel pointer already in hand. A__yesruns the arm's__claimed.__unknowntakes the path from #11889, where the arm re-observes and declines by rethrowing.does the same before each repetition; a pure (type-based)__nodeclines the whole repetition at once, while a predicate's__nodeclines that repetition only, since the predicate may have state.&carries its head's claim (a declining head declines the sequence before anything has run; a later selector is asked in its own position, after the effects before it).|andcarry a claim of their own when their parts' claims are pure, so nested ladders are asked once at the top.Behaviour is unchanged on every path, including a non-std exception through a typed ladder, a translator whose translation is seen by the next arm, an effect ahead of a declining guard (
notify & catch_only<E>(p) | qstill notifies), and a guard whose inner policy declines by throwing after a positive claim.Measured
Paper harness (Exception-Sinks
benchmarks/overhead), g++ 13.3-O2, x86 (36 cores,powersavegovernor), pinned to one core, 7 Google Benchmark repetitions, median ns per call. Base is the head of #11889 (090a44d396).| guard | taken, base → this PR (ns) | hand (ns) |
|---|---|---|
|
catch_only<E1>(subst(1)) \| subst(0)| 1373 → 1368 | 1318–1337 || 2 arms + fallback, match on 2nd | 2310 → 1340 | 1255 |
| 4 arms + fallback, match on 4th | 5129 → 1424 | 1398 |
|
when(pred, subst(1)) \| subst(2), pred false | 2283 → 1269 | 1281 ||
subst(-1)| 1370 → 1330 | 1311–1329 ||
rethrow(identity) | 3144 → 3089 | 1383–1395 |A declined selecting arm now costs its
dynamic_castinstead of an unwind; the four-arm ladder is within 2% of the hand-written catch ladder. The identity's catch-plus-rethrow is unchanged, as expected (it is not a selector).Not-taken path: unchanged within the method's noise. Every library variant is 3.3–4.0 ns against 3.3–4.3 ns by hand, with run-to-run drift of the hand-written baseline of the same size as any difference (this machine's governor is
powersave; the paper's numbers are from a pinned Neoverse-V2).Code size (bytes, from the object file): hot parts unchanged (
lib_alt437 → 37,lib_subst33/36 → 33/36). Handler code grows:lib_alt2490 → 810,lib_alt41053 → 3140, since each|level inlines both the claimed and the general arm body;lib_whenshrinks 260 → 120. All of it is on the failure path.Verification
UNITTESTs (22 + the new one) compile and pass with nvcc 13.0 (-DUNITTESTED_FILE=...), before and afterclang-format22.1.5 (the pre-commit pin).-Wallwithout warnings against this header. clang++ is not installed on the measurement machine, so no clang numbers here.cudax/test/stf/utility/exception_policy_c_headers.cuandexamples/stf/exception_policies_reciprocal.cu, for the reason given in #11889 (local nvcc cudafe stub errors on the unpatched head as well); CI needs to cover them.New
UNITTEST("selecting arms decline by return")Pins the claims of each selecting policy (yes / no / unknown, including the null funnel and a non-class listed type), the composites' claims (
__has_pure_claimon|,&with a selecting head,; not onwhen), results on every path of a mixed ladder includingthrow 42, a translator on the left, single evaluation of a predicate whether it claims or declines, an effect before a declining guard still running, repetition over a type guard (declines at once) and over a stateful predicate (claims on the third repetition), an inner policy declining after a positive claim, and void callables through the same paths.Checklist
🤖 Generated with Claude Code