← Back to Pull requests

[STF] exception_policy: selecting arms decline by return, not by rethrow #11967

Closed
unknown closed this pull request without merging on Oct 27, 2026 16:28 UTC
View on GitHub
unknown unknown commented on Oct 09, 2026 12:54 UTC
Author

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 own throw;. 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 __unknown when the funnel pointer cannot tell (a non-std exception, or a listed non-class type). Type guards and translators answer with dynamic_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 __no sends the exception to the right arm by return, with the funnel pointer already in hand. A __yes runs the arm's __claimed. __unknown takes the path from #11889, where the arm re-observes and declines by rethrowing. does the same before each repetition; a pure (type-based) __no declines the whole repetition at once, while a predicate's __no declines 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). | and carry 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) | q still 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, powersave governor), 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_cast instead 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_alt4 37 → 37, lib_subst 33/36 → 33/36). Handler code grows: lib_alt2 490 → 810, lib_alt4 1053 → 3140, since each | level inlines both the claimed and the general arm body; lib_when shrinks 260 → 120. All of it is on the failure path.

    Verification

  • The header's 23 embedded UNITTESTs (22 + the new one) compile and pass with nvcc 13.0 (-DUNITTESTED_FILE=...), before and after clang-format 22.1.5 (the pre-commit pin).

  • The paper's benchmark variants compile with g++ 13.3 -Wall without warnings against this header. clang++ is not installed on the measurement machine, so no clang numbers here.

  • Not verified here: cudax/test/stf/utility/exception_policy_c_headers.cu and examples/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_claim on |, & with a selecting head, ; not on when), results on every path of a mixed ladder including throw 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


  • New or existing tests cover these changes.

  • The documentation is up to date with these changes.
  • 🤖 Generated with Claude Code

    Diff: 645 lines (+483 / -162) across 8 files Reviewer: andralex Review duration: 26134m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.0% (MEDIUM) · Higher = larger blast radius
    52.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository