You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: unify residual-support cap as kMaxResidualSupport=6 (#31)
* fix: unify residual-support cap as kMaxResidualSupport=6
The residual-family solvers (ghost basis, factored ghost, residual
polynomial recovery, ExtractPolyCore) cap support size at 6 to keep
SolveGhostResidual's combo/args/var_indices buffers and ProbePoint::values
within fixed bounds. The constant 6 was duplicated across at least seven
sites — five residual passes, IsBooleanNullResidual, ExtractPolyCore,
plus the array sizes themselves. The companion GhostPrimitive::arity
contract — that each primitive's eval/build span is exactly the declared
arity — was unenforced on either side, so a future basis entry with
arity > 6 would silently never run today (skipped by support-size guard)
but corrupt stack memory if a caller ever passed a smaller cap.
Closes the ghost-residual-arity cluster from the 2026-05-04 audit:
- decomposition-engine-cross-4: max_real_vars=6 cap enforced inconsistently
- decomposition-engine-cross-1: GhostPrimitive arity vs fixed 6-element buffers
- decomposition-engine-cross-3: GhostPrimitive Eval/Build span-size contract implicit
Adds `inline constexpr uint32_t kMaxResidualSupport = 6;` in
GhostResidualSolver.h and references it from every site:
- 4 residual-pass guards in DecompositionPasses.cpp
- ExtractPolyCore in DecompositionEngine.cpp
- IsBooleanNullResidual support-size check
- ProbePoint::values, combo, args, var_indices, ghost_args array sizes
- the `prim.arity > kSupportSize` filters in SolveGhostResidual /
SolveFactoredGhostResidual now also reject `prim.arity > kMaxResidualSupport`
Hardens GhostBasis.cpp with named arity constants (kMulSubAndArity,
kMul3SubAnd3Arity), a static_assert that they fit in kMaxResidualSupport,
and assert(args.size() == arity) at every eval/build entry. A future
primitive that declares an arity > 6 either fails to compile (static_assert)
or fails loud at runtime if a caller ever passes a mis-sized span.
* style: clang-format GhostBasis static_assert block
0 commit comments