Add a type stability sweep over the exported functions (supersedes #43) - #549
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #549 +/- ##
==========================================
+ Coverage 94.49% 94.67% +0.17%
==========================================
Files 14 14
Lines 3016 3023 +7
==========================================
+ Hits 2850 2862 +12
+ Misses 166 161 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
andreasnoack
force-pushed
the
test/type-stability-sweep
branch
2 times, most recently
from
August 19, 2026 18:45
f5c05e8 to
6328744
Compare
This was referenced Aug 19, 2026
devmotion
reviewed
Aug 20, 2026
Checks `@inferred(f(x)) isa T` over a grid of `Float16`, `Float32`, `Float64`, `ComplexF32`, `ComplexF64`, integer, `Rational` and `BigFloat` arguments. Asserting the type and not only that inference succeeds matters: of the methods that get it wrong, most are inferred perfectly and simply return a `Float64`. 280 assertions pass and 58 are marked broken, identically on 1.10 through 1.13. Most of the broken ones are in the Bessel family, where the fall-through in `besselj(nu::Real, x::AbstractFloat)` and its siblings promotes the order with `float(nu)` and drags the argument up with it. `besselj(2, Float16(1))` and `bessely(2, Float16(1))` are left out entirely because they recurse until the stack overflows (#547). The rest are `expint(ν, z)` and `gamma(a, x)` widening `Float16`/`Float32` arguments, `logabsbinomial` returning a `Float64` where its docstring documents a sign, `expint(::BigFloat)` inferred as `Union{Float64,BigFloat}`, and `airyai` missing the `f(x::Real) = f(float(x))` promotion that `besselj0` has. Since `broken` fails once a case starts passing, the list can only shrink deliberately.
andreasnoack
force-pushed
the
test/type-stability-sweep
branch
from
August 20, 2026 11:57
6328744 to
c26740d
Compare
devmotion
approved these changes
Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reworks the sweep proposed by @giordano in #43, which has been waiting for a rebase since 2017. The idea is his; the implementation is new, because the file it patched (
test/runtests.jl) has since been split into per-topic files.Based on #548 — 12 of the assertions here depend on it. Please merge that one first; this PR targets its branch and GitHub will retarget it to
masterafterwards.What it checks
A new
test/type_stability.jlassertingover a grid of
Float16,Float32,Float64,ComplexF32andComplexF64arguments, for the error functions, the gamma family (includingzeta(s, z),polygamma,beta/logbeta,gamma(a, x)), the incomplete gamma and beta functions, the Airy functions plain and scaled, the elliptic integrals, the sine and cosine integrals, the exponential integrals and the Bessel functions.Asserting the type rather than only that inference succeeds is the part that differs from #43, and it matters: of the 43 methods that get this wrong, only 14 fail a bare
@inferred. The other 29 are inferred perfectly and simply return aFloat64— for examplebesseli(2, Float16(1)) === 0.13574766976703834.The rule being encoded is that the result carries the precision that promoting the arguments gives: an
Integerorder does not by itself forceFloat64, and aFloat16orFloat32argument is never widened.Result
243 passing, 43 broken, 0 failing, identical on 1.10, 1.11, 1.12 and 1.13-rc3, so no
@test_brokenunexpectedly passes on any supported version.Every broken entry is in the Bessel family and they share one cause, documented at the top of the file: the fall-through in
promotes the order with
float(nu), which isFloat64for anIntegerorder, and drags the argument up with it. Hencebesselj(2, 1.0f0)isUnion{Float32,Float64}— the two branches disagree — whilebesselj(2.0f0, 1.0f0)is fine. The breakdown is 12Float32, 12Float16and 19ComplexF32entries.besselj(2, Float16(1))andbessely(2, Float16(1))are deliberately not called: the same fall-through recurses until the stack overflows, which would leave the test process in a corrupted state. That is #547, and fixing it should clear most of this list at the same time. See also #234.The intent is that the broken entries be turned into passing ones one at a time;
@test_brokenfails loudly once a case starts working, so nothing can be fixed silently without the list shrinking.Not covered yet:
Complex{Float16}arguments, andBigFloat.Prepared by Claude Code on behalf of @andreasnoack; the investigation and the text above are Claude's.