[STF] exception_policy: catch a declined exception once and inline the composite dispatch #11889
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 545 lines diff across 6 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.377
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11889"
general
weight: 0.35
andralex
Description
Stacked on #11888 (the first commit here is that PR's commit; only the second is new).
Two changes to the
|andcomposites inexception_policy.cuh, both found by measuring a guarded call against the hand-writtentry/catchwith the same behaviour.1. A declined exception is caught once. A hook declines with
throw;. The composite then caught everything and re-threw inside a nestedtryto recover thestd::exceptionfunnel pointer for the next arm: two complete unwinds per declined arm. The composite's owntrynow has typed clauses (const std::exception&,...) that recover the pointer directly. Same semantics, one unwind per declined arm.2. Composite dispatch is inlined. GCC 13 and Clang 18 both left
__policy_or::operator()and__interpret_answeras outlined functions. One outlined function on the failure path forces the policy aggregate, thesource_location, and the addresses of the callable's by-reference captures into memory before the guarded call, on the path where nothing throws. The composite hooks (|,,&,catch_only,catch_exactly) and the answer interpreter are now_CCCL_FORCEINLINE, and the|body is lambda-free so there is something small enough to inline.Measured
Neoverse-V2,
-O2, GCC 13.3. Median ± standard deviation, at 0.01 ns / 1 ns resolution (the stddev is repeatability, not accuracy; two independent harnesses disagree by up to 0.3 ns on the returning path), over 15 Google Benchmark repetitions (each repetition ≥ 0.5 s, about 330 M calls on the not-taken path and 110–460 k on the taken path, after a discarded warm-up), pinned to one core. Library guard vs hand-writtentry/catchwith identical behaviour; the callee alone costs 2.1 ns and one throw caught once costs ~1.5 µs here. Full protocol, harnesses and raw outputs: Exception-Sinksbenchmarks/overhead.| guard | returns, before → after (ns) | hand (ns) | throws, before → after (µs) | hand (µs) |
|---|---|---|---|---|
|
catch_only<E1>(subst(1)) \| subst(0)| 3.83 ± 0.01 → 2.05 ± <0.01 | 2.08 ± <0.01 | 1.539 ± <0.001 → 1.527 ± <0.001 | 1.506 ± <0.001 || 2 arms + fallback, match on 2nd | 6.61 ± 0.01 → 2.17 ± <0.01 | 2.09 ± 0.01 | 4.012 ± 0.001 → 2.767 ± 0.001 | 1.329 ± 0.001 |
| 4 arms + fallback, match on 4th | 6.51 ± <0.01 → 2.17 ± <0.01 | 2.08 ± <0.01 | 10.250 ± 0.004 → 6.180 ± 0.001 | 1.503 ± <0.001 |
|
when(pred, subst(1)) \| subst(2), pred false | 7.53 ± 0.01 → 2.08 ± <0.01 | 2.07 ± 0.01 | 3.991 ± 0.002 → 2.859 ± 0.001 | 1.341 ± 0.001 |Not-taken path instruction count (prologue to
ret): 40–46 → 5–7 (GCC), 24–28 → 7–9 (Clang); hand-written is 5 and 7. No outlined dispatch functions remain in the object file. Single-rule guards were already identical to hand-written code and are unchanged (2.08 ± 0.01 vs 2.09 ± 0.04 ns). Clang's four-arm alternation keeps a third callee-saved register save (3.56 ± <0.01 vs 2.28 ± <0.01 ns): clang hoists the shared__cxa_begin_catchabove the clause-selector test, so one selector per nesting level survives a call. Not reachable from the header.-O3alone changed nothing;-fno-stack-protectoralone removed 16 of GCC's 40 instructions.Code size moves the other way: inlining duplicates the arms' clauses into each landing pad, so GCC's four-arm alternation grows from 400 to 920 bytes (hand-written: 112). That code is on the failure path only.
The unwind that remains per declined arm (1.240 ± 0.001 µs with two arms, 1.551 ± 0.001 with four) is the hook's own
throw;, which is the library's decline protocol.Verification
UNITTESTs compile and pass withnvcc13.4 (-DUNITTESTED_FILE=...).clang-format22.1.5 (the pre-commit pin) applied.cudax/test/stf/utility/exception_policy_c_headers.cuandexamples/stf/exception_policies_reciprocal.cufail to build with the local nvcc 13.4 on the unpatched #11888 head as well (cudafe stub errors unrelated to this header), so CI needs to cover them.Checklist
🤖 Generated with Claude Code