Skip to content

Commit 0c07d78

Browse files
Merge pull request #118 from SciML/as/setsym-oop-retain-tuple
fix: improve type-stability of `setsym_oop`
2 parents 158080c + 6cad2ab commit 0c07d78

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/state_indexing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ for (t1, t2) in [
464464
throw(NotVariableOrParameter("setsym_oop", s))
465465
end
466466
end
467+
if sym isa Tuple
468+
vars = Tuple(vars)
469+
pars = Tuple(pars)
470+
end
467471
indp = _root_indp(indp)
468472
return FullSetter(isempty(vars) ? nothing : OOPSetter(indp, identity.(vars), true),
469473
isempty(pars) ? nothing : OOPSetter(indp, identity.(pars), false),

src/value_provider_interface.jl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,27 +231,36 @@ function (fn::Fix1Multiple)(args...)
231231
fn.f(fn.arg, args...)
232232
end
233233

234-
struct OOPSetter{I, D}
234+
struct OOPSetter{S, I, D}
235235
indp::I
236236
idxs::D
237-
is_state::Bool
238237
end
239238

240-
function (os::OOPSetter)(valp, val)
241-
buffer = if os.is_state
242-
hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
243-
else
244-
hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
245-
end
239+
OOPSetter(indp, idxs, isstate) = OOPSetter{isstate, typeof(indp), typeof(idxs)}(indp, idxs)
240+
241+
function (os::OOPSetter{true})(valp, val)
242+
buffer = hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
243+
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
244+
end
245+
246+
function (os::OOPSetter{false})(valp, val)
247+
buffer = hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) :
248+
valp
246249
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
247250
end
248251

249-
function (os::OOPSetter)(valp, val::Union{Tuple, AbstractArray})
250-
buffer = if os.is_state
251-
hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
252+
function (os::OOPSetter{true})(valp, val::Union{Tuple, AbstractArray})
253+
buffer = hasmethod(state_values, Tuple{typeof(valp)}) ? state_values(valp) : valp
254+
if os.idxs isa Union{Tuple, AbstractArray}
255+
return remake_buffer(os.indp, buffer, os.idxs, val)
252256
else
253-
hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) : valp
257+
return remake_buffer(os.indp, buffer, (os.idxs,), (val,))
254258
end
259+
end
260+
261+
function (os::OOPSetter{false})(valp, val::Union{Tuple, AbstractArray})
262+
buffer = hasmethod(parameter_values, Tuple{typeof(valp)}) ? parameter_values(valp) :
263+
valp
255264
if os.idxs isa Union{Tuple, AbstractArray}
256265
return remake_buffer(os.indp, buffer, os.idxs, val)
257266
else

0 commit comments

Comments
 (0)