Skip to content

Commit 0621b14

Browse files
Fix type inference issue with LinearVerbosity keyword constructor
This commit fixes a type stability issue in the `LinearVerbosity` keyword argument constructor that was causing type inference failures in `LinearCache` initialization. Root Cause: The keyword argument constructor for `LinearVerbosity` was not type-stable because `values(final_args)...` produces different types depending on runtime kwargs, preventing the compiler from inferring a concrete type. Solution: 1. Added a fast path in the keyword constructor that returns early with a concrete type when all arguments are `nothing` (the default case) 2. Added `Base.@constprop :aggressive` to `__init` to help the compiler propagate the default `verbose=true` constant through the call chain This ensures that `LinearVerbosity()` with no arguments is type-stable, which is the common case when users rely on defaults. Changes: - src/verbosity.jl: Added fast path for default construction - src/common.jl: Added @constprop :aggressive to __init function Fixes the CI error: ``` return type LinearCache{..., LinearVerbosity{...}, ...} does not match inferred return type LinearCache{..., _A<:LinearVerbosity, ...} ``` All tests pass with this change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 547bf0c commit 0621b14

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm, arg
261261
__init(prob, alg, args...; kwargs...)
262262
end
263263

264-
function __init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
264+
Base.@constprop :aggressive function __init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
265265
args...;
266266
alias = LinearAliasSpecifier(),
267267
abstol = default_tol(real(eltype(prob.b))),
@@ -328,7 +328,7 @@ function __init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
328328
# @warn "Using `true` or `false` for `verbose` is being deprecated. Please use a `LinearVerbosity` type to specify verbosity settings.
329329
# For details see the verbosity section of the common solver options documentation page."
330330
init_cache_verb = verbose
331-
if verbose
331+
if verbose
332332
verbose_spec = LinearVerbosity()
333333
else
334334
verbose_spec = LinearVerbosity(SciMLLogging.None())

src/verbosity.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ end
9494

9595
function LinearVerbosity(;
9696
error_control = nothing, performance = nothing, numerical = nothing, kwargs...)
97+
# Fast path for default construction (type-stable)
98+
if error_control === nothing && performance === nothing &&
99+
numerical === nothing && isempty(kwargs)
100+
return LinearVerbosity(
101+
Silent(),
102+
Silent(),
103+
Silent(),
104+
Silent(),
105+
CustomLevel(1), # WARN_LEVEL in KrylovKit.jl
106+
Silent(),
107+
InfoLevel(),
108+
Silent(),
109+
ErrorLevel(),
110+
ErrorLevel(),
111+
Silent(),
112+
Silent(),
113+
Silent(),
114+
WarnLevel(),
115+
WarnLevel(),
116+
WarnLevel())
117+
end
118+
97119
# Validate group arguments
98120
if error_control !== nothing && !(error_control isa AbstractMessageLevel)
99121
throw(ArgumentError("error_control must be a SciMLLogging.AbstractMessageLevel, got $(typeof(error_control))"))

0 commit comments

Comments
 (0)