Skip to content

Consider a different way to error on extension not loaded #68

Open
@avik-pal

Description

@avik-pal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions