# Precompiling my own functions returns true/false

**URL:** <https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303>\
**Category:** General Usage\
**Tags:** question, precompile\
**Created:** [February 25, 2017, 7:24pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303 "2017-02-25T19:24:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [February 25, 2017, 7:24pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/1 "2017-02-25T19:24:13Z")

</div>

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:

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

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

```

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,  
BVPs

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 25, 2017, 9:41pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/2 "2017-02-25T21:41:01Z")

</div>

`jl_compile_hint` being `ccall`ed 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.

---

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [February 27, 2017, 6:54am UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/3 "2017-02-27T06:54:02Z")

</div>

@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.,

```julia
precompile(myfunc, (MyType{UInt16},))
 ... 
precompile(myfunc, (MyType{UInt128},))

```

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

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 27, 2017, 1:42pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/4 "2017-02-27T13:42:14Z")

</div>

> [@BVPs](#):
>
> I still haven’t thoroughly studied what the leaftype really is

[http://docs.julialang.org/en/latest/stdlib/base.html#Base.isleaftype](http://docs.julialang.org/en/latest/stdlib/base.html#Base.isleaftype)

---

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [February 27, 2017, 5:05pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/5 "2017-02-27T17:05:38Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 27, 2017, 5:26pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/6 "2017-02-27T17:26:30Z")

</div>

[http://docs.julialang.org/en/latest/manual/types.html#Parametric-Composite-Types-1](http://docs.julialang.org/en/latest/manual/types.html#Parametric-Composite-Types-1)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 27, 2017, 5:44pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/7 "2017-02-27T17:44:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BVPs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bvps/32/2190_2.png) [@BVPs](https://discourse.julialang.org/u/BVPs)\
**Post date:** [February 27, 2017, 6:06pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/8 "2017-02-27T18:06:16Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 27, 2017, 6:09pm UTC](https://discourse.julialang.org/t/precompiling-my-own-functions-returns-true-false/2303/9 "2017-02-27T18:09:09Z")

</div>

```julia
julia> typeof(Complex[1 + im, 1.0 + 1.0im, big(1.0) + big(1.0)*im])
Array{Complex,1}

```
