Skip to content

Commit 4225352

Browse files
Merge pull request SciML#66 from ChrisRackauckas-Claude/static-improvements-20260107-173456
Improve static analysis: fix BigInt compatibility, enhance JET tests
2 parents 01e76fb + 1266cd0 commit 4225352

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/MATLABDiffEq.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ using MATLAB, ModelingToolkit
66
using PrecompileTools
77

88
# MATLAB only supports Float64 arrays. Check if a type is MATLAB-compatible.
9+
# Note: We specifically accept standard Julia integer types that MATLAB can convert,
10+
# but NOT BigInt since MATLAB doesn't support arbitrary precision integers.
911
_is_matlab_compatible_eltype(::Type{Float64}) = true
10-
_is_matlab_compatible_eltype(::Type{<:Integer}) = true # MATLAB can convert integers
12+
_is_matlab_compatible_eltype(::Type{<:Union{Int8, Int16, Int32, Int64, Int128}}) = true
13+
_is_matlab_compatible_eltype(::Type{<:Union{UInt8, UInt16, UInt32, UInt64, UInt128}}) = true
1114
_is_matlab_compatible_eltype(::Type{<:Complex{Float64}}) = true
1215
_is_matlab_compatible_eltype(::Type) = false
1316

14-
function _check_matlab_compatible(u0, tspan)
17+
function _check_matlab_compatible(u0, tspan)::Nothing
1518
T = eltype(u0)
1619
if !_is_matlab_compatible_eltype(T)
1720
throw(
@@ -207,8 +210,10 @@ end
207210
# Precompile type compatibility checks
208211
_ = _is_matlab_compatible_eltype(Float64)
209212
_ = _is_matlab_compatible_eltype(Int64)
213+
_ = _is_matlab_compatible_eltype(UInt64)
210214
_ = _is_matlab_compatible_eltype(Complex{Float64})
211215
_ = _is_matlab_compatible_eltype(BigFloat)
216+
_ = _is_matlab_compatible_eltype(BigInt)
212217
_ = _check_matlab_compatible([1.0, 2.0], (0.0, 1.0))
213218
_ = _check_matlab_compatible(1.0, (0.0, 1.0))
214219
end

test/jet_tests.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,54 @@ end
106106
@test isconcretetype(ode15s_test)
107107
@test isconcretetype(ode15i_test)
108108
end
109+
110+
@testset "Type compatibility functions" begin
111+
# Test the type compatibility check functions
112+
# These mirror the actual module implementations
113+
# Note: BigInt is NOT accepted because MATLAB doesn't support arbitrary precision
114+
115+
_is_matlab_compatible_eltype_test(::Type{Float64})::Bool = true
116+
_is_matlab_compatible_eltype_test(::Type{<:Union{Int8, Int16, Int32, Int64, Int128}})::Bool = true
117+
_is_matlab_compatible_eltype_test(::Type{<:Union{UInt8, UInt16, UInt32, UInt64, UInt128}})::Bool = true
118+
_is_matlab_compatible_eltype_test(::Type{<:Complex{Float64}})::Bool = true
119+
_is_matlab_compatible_eltype_test(::Type)::Bool = false
120+
121+
# Test return types are Bool
122+
@test _is_matlab_compatible_eltype_test(Float64) === true
123+
@test _is_matlab_compatible_eltype_test(Int64) === true
124+
@test _is_matlab_compatible_eltype_test(UInt64) === true
125+
@test _is_matlab_compatible_eltype_test(Complex{Float64}) === true
126+
@test _is_matlab_compatible_eltype_test(BigFloat) === false
127+
@test _is_matlab_compatible_eltype_test(BigInt) === false
128+
@test _is_matlab_compatible_eltype_test(Float32) === false
129+
130+
# JET @test_opt analysis for type stability
131+
if HAS_JET
132+
@testset "JET @test_opt type stability" begin
133+
# Test type stability of _is_matlab_compatible_eltype
134+
@test_opt _is_matlab_compatible_eltype_test(Float64)
135+
@test_opt _is_matlab_compatible_eltype_test(Int64)
136+
@test_opt _is_matlab_compatible_eltype_test(BigFloat)
137+
end
138+
end
139+
end
140+
141+
@testset "Return type inference" begin
142+
# Test that return types can be inferred correctly
143+
function buildDEStats_test2(solverstats::Dict{String, <:Any})::DiffEqBase.Stats
144+
destats = DiffEqBase.Stats(0)
145+
destats.nf = Int(get(solverstats, "nfevals", 0))
146+
destats.nreject = Int(get(solverstats, "nfailed", 0))
147+
destats.naccept = Int(get(solverstats, "nsteps", 0))
148+
destats.nsolve = Int(get(solverstats, "nsolves", 0))
149+
destats.njacs = Int(get(solverstats, "npds", 0))
150+
destats.nw = Int(get(solverstats, "ndecomps", 0))
151+
destats
152+
end
153+
154+
# Verify return type is inferred as concrete
155+
return_types = Base.return_types(buildDEStats_test2, (Dict{String, Any},))
156+
@test length(return_types) == 1
157+
@test return_types[1] == DiffEqBase.Stats
158+
end
109159
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ using DiffEqBase, MATLABDiffEq, ParameterizedFunctions, Test
33
# Interface tests - these test type validation without needing MATLAB runtime
44
include("interface_tests.jl")
55

6+
# JET static analysis tests - these also run without MATLAB
7+
include("jet_tests.jl")
8+
69
# The following tests require MATLAB runtime to be available
710
# They test the actual ODE solving functionality
811

0 commit comments

Comments
 (0)