Here is a simplified example demonstrating my problem. I have a package named MyPkg2
:
module MyPkg2 # defined in MyPkg2.jl
using StaticArrays
const SBool{K} = SVector{K,Bool}
SBool(x::Number...) = SVector(Bool.(x)...)
# other useful functions are also defined but omitted
end # module
It imports StaticArrays
, and because it uses SVector
for Bool
often, it defines a type alias SBool{K} = SVector{K,Bool}
for convenience. Additionally, it defines SBool(x::Number...)
, which conveniently creates SBool{K}
when numbers convertible to Bool
are passed; for example, SBool(0,1,0)
generates [false, true, false]
typed SVector{3,Bool}
.
MyPkg2
has other useful functions as well. To use those functions, I import MyPkg2
in another package MyPkg3
. However, because MyPkg3
also uses SVector
for Bool
often, I define the type alias SBool
in MyPkg3
again. Here is how the package looks:
module MyPkg3 # defined in MyPkg3.jl
using MyPkg2
using StaticArrays
const SBool{K} = SVector{K,Bool}
SBool(x::Number...) = SVector(Bool.(x)...)
end # module
Because SBool
in MyPkg2
and SBool
in MyPkg3
live in different namespaces, I thought repeating its definition in both packages would be fine. However, when I use MyPkg3
, I get the following warning:
julia> using MyPkg3
[ Info: Precompiling MyPkg3 [73b3b46d-e1cd-46a7-992c-0e3a8322463c]
WARNING: Method definition (::Type{StaticArrays.SArray{Tuple{K}, Bool, 1, K} where K})(Number...) in module MyPkg2 at /Users/wsshin/Programming/MyPkg2/src/MyPkg2.jl:6 overwritten in module MyPkg3 at /Users/wsshin/Programming/MyPkg3/src/MyPkg3.jl:7.
** incremental compilation may be fatally broken for this module **
In my actual full-blown packages, the code performance has drastically reduced since the code was updated to produce this issue, probably because of the precompilation failure. Is there any way to eliminate this overwritten method warning?
Here is a more simplified example demonstrating the same issue without using StaticArrays
, from which the solution to the issue might be more easily figured out:
## MyPkg1.jl
module MyPkg1 # instead of StaticArrays
export MyType
struct MyType end # instead of SVector
end
## MyPkg2.jl
module MyPkg2
using MyPkg1 # instead of StaticArrays
const MyTypeAlias = MyType # instead of SBool
MyTypeAlias(x) = x
end
## MyPkg3.jl
module MyPkg3
using MyPkg2
using MyPkg1 # instead of StaticArrays
const MyTypeAlias = MyType # instead of SBool
MyTypeAlias(x) = x
end
And here is the corresponding overwritten method warning during precompilation:
julia> using MyPkg3
[ Info: Precompiling MyPkg3 [73b3b46d-e1cd-46a7-992c-0e3a8322463c]
WARNING: Method definition (::Type{MyPkg1.MyType})(Any) in module MyPkg2 at /Users/wsshin/Programming/MyPkg2/src/MyPkg2.jl:6 overwritten in module MyPkg3 at /Users/wsshin/Programming/MyPkg3/src/MyPkg3.jl:7.
** incremental compilation may be fatally broken for this module **