-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove eval
s from model parsing
#2379
fix: remove eval
s 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
@mtkmodel ModelWithExprIcon begin
@icon read(abspath(@__DIR__, "..", "icons", "ground.svg"), String)
# or @icon ground_logo
end
from tests - here is an example.
In general,
anything with
@mtkmodel A begin
@icon begin
...
end
end
The 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify that to just the string as a path to an SVG?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've dropped the Core.eval and Expr dispatch from the @icon
parser.
Resolved it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Expr
type had this issue.Checklist
contributor guidelines, in particular the ScioML Style Guide and
COLPRAC.