Skip to content

Commit

Permalink
Don't extend implicit eval method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Oct 17, 2024
1 parent edc3ad9 commit e238776
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ext/JLD2JUDIExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ JUDI.Geometry(x::JLD2.ReconstructedMutable{N, FN, NT}) where {N, FN, NT} = Geome
function JUDI.tof32(x::JLD2.ReconstructedStatic{N, FN, NT}) where {N, FN, NT}
# 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]...))
end

end
2 changes: 1 addition & 1 deletion src/TimeModeling/LinearOperators/lazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,4 @@ _as_src(::judiNoopOperator, ::AbstractModel, q::judiMultiSourceVector) = q

############################################################################################################################
###### Evaluate lazy operation
eval(rhs::judiRHS) = rhs.d
eval_lazy(rhs::judiRHS) = rhs.d
4 changes: 2 additions & 2 deletions src/TimeModeling/Types/GeometryStructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function getproperty(G::Geometry, s::Symbol)
end
# Legacy dt/nt/t
if s in [:dt, :t, :nt, :t0]
return eval(Symbol("get_$(s)"))(G)
return getproperty(@__MODULE__, Symbol("get_$(s)"))(G)
end

return getfield(G, s)
end

Expand Down
8 changes: 4 additions & 4 deletions src/TimeModeling/Types/lazy_msv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ end
getindex(la::LazyAdd{D}, i::RangeOrVec) where D = LazyAdd{D}(length(i), la.A[i], la.B[i], la.sign)


function eval(ls::LazyAdd{D}) where D
aloc = eval(ls.A)
bloc = eval(ls.B)
function eval_lazy(ls::LazyAdd{D}) where D
aloc = eval_lazy(ls.A)
bloc = eval_lazy(ls.B)
ga = aloc.geometry
gb = bloc.geometry
@assert (ga.nt == gb.nt && ga.dt == gb.dt && ga.t == gb.t)
Expand All @@ -49,7 +49,7 @@ function eval(ls::LazyAdd{D}) where D
end

function make_src(ls::LazyAdd{D}) where D
q = eval(ls)
q = eval_lazy(ls)
return q.geometry[1], q.data[1]
end

Expand Down

0 comments on commit e238776

Please sign in to comment.