Skip to content

Commit 8a577e9

Browse files
committed
prevent invalidation of mtkmodel macro code
1 parent 9c415dc commit 8a577e9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/systems/model_parsing.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,10 @@ function generate_var!(dict, a, b, varclass, mod;
511511
end
512512

513513
# Use the `t` defined in the `mod`. When it is unavailable, generate a new `t` with a warning.
514-
function get_t(mod, t)
514+
get_t(mod, t) = invokelatest(_get_t, mod, t)
515+
function _get_t(mod, t)
515516
try
516-
get_var(mod, t)
517+
_get_var(mod, t)
517518
catch e
518519
if e isa UndefVarError
519520
@warn("Could not find a predefined `t` in `$mod`; generating a new one within this model.\nConsider defining it or importing `t` (or `t_nounits`, `t_unitful` as `t`) from ModelingToolkit.")
@@ -588,7 +589,8 @@ function set_var_metadata(a, ms)
588589
a, metadata_with_exprs
589590
end
590591

591-
function get_var(mod::Module, b)
592+
get_var(mod, b) = invokelatest(_get_var, mod, b)
593+
function _get_var(mod::Module, b)
592594
if b isa Symbol
593595
isdefined(mod, b) && return getproperty(mod, b)
594596
isdefined(@__MODULE__, b) && return getproperty(@__MODULE__, b)
@@ -1355,7 +1357,8 @@ 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(condition, x::Expr, y::Union{Expr,Nothing} = nothing, branch::Symbol = :if)
1361+
@nospecialize condition x y
13591362
blocks::Vector{Union{Expr, Nothing}} = component_blk, equations_blk, parameter_blk, variable_blk = define_blocks(branch)
13601363

13611364
for arg in x

0 commit comments

Comments
 (0)