@@ -350,15 +350,14 @@ function process_ipo_return!(𝕃, ultimate_rt::Incidence, eqclassification, var
350350 new_eq_row = _zero_row ()
351351 for (v_offset, coeff) in zip (rowvals (ultimate_rt. row), nonzeros (ultimate_rt. row))
352352 v = v_offset - 1
353- if varclassification[v] != External && coeff == nonlinear
353+ if v != 0 && varclassification[v] != External && coeff == nonlinear
354354 get_nonlinrepl ()
355355 new_eq_row[v_offset] = nonlinear
356356 else
357357 new_row[v_offset] = coeff
358- while true
358+ while v != 0 && v != = nothing
359359 varclassification[v] = External
360360 v = invview (var_to_diff)[v]
361- v === nothing && break
362361 end
363362 end
364363 end
@@ -426,6 +425,17 @@ function add_internal_equations_to_structure!(refiner::StructuralRefiner, eqkind
426425 return true
427426end
428427
428+ function process_ipo_return! (𝕃, ultimate_rt:: Type , eqclassification, varclassification, var_to_diff, total_incidence, eq_callee_mapping)
429+ # If we don't have any internal variables (in which case we might have to to do a more aggressive rewrite), strengthen the incidence
430+ # by demoting to full incidence over the argument variables. Incidence is not allowed to propagate through global mutable state, so
431+ # the incidence of the return type is bounded by the incidence of the arguments in this case.
432+ if ! all (== (External), varclassification)
433+ return ultimate_rt, 0
434+ end
435+ # TODO : Keep track of whether we have any time dependence?
436+ return Incidence (ultimate_rt, IncidenceVector (MAX_EQS, Int[1 : length (varclassification)+ 1 ;], Union{Float64, NonLinear}[nonlinear for _ in 1 : length (varclassification)+ 1 ])), 0
437+ end
438+
429439function process_ipo_return! (𝕃, ultimate_rt:: Eq , eqclassification, args... )
430440 eqclassification[ultimate_rt. id] = External
431441 return ultimate_rt, 0
0 commit comments