microsoft / microsoft/DirectXShaderCompiler
[HLSL] LinAlg HLK: Use a checked-arithmetic type for oracle size computations
@JoeCitizen is already working on this.
Since Aug 6, 2026.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Goal
Replace the bool return plus out-parameter shape of checkedMultiply and checkedAdd in LinAlgTests.cpp with a type that composes, so chained overflow-checked size computations read as arithmetic rather than as a cascade of early returns.
Why
Every other helper added by #8666 returns std::optional; these two are the exception and they are the older, weaker shape. Converting them to a bare std::optional is a strict improvement in isolation, but on the sites that actually matter — the buffer-size and element-offset computations, which chain three to four checked operations feeding each other — a bare optional trades one form of noise for another.
A small Checked{} wrapper with operator overloads collapses those chains to ordinary expressions and keeps a single validity test at the end. It should be designed against the real chained call sites, which is why this was deferred out of #8666 rather than done inline: there are 14 call sites in that PR and 43 by the end of the current stack.
Required work
- Design a minimal checked-integer type with the operators the oracle actually uses; do not build a general-purpose numerics facility.
- Convert
checkedMultiplyandcheckedAddand every call site. - Preserve the existing overflow diagnostics, including the raw-value logging.
Acceptance criteria
- No overflow-checked helper in
LinAlgTests.cppuses an out-parameter. - Overflow behaviour is unchanged, with a host test covering at least one overflowing and one non-overflowing chained computation.
LinAlgCPUOracleTestsandLinAlg::DxilConf_SM610_LinAlg::*are unchanged test for test.
Blocked on
Nothing, but it is cheaper after the current LinAlg HLK PR stack has landed, since the call site count roughly triples across it.
Public references
- Review thread on #8666 at L226.
Out of scope
- Templating the oracle (tracked separately).
- Any change to expected values or coverage.
Assisted-by: GitHub Copilot
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.