Skip to content

Don't extend implicit eval method#274

Merged
mloubout merged 2 commits intoslimgroup:masterfrom
Keno:kf/eval
Oct 28, 2024
Merged

Don't extend implicit eval method#274
mloubout merged 2 commits intoslimgroup:masterfrom
Keno:kf/eval

Conversation

@Keno
Copy link
Copy Markdown
Contributor

@Keno Keno commented Oct 17, 2024

The eval and include generic functions are implicitly provided by module for every new julia module. Currently it is possible to extend these (somewhat by accident), but this might change in JuliaLang/julia#55949.

To avoid that causing issues, this renames the eval method in this package to eval_lazy to avoid accidentally extending the builtin. If desireed, you could instead use a baremodule to avoid creating the implicit functions (see e.g. phelipe/Fuzzy.jl#21).

While I'm here, also strength-reduce the (builtin) eval method to getproperty instead as applicable. This is not required, but simply a best practice to avoid requiring the full semantics of eval (which include arbitrary code execution) when it is not needed.

I was unable to test this locally due to some python dependency errors, so please take a careful look to make sure I got this right.

The `eval` and `include` generic functions are implicitly provided
by `module` for every new julia module. Currently it is possible
to extend these (somewhat by accident), but this might change in
JuliaLang/julia#55949.

To avoid that causing issues, this renames the `eval` method in
this package to `eval_lazy` to avoid accidentally extending the
builtin. If desireed, you could instead use a baremodule to avoid
creating the implicit functions (see e.g. phelipe/Fuzzy.jl#21).

While I'm here, also strength-reduce the (builtin) `eval` method
to `getproperty` instead as applicable. This is not required, but
simply a best practice to avoid requiring the full semantics of
`eval` (which include arbitrary code execution) when it is not needed.

I was unable to test this locally due to some python dependency
errors, so please take a careful look to make sure I got this right.
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.

Project coverage is 78.31%. Comparing base (edc3ad9) to head (7ff1cb3).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/TimeModeling/Modeling/python_interface.jl 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #274      +/-   ##
==========================================
- Coverage   82.70%   78.31%   -4.40%     
==========================================
  Files          36       36              
  Lines        2735     2734       -1     
==========================================
- Hits         2262     2141     -121     
- Misses        473      593     +120     
Files with missing lines Coverage Δ
ext/JLD2JUDIExt.jl 80.00% <100.00%> (-3.34%) ⬇️
src/TimeModeling/LinearOperators/lazy.jl 81.33% <100.00%> (ø)
src/TimeModeling/Types/GeometryStructure.jl 82.16% <100.00%> (-0.64%) ⬇️
src/TimeModeling/Types/lazy_msv.jl 86.84% <100.00%> (ø)
src/TimeModeling/Modeling/python_interface.jl 79.00% <0.00%> (-19.99%) ⬇️

... and 6 files with indirect coverage changes

Comment thread ext/JLD2JUDIExt.jl
# Drop "typed" signature
reconstructT = Symbol(split(string(N), "{")[1])
return JUDI.tof32(eval(reconstructT)([getproperty(x, f) for f in FN]...))
return JUDI.tof32(getproperty(@__MODULE__, reconstructT)([getproperty(x, f) for f in FN]...))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return JUDI.tof32(getproperty(@__MODULE__, reconstructT)([getproperty(x, f) for f in FN]...))
return JUDI.tof32(getglobal(@__MODULE__, reconstructT)([getproperty(x, f) for f in FN]...))

(assuming you only support v1.9 or later)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's a 1.6 compat, which is why I used get property. But yes, getglobal is preferred for 1.9+

@mloubout mloubout merged commit 7ff1cb3 into slimgroup:master Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants