fix: remove evals from model parsing#2379
Conversation
src/systems/model_parsing.jl
Outdated
| function parse_icon!(icon, dict, body::Expr) | ||
| parse_icon!(icon, dict, eval(body)) | ||
| function parse_icon!(body::Union{Expr, Symbol}, dict, icon, mod) | ||
| parse_icon!(Core.eval(mod, body), dict, icon, mod) |
There was a problem hiding this comment.
| parse_icon!(Core.eval(mod, body), dict, icon, mod) | |
| parse_icon!(getfield(mod, :body), dict, icon, mod) |
? Example of what you're evaling
There was a problem hiding this comment.
This
@mtkmodel ModelWithExprIcon begin
@icon read(abspath(@__DIR__, "..", "icons", "ground.svg"), String)
# or @icon ground_logo
endfrom tests - here is an example.
In general,
anything with
@mtkmodel A begin
@icon begin
...
end
endThe body is an expression that should be evaluated within the defining module mod; in our test example that is ModelParsingPrecompile.
getfield can't be used as body is an expression in the module and not a function or a variable.
There was a problem hiding this comment.
Simplify that to just the string as a path to an SVG?
There was a problem hiding this comment.
I checked; if @icon abspath() is used instead of plane string, that would need this too.
Core.eval doesn't suffer with the same issue as Base.eval; is there any performance issue with it?
In that case we can force to assign abspath() value to a var; and rewrite this only for Symbol (and drop Expr)
parse_icon!(body::Symbol, dict, icon, mod) = parse_icon!(getfield(mod, body), dict, icon, mod)
There was a problem hiding this comment.
I've dropped the Core.eval and Expr dispatch from the @icon parser.
Resolved it here.
There was a problem hiding this comment.
Doc doesn't need to be updated as it uses strings to showcase all 3 ways (URI, inlined SVG, paths).
409a05d to
1a556f2
Compare
|
Rebase? |
|
Already done 👍 |
- Ensure that modules consisting MTKModels with component arrays and icons of `Expr` type and `unit` metadata can be precompiled.
b543c45 to
e60c214
Compare
Closes #2377
Exprtype had this issue.Checklist
contributor guidelines, in particular the ScioML Style Guide and
COLPRAC.