Skip to content

Fix @inferred type instability from JacReuseState Union type#3399

Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-jac-reuse-type-instability
Apr 12, 2026
Merged

Fix @inferred type instability from JacReuseState Union type#3399
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-jac-reuse-type-instability

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • _make_jac_reuse_state returned Union{Nothing, JacReuseState{T}} based on runtime max_jac_age, causing type instability in Rosenbrock cache's JRType parameter
  • This broke @inferred tests in OrdinaryDiffEqRosenbrock (dae_rosenbrock_ad_tests.jl) and OrdinaryDiffEqNonlinearSolve (mass_matrix_tests.jl)
  • Fix: always allocate JacReuseState — when max_jac_age ≤ 1 the age check in _rosenbrock_jac_reuse_decision triggers every step anyway, so behavior is unchanged

Introduced by #3075.

Test plan

  • OrdinaryDiffEqRosenbrock Pkg.test passes locally (was erroring on DAE Rosenbrock AD Tests)
  • OrdinaryDiffEqNonlinearSolve Pkg.test passes locally (was erroring on Mass Matrix Tests with Singular Mass Matrices)

🤖 Generated with Claude Code

_make_jac_reuse_state previously returned Union{Nothing, JacReuseState{T}}
because it conditionally allocated based on max_jac_age > 1. This caused
type instability in the Rosenbrock cache's JRType parameter, which
propagated to ODESolution return types and broke @inferred tests in:
- OrdinaryDiffEqRosenbrock: DAE Rosenbrock AD Tests
- OrdinaryDiffEqNonlinearSolve: Mass Matrix Tests with Singular Mass Matrices

