262262
263263const VectorViewType = SubArray{Float64, 1 , Vector{Float64}, Tuple{UnitRange{Int}}, true }
264264
265+ function cache_dae_ci! (old_ci, src, debuginfo, owner)
266+ daef_ci = CC. engine_reserve (old_ci. def, owner)
267+ ccall (:jl_fill_codeinst , Cvoid, (Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
268+ daef_ci, Tuple{}, Union{}, nothing , Int32 (0 ),
269+ UInt (1 )#= ci.min_world=# , old_ci. max_world,
270+ old_ci. ipo_purity_bits, nothing , nothing , CC. empty_edges)
271+ ccall (:jl_update_codeinst , Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
272+ daef_ci, src, Int32 (0 ), UInt (1 )#= ci.min_world=# , old_ci. max_world, old_ci. ipo_purity_bits,
273+ nothing , 0x0 , debuginfo, CC. empty_edges)
274+ ccall (:jl_mi_cache_insert , Cvoid, (Any, Any), old_ci. def, daef_ci)
275+ return daef_ci
276+ end
277+
265278function dae_finish_ipo! (
266279 interp,
267280 ci:: CodeInstance ,
@@ -288,6 +301,7 @@ function dae_finish_ipo!(
288301 old_daef_mi = nothing
289302 assigned_slots = falses (length (result. total_incidence))
290303
304+ cis = Vector {CodeInstance} ()
291305 for (ir_ordinal, ir) in enumerate (torn. ir_seq)
292306 ir = torn. ir_seq[ir_ordinal]
293307
@@ -338,11 +352,11 @@ function dae_finish_ipo!(
338352 spec_data = stmt. args[1 ]
339353 callee_key = stmt. args[1 ][2 ]
340354 callee_ordinal = stmt. args[1 ][end ]:: Int
341- callee_daef_mi = dae_finish_ipo! (interp, callee_ci, callee_key, callee_ordinal)
355+ callee_daef_cis = dae_finish_ipo! (interp, callee_ci, callee_key, callee_ordinal)
342356 # Allocate a continuous block of variables for all callee alg and diff states
343357
344358 empty! (stmt. args)
345- push! (stmt. args, callee_daef_mi )
359+ push! (stmt. args, callee_daef_cis[ 1 ] )
346360 push! (stmt. args, closure_env)
347361 push! (stmt. args, in_vars)
348362
@@ -402,33 +416,17 @@ function dae_finish_ipo!(
402416 widen_extra_info! (ir)
403417 src = ir_to_src (ir)
404418
405- daef_mi = MethodSpecialization {RHSSpec} (ci. def, Tuple{}, Tuple{Tuple, Tuple, (VectorViewType for _ in arg_range). .. , Float64})
406- daef_mi. data = RHSSpec (key, ir_ordinal)
419+ abi = Tuple{Tuple, Tuple, (VectorViewType for _ in arg_range). .. , Float64}
420+ owner = Core. ABIOverwrite (abi, RHSSpec (key, ir_ordinal))
421+ daef_ci = cache_dae_ci! (ci, src, src. debuginfo, owner)
407422
408- daef_ci = CodeInstance (daef_mi, Tuple, Union{}, nothing ,
409- src, Int32 (0 ), UInt (1 )#= ci.min_world=# , ci. max_world, ci. ipo_purity_bits, ci. purity_bits,
410- nothing , 0x0 , src. debuginfo)
411-
412- @atomic :release daef_mi. cache = daef_ci
413423 global nrhscompiles += 1
414-
415- if old_daef_mi != = nothing
416- @atomic :release old_daef_mi. next = daef_mi
417- end
418- old_daef_mi = daef_mi
419-
420- if rhs_ms === nothing
421- rhs_ms = daef_mi
422- end
424+ push! (cis, daef_ci)
423425 end
424426
425- result. dae_finish_cache[key] = rhs_ms
427+ result. dae_finish_cache[key] = cis
426428
427- ms = rhs_ms
428- while ! isa (ms. data, RHSSpec) || ms. data. ordinal != ordinal
429- ms = ms. next
430- end
431- return ms
429+ return cis
432430end
433431
434432function ir_to_src (ir:: IRCode )
@@ -499,6 +497,7 @@ function dae_factory_gen(world::UInt, source::LineNumberNode, _, @nospecialize(f
499497 src. ssavaluetypes = length (src. code)
500498 src. min_world = @atomic codeinst. min_world
501499 src. max_world = @atomic codeinst. max_world
500+ src. edges = codeinst. edges
502501
503502 return src
504503end
@@ -527,7 +526,7 @@ function dae_factory_gen(interp, ci::CodeInstance, key)
527526
528527 argt = Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, SciMLBase. NullParameters, Float64}
529528
530- daef_ci = dae_finish_ipo! (interp, ci, key, 1 )
529+ daef_cis = dae_finish_ipo! (interp, ci, key, 1 )
531530
532531 # Create a small opaque closure to adapt from SciML ABI to our own internal
533532 # ABI
@@ -582,7 +581,7 @@ function dae_factory_gen(interp, ci::CodeInstance, key)
582581 oc_sicm = insert_node_here! (oc_compact,
583582 NewInstruction (Expr (:call , getfield, Argument (1 ), 1 ), Tuple, line))
584583 insert_node_here! (oc_compact,
585- NewInstruction (Expr (:invoke , daef_ci , oc_sicm, (), out_du_mm, out_eq, in_u_mm, in_u_unassgn, in_du_unassgn, in_alg, Argument (6 )), Nothing, line))
584+ NewInstruction (Expr (:invoke , daef_cis[ 1 ] , oc_sicm, (), out_du_mm, out_eq, in_u_mm, in_u_unassgn, in_du_unassgn, in_alg, Argument (6 )), Nothing, line))
586585
587586 # Manually apply mass matrix
588587 bc = insert_node_here! (oc_compact,
0 commit comments