Precompiling my own functions returns true/false



Hello. I wrote a set of functions myself (with julia v0.5.0), and wanted to precompile them using precompile, e.g., precompile(myfunc, (Matrix{Float64}, Vector{Int64})), etc. Now, precompile returns true on some of my functions while it returns false on the other functions of mine. All these functions do work properly, but I do not understand why precompile behave differently. First of all, does getting true and false from precompile indicate the success and failure of precompiling it, respectively?
If I dig a bit more, the precompile function is defined in base/essentials.jl as:

function precompile(f::ANY, args::Tuple)
    ccall(:jl_compile_hint, Cint, (Any,), Tuple{Core.Typeof(f), args...}) != 0

function precompile(argt::Type)
    ccall(:jl_compile_hint, Cint, (Any,), argt) != 0

But it’s not clear to me how to check more, e.g., how jl_compile_hint works, etc.
Since the julia documentation does not describe this precompile function in detail, I would appreciate your help!
Best regards,


jl_compile_hint being ccalled is defined in, well, C code…

If it returns false it means nothing is compiled since there isn’t a method matching or the type you are asking isn’t a leaftype.


@yuyichao, Thank you very much for your reply.
I still haven’t thoroughly studied what the leaftype really is, but those functions that precompile returned false are all involved with parametric types. When I ran precompile on those functions with providing specific parameter values, then they returned true. So, what I have to do is to run precompile by specifying all possible combinations of those parameter values, e.g.,

precompile(myfunc, (MyType{UInt16},))
precompile(myfunc, (MyType{UInt128},))

Previously, I did precompile(myfunc, (MyType,)) that returned false.



@yuyichao: thanks a lot for the document page. However, I don’t understand why isleaftype(Vector{Complex}) returns true. Of course, I understand why isleaftype(Vector{Complex{Float32}}) returns true. Could you explain this behavior to me? Thanks!



Woho, that was the point of (me) writing that doctest, to get people to go a bit “hmmm”.


@yuyichao; @kristoffer.carlsson: thanks for your reply. But I still don’t understand the leaftypes. Why Vector{Complex} is of leaftype while Complex itself is not?

julia> typeof(Complex[1 + im, 1.0 + 1.0im, big(1.0) + big(1.0)*im])