# How is Julia written in Julia?

**URL:** https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918
**Category:** Internals & Design
**Tags:** question
**Created:** [November 28, 2020, 9:31pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918 "2020-11-28T21:31:51Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![logankilpatrick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/logankilpatrick/32/38123_2.png) [@logankilpatrick](https://discourse.julialang.org/u/logankilpatrick)
#### Post date: [November 28, 2020, 9:31pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/1 "2020-11-28T21:31:51Z")

</div>

Hey all, I am broadly trying to understand how Julia as a language is written in Julia itself. Is the compiler what is enabling this or is there a different reason?

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [November 28, 2020, 9:55pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/2 "2020-11-28T21:55:40Z")

</div>

Julia is not written in Julia.  
The Julia standard libraries, including Base, are implemented in Julia.

Julia is implemented mostly in C,  
with a little bit of C++ for LLVM code-gen,  
and FemtoLisp for the lowering and the parser.  
And a little bit of Julia for the optimizer.

I assume the optimizer is compiled by Julia without optimization running. Or maybe it is compiled twice.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 28, 2020, 10:11pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/3 "2020-11-28T22:11:17Z")

</div>

Note that it is _possible_ for a language to be implemented entirely in itself: this called [self-hosting (Wikipedia)](https://en.wikipedia.org/wiki/Self-hosting_(compilers)).

However, Julia is not self-hosting and there is not much interest in working on this. See e.g. [this discussion](https://discourse.julialang.org/t/julia-written-in-julia/25781), [this discussion](https://groups.google.com/g/julia-dev/c/dOAwcwm5iEA/m/dJFqob5HfNYJ?pli=1), and [this article](https://tratt.net/laurie/blog/entries/the_bootstrapped_compiler_and_the_damage_done.html) on why an emphasis on self-hosting can be detrimental to language design.

---

<div class="post-metadata">

### Author: ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)
#### Post date: [November 29, 2020, 12:02am UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/4 "2020-11-29T00:02:27Z")

</div>

@stevengj

(Disclaimer: this is probably a very stupid question, but I have no background on compilers and things like this)

If Julia can create executables, then, theoretically, Julia can be written entirely in Julia, right? Since you said that Julia devs are not interested in writing Julia entirely in Julia, does this means that probably Julia will not be able to generate executables without relying on C/C++ (like we do today)?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 29, 2020, 1:33am UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/5 "2020-11-29T01:33:05Z")

</div>

> [@Ronis\_BR](#):
>
> If Julia can create executables, then, theoretically, Julia can be written entirely in Julia, right?

Yes. (Any programming language can implement any programming language, in theory. You could write a Cobol interpreter or compiler in PowerShell if you wanted to, in theory.)

> [@Ronis\_BR](#):
>
> Since you said that Julia devs are not interested in writing Julia entirely in Julia, does this means that probably Julia will not be able to generate executables without relying on C/C++ (like we do today)

Yes, Julia will need C and C++ compilers for the foreseeable future. (This poses no practical difficulties.)

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [November 29, 2020, 8:10am UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/6 "2020-11-29T08:10:04Z")

</div>

Whilst there is a big bit of C, C++, and Scheme, a lot of Julia is written in Julia itself; and it’s not just the standard libs. My limited understanding is that “bootstrap” starts with the part of Julia the C/C++/Scheme provides, which is very limited, then bit by bit the more complicated parts of Julia are implemented. During this bootstrap the `Core` part of Julia is made, see: [https://github.com/JuliaLang/julia/blob/master/base/boot.jl](https://github.com/JuliaLang/julia/blob/master/base/boot.jl). Once Core is in place the bootstrap continues to build up `Base` here [https://github.com/JuliaLang/julia/blob/master/base/Base.jl](https://github.com/JuliaLang/julia/blob/master/base/Base.jl). That bootstrap process is, I think, why there is the odd duplication of functionality between `Core` and `Base`.

As you can probably tell, I’m a bit out of my depth here. So maybe someone can fill in some details and/or correct me.

Edit: one way to experience this bootstrap process is when contributing something to `Base` which is needed fairly early during bootstrap. Then you have to program the feature using only what is already available during that time in bootstrap, which can be tricky to do (if you’re not used to it).

---

<div class="post-metadata">

### Author: ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)
#### Post date: [November 29, 2020, 7:40pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/7 "2020-11-29T19:40:49Z")

</div>

Something I find really cool about Julia is the ability to see how things are implemented. When someone says “well, Julia’s just calling C libraries for all the math and stuff, right?”, I can do `@edit sin(1.0)` and show them that, no, that math function is written in Julia, here’s the polynomial used for the approximation and here’s what it does for different argument types. Or I can load the SpecialFunctions package and go down the rabbit hole for a Bessel function, and after a few clicks see that it isn’t written in Julia, but is in Fortran.

Oh, and the source buttons you find in the manual when looking at the doc for a function that take you straight to the source for that function. So cool!

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 29, 2020, 7:55pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/8 "2020-11-29T19:55:59Z")

</div>

though Julia is not a self-host language, in practice, especially in scientific research, a pitch I often give is: all the parts you would ever care about is in Julia and you can read, understand, and even tweak at will. I’m referring to the fact that `base` and `stdlib` are in Julia and packages are more often pure Julia (at least for the part that does heavy lifting).

Unlike, for example, Numpy, where one hits C code super quickly once start digging (even function as simple as `mean` is written in C).

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [November 29, 2020, 9:57pm UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/9 "2020-11-29T21:57:20Z")

</div>

I’ve definitely solved a few problems unrelated to Julia by looking at a method in stdlib to see what the most efficient solution to a linear algebra problem was.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 30, 2020, 1:18am UTC](https://discourse.julialang.org/t/how-is-julia-written-in-julia/50918/10 "2020-11-30T01:18:37Z")

</div>

I know people who “copied” the `searchsorted` algorithm from Julia and Numba JITed it for their own utility package, works like a charm. The reason is of course the implementation in Numpy it’s “not accessible” 😉
