I’m very excited to see the new features in Julia 1.9. I’m interested in how it is decided which packages are required for loading extensions. Specifically, consider an example:
A package “MyPackage” has an optional dependency on CUDA.jl, but also uses Adapt.jl within the CUDA.jl dependency. This is added to the [extensions]
section of the Project.toml
:
[weakdeps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
[extensions]
CUDAExt = ["Adapt", "CUDA"]
with some code in CUDAExt.jl
module CUDAExt
using MyPackage, CUDA, Adapt
function Adapt.adapt_structure(::CUDA.CuArrayAdaptor, x::MyDefinedType)
# new rule for how to convert MyDefinedType to a CuArray
end
function do_a_cuda_thing()
x = MyDefinedType( [0.3f0, 0.5f0] )
cu_x = cu(x)
# do some computation
CUDA.unsafe_free!(cu_x)
end
Does the user now have to load both Adapt and CUDA before CUDAExt gets activated? Ideally, the user would not need to be exposed to the Adapt dependency; they could just run
using CUDA
using MyPackage
and CUDAExt would be activated. Would this work with just [weakdeps]
? What if the Project.toml
were written as
[weakdeps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
[extensions]
CUDAExt = "CUDA"
Would CUDAExt now still work? Or is this not allowed? Is there any documented behaviors for such “weak-subdependencies”?
(PS if this were a full release I would just try these things out, but since it is a pre-release the functionality might not be entirely as planned. Therefore I suppose the question is more about what should be allowed rather than what already is)