Skip to content

Commit 7065114

Browse files
Add trace type assertion to fix inference on Julia 1.10
The previous type assertions fixed T, N, uType, R but the compiler on 1.10 still couldn't resolve the trace type across branches. Assert _traceType = typeof(cache.caches[1].trace) on all trace accesses. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8b2d31 commit 7065114

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/NonlinearSolveBase/src/solve.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ end
353353
calls = [
354354
quote
355355
1 cache.current $(N) || error("Current choices shouldn't get here!")
356-
# Compute concrete types for u and resid from the cache to help inference
357-
# on Julia 1.10 where the compiler can't track them across branches.
356+
# Compute concrete types from the cache to help inference on Julia 1.10
357+
# where the compiler can't track them across branches.
358358
_uType = typeof(cache.u0)
359359
_fuType = typeof(NonlinearSolveBase.get_fu(cache.caches[1]))
360+
_traceType = typeof(cache.caches[1].trace)
360361
end,
361362
]
362363

@@ -373,7 +374,7 @@ end
373374
cache.prob, cache.alg, u,
374375
$(Utils.evaluate_f)(cache.prob, u)::_fuType;
375376
retcode = cache.retcode, stats = cache.stats,
376-
trace = cache.caches[1].trace
377+
trace = (cache.caches[1].trace::_traceType)
377378
)
378379
end
379380
end
@@ -399,7 +400,7 @@ end
399400
return build_solution_less_specialize(
400401
cache.prob, cache.alg, $(u_result_syms[i]), fu;
401402
retcode = $(sol_syms[i]).retcode, stats,
402-
original = $(sol_syms[i]), trace = $(sol_syms[i]).trace
403+
original = $(sol_syms[i]), trace = ($(sol_syms[i]).trace::_traceType)
403404
)
404405
elseif cache.alias_u0
405406
# For safety we need to maintain a copy of the solution
@@ -442,9 +443,10 @@ end
442443
copyto!(cache.u0, u)
443444
u = cache.u0
444445
end
446+
_trace = cache.caches[idx].trace::_traceType
445447
return build_solution_less_specialize(
446448
cache.prob, cache.alg, u::_uType, fus[idx]::_fuType;
447-
retcode, cache.stats, cache.caches[idx].trace
449+
retcode, cache.stats, trace = _trace
448450
)
449451
end
450452
)

0 commit comments

Comments
 (0)