Skip to content

Commit a76034d

Browse files
Fix BLAS logging type stability issues
Fixed three issues in blas_logging.jl: 1. Line 69: Bug comparing info <= size where 'size' was the Base.size function instead of a matrix dimension variable. Simplified to provide generic error message for ggev/gges failures. 2. Line 121: Runtime dispatch from string interpolation with Dict{Symbol,Any} values. Added _format_context_pair type barrier function with ::String return annotation to isolate dispatch and prevent propagation. These fixes improve type stability throughout the BLAS logging code, reducing from 3 runtime dispatches to 1 isolated dispatch in rarely-called logging code. The remaining dispatch in _format_context_pair is acceptable as it's: - Behind a type barrier (doesn't propagate to callers) - In logging code that only runs on BLAS errors (rare) - Inherent to working with Dict{Symbol,Any} context data 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d12057d commit a76034d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/blas_logging.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,9 @@ function interpret_positive_info(func::Symbol, info::Integer)
6666

6767
# General eigenvalue problem
6868
elseif occursin("ggev", func_str) || occursin("gges", func_str)
69-
if info <= size
70-
return (:convergence_failure,
71-
"QZ iteration failed",
72-
"The QZ iteration failed to compute all eigenvalues. Elements 1:$(info-1) converged.")
73-
else
74-
return (:unexpected_error,
75-
"Unexpected error in generalized eigenvalue problem",
76-
"Info value $info is unexpected for $func.")
77-
end
69+
return (:convergence_failure,
70+
"Generalized eigenvalue computation failed",
71+
"The algorithm failed to compute eigenvalues (info=$info). This may indicate QZ iteration failure or other numerical issues.")
7872

7973
# LDLT factorization
8074
elseif occursin("ldlt", func_str)
@@ -92,6 +86,10 @@ end
9286

9387

9488

89+
# Type barrier for string interpolation with Any-typed values
90+
# The ::String return type annotation prevents JET from seeing runtime dispatch propagate
91+
@noinline _format_context_pair(key::Symbol, value)::String = string(key, ": ", value)
92+
9593
"""
9694
blas_info_msg(func::Symbol, info::Integer, verbose::LinearVerbosity;
9795
extra_context::Dict{Symbol,Any} = Dict())
@@ -124,7 +122,8 @@ function blas_info_msg(func::Symbol, info::Integer;
124122
push!(parts, "Return code (info): $msg_info")
125123
if !isempty(extra_context)
126124
for (key, value) in extra_context
127-
push!(parts, "$key: $value")
125+
# Use type barrier to prevent runtime dispatch from propagating
126+
push!(parts, _format_context_pair(key, value))
128127
end
129128
end
130129
join(parts, "\n ")

test/nopre/jet.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ end
7777

7878
# Platform-specific factorizations (may not be available on all systems)
7979
if @isdefined(MKLLUFactorization)
80-
# MKLLUFactorization has runtime dispatch in blas_logging.jl (pre-existing bug)
80+
# MKLLUFactorization has one acceptable runtime dispatch in logging code
81+
# (_format_context_pair with Dict{Symbol,Any}) that's isolated behind a type barrier
8182
JET.@test_opt solve(prob, MKLLUFactorization()) broken=true
8283
end
8384

0 commit comments

Comments
 (0)