Don't extend implicit eval method#274
Merged
mloubout merged 2 commits intoslimgroup:masterfrom Oct 28, 2024
Merged
Conversation
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 ReportAttention: Patch coverage is
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
|
vtjnash
approved these changes
Oct 17, 2024
| # 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]...)) |
There was a problem hiding this comment.
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)
Contributor
Author
There was a problem hiding this comment.
I believe there's a 1.6 compat, which is why I used get property. But yes, getglobal is preferred for 1.9+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
evalandincludegeneric functions are implicitly provided bymodulefor 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
evalmethod in this package toeval_lazyto 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)
evalmethod togetpropertyinstead as applicable. This is not required, but simply a best practice to avoid requiring the full semantics ofeval(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.