Remove performance-/precompilation-time harmful `@eval`
this PR fixes the issue of having @eval inside callable functions not resolved at compile time
closes #3555
cc @vchuravy
The next one I ran into is https://github.com/CliMA/Oceananigans.jl/blob/00f028bb37f13692e24921588aeb8a9150f6dd55/src/Advection/reconstruction_coefficients.jl#L215
So one alternative is to use named tuples instead of variables.
@inline function compute_reconstruction_coefficients(grid, FT, scheme; order)
method = scheme == :Centered ? 1 : scheme == :Upwind ? 2 : 3
rect_metrics = (:xᶠᵃᵃ, :xᶜᵃᵃ, :yᵃᶠᵃ, :yᵃᶜᵃ, :zᵃᵃᶠ, :zᵃᵃᶜ)
if grid isa Nothing
coeffs = (; (m => nothing for m in rect_metrics)...)
else
metrics = coordinates(grid)
dirsize = (:Nx, :Nx, :Ny, :Ny, :Nz, :Nz)
arch = architecture(grid)
Hx, Hy, Hz = halo_size(grid)
new_grid = with_halo((Hx+1, Hy+1, Hz+1), grid)
coeffs = (; (rect_metric => calc_reconstruction_coefficients(
FT, getfield(new_grid, metric), arch, getfield(new_grid, dir), Val(method); order = order)
for (dir, metric, rect_metric) in zip(dirsize, metrics, rect_metrics))...)
end
return tuple(coeffs...) # actually return named tuple to be order invariant
end
I think we need to look at all eval usage
I hit:
function minimum_spacing(dir, grid, ℓx, ℓy, ℓz)
spacing = eval(Symbol(dir, :spacing))
LX, LY, LZ = map(destantiate, (ℓx, ℓy, ℓz))
Δ = KernelFunctionOperation{LX, LY, LZ}(spacing, grid, ℓx, ℓy, ℓz)
return minimum(Δ)
end
next. Which probably should be getglobal?
@simone-silvestri are you going to shepherd this through to completion?
I couldn't find any other @eval inside functions so I think we are clear.
@vchuravy can you confirm?
this should be ready to merge