Skip to content

Commit 3a4f44a

Browse files
Merge pull request #3471 from hexaeder/hw/precompile_mtkmodel
Reduce TTF`@mtkmodel`
2 parents 5691fa3 + 3a137d6 commit 3a4f44a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/ModelingToolkit.jl

+28
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,34 @@ PrecompileTools.@compile_workload begin
224224
@variables x(ModelingToolkit.t_nounits)
225225
@named sys = ODESystem([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
226226
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
227+
@mtkmodel __testmod__ begin
228+
@constants begin
229+
c = 1.0
230+
end
231+
@structural_parameters begin
232+
structp = false
233+
end
234+
if structp
235+
@variables begin
236+
x(t) = 0.0, [description = "foo", guess = 1.0]
237+
end
238+
else
239+
@variables begin
240+
x(t) = 0.0, [description = "foo w/o structp", guess = 1.0]
241+
end
242+
end
243+
@parameters begin
244+
a = 1.0, [description = "bar"]
245+
if structp
246+
b = 2 * a, [description = "if"]
247+
else
248+
c
249+
end
250+
end
251+
@equations begin
252+
x ~ a + b
253+
end
254+
end
227255
end
228256

229257
export AbstractTimeDependentSystem,

src/systems/model_parsing.jl

+6-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ end
246246
# The comments indicate the syntax matched by a block; either when parsed directly
247247
# when it is called recursively for parsing a part of an expression.
248248
# These variable definitions are part of test suite in `test/model_parsing.jl`
249-
function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
249+
Base.@nospecializeinfer function parse_variable_def!(
250+
dict, mod, arg, varclass, kwargs, where_types;
250251
def = nothing, type::Type = Real, meta = Dict{DataType, Expr}())
252+
@nospecialize
251253
arg isa LineNumberNode && return
252254
MLStyle.@match arg begin
253255
# Parses: `a`
@@ -1355,7 +1357,9 @@ push_something!(v, x...) = push_something!.(Ref(v), x)
13551357

13561358
define_blocks(branch) = [Expr(branch), Expr(branch), Expr(branch), Expr(branch)]
13571359

1358-
function parse_top_level_branch(condition, x, y = nothing, branch = :if)
1360+
Base.@nospecializeinfer function parse_top_level_branch(
1361+
condition, x, y = nothing, branch::Symbol = :if)
1362+
@nospecialize
13591363
blocks::Vector{Union{Expr, Nothing}} = component_blk, equations_blk, parameter_blk, variable_blk = define_blocks(branch)
13601364

13611365
for arg in x

0 commit comments

Comments
 (0)