Fix: always allocate JacReuseState regardless of max_jac_age. When
max_jac_age <= 1, the age check in _rosenbrock_jac_reuse_decision
triggers every step anyway, so behavior is unchanged.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas ChrisRackauckas merged commit f0de8b6 into SciML:master Apr 12, 2026
69 of 84 checks passed
ChrisRackauckas added a commit that referenced this pull request Apr 12, 2026
Bumps every subpackage that has accumulated source, compat, or
formatting changes on master since its last registered version
(i.e. since #3387). Each entry is registered after this PR merges via
@JuliaRegistrator.

- DelayDiffEq                    5.73.0  -> 5.74.0   (shift_past_discontinuity! alg_choice, composite DDE fix, #3394)
- DiffEqBase                     6.215.0 -> 6.216.0  (solve hook for shift-past d_discontinuities, #3394)
- DiffEqDevTools                 2.52.0  -> 2.53.0   (LICENSE.md add)
- OrdinaryDiffEqCore             3.30.0  -> 3.31.0   (shift_past_discontinuity! integrator path, alg_utils formatting)
- OrdinaryDiffEqDifferentiation  2.8.0   -> 2.9.0    (StaticArrays -> StaticArraysCore, #3405)
- OrdinaryDiffEqNonlinearSolve   1.27.0  -> 1.28.0   (StaticArrays -> StaticArraysCore + formatting)
- OrdinaryDiffEqRosenbrock       1.30.0  -> 1.31.0   (JacReuseState type-inference fix, #3399)
- OrdinaryDiffEqStabilizedRK     1.10.0  -> 1.11.0   (StaticArrays -> StaticArraysCore, #3405)
- OrdinaryDiffEqTaylorSeries     1.13.0  -> 1.14.0   (FunctionWrappers compat bound)

Not bumped (still awaiting their initial General registration at 1.0.0;
new READMEs, compat fixes, and formatting from #3388/#3390/#3400 will
be picked up by the first registration):
- OrdinaryDiffEqAMF
- OrdinaryDiffEqMultirate

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ChrisRackauckas added a commit that referenced this pull request Apr 12, 2026
…#3408)

Bumps every subpackage that has accumulated source, compat, or
formatting changes on master since its last registered version
(i.e. since #3387). Each entry is registered after this PR merges via
@JuliaRegistrator.

- DelayDiffEq                    5.73.0  -> 5.74.0   (shift_past_discontinuity! alg_choice, composite DDE fix, #3394)
- DiffEqBase                     6.215.0 -> 6.216.0  (solve hook for shift-past d_discontinuities, #3394)
- DiffEqDevTools                 2.52.0  -> 2.53.0   (LICENSE.md add)
- OrdinaryDiffEqCore             3.30.0  -> 3.31.0   (shift_past_discontinuity! integrator path, alg_utils formatting)
- OrdinaryDiffEqDifferentiation  2.8.0   -> 2.9.0    (StaticArrays -> StaticArraysCore, #3405)
- OrdinaryDiffEqNonlinearSolve   1.27.0  -> 1.28.0   (StaticArrays -> StaticArraysCore + formatting)
- OrdinaryDiffEqRosenbrock       1.30.0  -> 1.31.0   (JacReuseState type-inference fix, #3399)
- OrdinaryDiffEqStabilizedRK     1.10.0  -> 1.11.0   (StaticArrays -> StaticArraysCore, #3405)
- OrdinaryDiffEqTaylorSeries     1.13.0  -> 1.14.0   (FunctionWrappers compat bound)

Not bumped (still awaiting their initial General registration at 1.0.0;
new READMEs, compat fixes, and formatting from #3388/#3390/#3400 will
be picked up by the first registration):
- OrdinaryDiffEqAMF
- OrdinaryDiffEqMultirate

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
singhharsh1708 pushed a commit to singhharsh1708/OrdinaryDiffEq.jl that referenced this pull request Apr 16, 2026
)

_make_jac_reuse_state previously returned Union{Nothing, JacReuseState{T}}
because it conditionally allocated based on max_jac_age > 1. This caused
type instability in the Rosenbrock cache's JRType parameter, which
propagated to ODESolution return types and broke @inferred tests in:
- OrdinaryDiffEqRosenbrock: DAE Rosenbrock AD Tests
- OrdinaryDiffEqNonlinearSolve: Mass Matrix Tests with Singular Mass Matrices

Fix: always allocate JacReuseState regardless of max_jac_age. When
max_jac_age <= 1, the age check in _rosenbrock_jac_reuse_decision
triggers every step anyway, so behavior is unchanged.

Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
singhharsh1708 pushed a commit to singhharsh1708/OrdinaryDiffEq.jl that referenced this pull request Apr 16, 2026
…SciML#3408)

Bumps every subpackage that has accumulated source, compat, or
formatting changes on master since its last registered version
(i.e. since SciML#3387). Each entry is registered after this PR merges via
@JuliaRegistrator.

- DelayDiffEq                    5.73.0  -> 5.74.0   (shift_past_discontinuity! alg_choice, composite DDE fix, SciML#3394)
- DiffEqBase                     6.215.0 -> 6.216.0  (solve hook for shift-past d_discontinuities, SciML#3394)
- DiffEqDevTools                 2.52.0  -> 2.53.0   (LICENSE.md add)
- OrdinaryDiffEqCore             3.30.0  -> 3.31.0   (shift_past_discontinuity! integrator path, alg_utils formatting)
- OrdinaryDiffEqDifferentiation  2.8.0   -> 2.9.0    (StaticArrays -> StaticArraysCore, SciML#3405)
- OrdinaryDiffEqNonlinearSolve   1.27.0  -> 1.28.0   (StaticArrays -> StaticArraysCore + formatting)
- OrdinaryDiffEqRosenbrock       1.30.0  -> 1.31.0   (JacReuseState type-inference fix, SciML#3399)
- OrdinaryDiffEqStabilizedRK     1.10.0  -> 1.11.0   (StaticArrays -> StaticArraysCore, SciML#3405)
- OrdinaryDiffEqTaylorSeries     1.13.0  -> 1.14.0   (FunctionWrappers compat bound)

Not bumped (still awaiting their initial General registration at 1.0.0;
new READMEs, compat fixes, and formatting from SciML#3388/SciML#3390/SciML#3400 will
be picked up by the first registration):
- OrdinaryDiffEqAMF
- OrdinaryDiffEqMultirate

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants