Consider a different way to error on extension not loaded
avik-pal opened this issue · 1 comments
avik-pal commented
Currently the functions are written as:
function foo(args...; kwargs...)
error("ExtX.jl not loaded")
end
# In ExtX.jl
function foo(a::Int, b::Char)
# do the correct thing
end
Now this works, but let's say I did using X, DynamicExpressions; foo(1, 2)
I will get an error "ExtX.jl not loaded"
which is somewhat confusing because X.jl
is already loaded. For quite a few of my packages the way I handle this is:
@inline _is_extension_loaded(::Val) = false
function _foo_internal end
function foo(...)
_is_extension_loaded(Val(:X)) && return _foo_internal(...)
error("....")
end
# In ExtX.jl
@inline _is_extension_loaded(::Val{:X}) = true
This does cause a minor increase in invalidations, but julia compiles away the branch so there is no runtime cost
MilesCranmer commented
Good point, thanks!