Skip to content

Commit 1483011

Browse files
refactor: improve type-stability of System ctor
1 parent 0e13977 commit 1483011

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/ModelingToolkitBase/src/systems/system.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ function System(eqs::Vector{Equation}, iv, dvs, ps, brownians = SymbolicT[];
381381
continuous_events = SymbolicContinuousCallback[], discrete_events = SymbolicDiscreteCallback[],
382382
connector_type = nothing, assertions = Dict{SymbolicT, String}(),
383383
metadata = MetadataT(), gui_metadata = nothing,
384-
is_dde = nothing, tstops = [], inputs = OrderedSet{SymbolicT}(),
384+
is_dde = nothing, @nospecialize(tstops = []), inputs = OrderedSet{SymbolicT}(),
385385
outputs = OrderedSet{SymbolicT}(), tearing_state = nothing,
386386
ignored_connections = nothing, parent = nothing,
387387
description = "", name = nothing, discover_from_metadata = true,
388388
initializesystem = nothing, is_initializesystem = false, is_discrete = false,
389-
preface = [], checks = true, __legacy_defaults__ = nothing)
389+
@nospecialize(preface = nothing), checks = true, __legacy_defaults__ = nothing)
390390
name === nothing && throw(NoNameError())
391391

392392
if __legacy_defaults__ !== nothing
@@ -683,19 +683,20 @@ Create a `System` with a single equation `eq`.
683683
System(eq::Equation, args...; kwargs...) = System([eq], args...; kwargs...)
684684

685685
function gather_array_params(ps)
686-
new_ps = OrderedSet()
686+
new_ps = OrderedSet{SymbolicT}()
687687
for p in ps
688-
if iscall(p) && operation(p) === getindex
689-
par = arguments(p)[begin]
690-
if symbolic_has_known_size(par) && all(par[i] in ps for i in eachindex(par))
691-
push!(new_ps, par)
688+
arr, isarr = split_indexed_var(p)
689+
sh = SU.shape(arr)
690+
if isarr
691+
if !(sh isa SU.Unknown) && all(in(ps) Base.Fix1(getindex, arr), SU.stable_eachindex(arr))
692+
push!(new_ps, arr)
692693
else
693694
push!(new_ps, p)
694695
end
695696
else
696-
if symbolic_type(p) == ArraySymbolic() && symbolic_has_known_size(p)
697-
for i in eachindex(p)
698-
delete!(new_ps, p[i])
697+
if sh isa SU.ShapeVecT && !isempty(sh)
698+
for i in SU.stable_eachindex(arr)
699+
delete!(new_ps, arr[i])
699700
end
700701
end
701702
push!(new_ps, p)

0 commit comments

Comments
 (0)