Requires.jl and precompilation

I have a question, about Requires.jl and precompilation. Say I have the following package:

module AxisArrayConversion
...
__init__() = @require AxisArrays=... include("axis_arrays.jl")
end

Then things defined in the “axis_arrays.jl” file will not get precompiled. Correct so far or is it more complicated?

Now suppose I have in addition another package:

module OtherPackage
using AxisArrays
using AxisArrayConversion

function f(...)
    # use stuff defined in axis_arrays.jl file
end

Will OtherPackage.f get precompiled?

1 Like

The term precompile is a little confusing, because it means different things. The standard Precompiling SomePkg... message by default means its caching the method definitions etc in your package. Optionally you can also save the type-inferred code, but that requires that you either (1) use the methods while the package is being built, or (2) explicitly call precompile while the package is being built.

To answer your direct question: the @require example, your methods will not even be cached, let alone in type-inferred form. In the second case, the method definition for f will be automatically cached. To cache the type-inferred form you’ll have to emit precompile directives.

3 Likes

In case a type definition (e.g. struct Alpha end) takes place in axis_arrays.jl, is there a way to access and use it in OtherPackage ?

@tim.holy how does the weak dependency system fit into this? Does this lead to caching the method definitions, unlike Requires?

That’s right. You can also optionally precompile type-inferred and native code.