# Julia written in Julia?

**URL:** https://discourse.julialang.org/t/julia-written-in-julia/25781
**Category:** Internals & Design
**Tags:** question
**Created:** [June 27, 2019, 10:31pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781 "2019-06-27T22:31:17Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 27, 2019, 10:31pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/1 "2019-06-27T22:31:17Z")

</div>

Is it possible to write Julia completely in Julia using the PackageCompiler? Why is C/C++ needed at the moment? Just curious. 🙂

---

<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: [June 27, 2019, 10:39pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/2 "2019-06-27T22:39:19Z")

</div>

We don’t have simple to use low level language features. We have nothing that guarantee free of runtime calls.

---

<div class="post-metadata">

### Author: ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)
#### Post date: [June 28, 2019, 9:03am UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/3 "2019-06-28T09:03:04Z")

</div>

I was wondering whether developing more low level features is on the roadmap, to make Julia also viable as a “systems” language. If not, is it because it’s not why Julia was created, or more because of devtime constraints.

---

<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: [June 28, 2019, 11:45am UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/4 "2019-06-28T11:45:06Z")

</div>

It was never on any roadmap I’m aware of and it’s not even clear what **is** a system language. It’s not necessarily incompatible with “why julia was created” but also not because no one has time working on it.

In general, I don’t think making something a “system” language is ever a useful goal, unless you have a specific usecase in mind that requires it. Adding functions that is part of a “system” language could be useful and is probably being done from time to time depending on what you mean by system language just not for the purpose of making a “system” language.

This is similar for writing julia in julia, which is similar but certainly not the same. I also don’t see **much** value of getting rid of the C/C++ part completely. However, there are certainly cases that do and they are done from time to time. Just like adding “system” language features, they are done mostly as a mean to fix other problem for specific cases (performance, reduce duplicate, easy of maintainance) and not to achieve writing julia in julia.

---

<div class="post-metadata">

### Author: ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)
#### Post date: [June 28, 2019, 11:48am UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/5 "2019-06-28T11:48:19Z")

</div>

Yea I agree with what you say. To me what I would like is a more easy way of interacting with/controlling the GC. Anyway thanks for the clarification!

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [June 28, 2019, 12:32pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/6 "2019-06-28T12:32:15Z")

</div>

Well before Julia existed it had to be written in a language that already existed…Granted I believe Go wrote their “reference implementation” in C/C++, then once they had that, wrote the compiler again all in Go…but then they had google’s money behind them.

I’m sure if you wanted to fund a pure Julia compiler someone would be happy to build it 😃. Baring that, it’s probably better for the language if people focus on new features rather than re-writing existing working code. Well at least until they get threads fully implemented…I want that first!

---

<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: [June 28, 2019, 12:59pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/7 "2019-06-28T12:59:21Z")

</div>

> [@louisponet](#):
>
> To me what I would like is a more easy way of interacting with/controlling the GC.

That has nothing to do with how the GC is written. If the GC is ever written in julia itself, it’ll be hidden in a way that’s almost impossible for you to touch, only exposing necessary API just like what you have now.

> [@pixel27](#):
>
> I’m sure if you wanted to fund a pure Julia compiler someone would be happy to build it

If you give enough money for just this project and nothing else, sure. But still, the question is why you want to do it. If you don’t have some particular limitation of the current approach in mind (and these should be real/practical limitation rather than some abstract/vague ones that people likes to throw around) then it makes no sense to do it. If you do have some limitation in mind, then that’s an issue that could be specifically solved, which may or may not involve rewriting part of the runtime in julia.

---

<div class="post-metadata">

### Author: ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)
#### Post date: [June 28, 2019, 1:13pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/8 "2019-06-28T13:13:45Z")

</div>

> [@yuyichao](#):
>
> That has nothing to do with how the GC is written. If the GC is ever written in julia itself, it’ll be hidden in a way that’s almost impossible for you to touch, only exposing necessary API just like what you have now.

Yea I know, it was more a comment on low level language features. Sorry for going off topic

---

<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: [June 28, 2019, 1:26pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/9 "2019-06-28T13:26:16Z")

</div>

Not really OT. What I mean is that whether the GC is written in julia, or whether julia get’s more low level features, or both, it’ll not make interacting with the GC easier. The GC, and much of the runtime, is meant to be hidden, they are implementation detail and must maintain certain invariance and are not meant to be touched by the user freely.

Now if you mean you want a easier/guaranteed way to **not** interact with the GC, that’s indeed something that has come up before and AFAICT the status of that is that we have enough support (unsafe\_\* llvmcall, ccall) that for anything that doesn’t need a guarantee it’s mostly good enough. There hasn’t been much (any?) usecase that needs such a guarantee either.

---

<div class="post-metadata">

### Author: ![gabrielfreire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gabrielfreire/32/8799_2.png) [@gabrielfreire](https://discourse.julialang.org/u/gabrielfreire)
#### Post date: [June 28, 2019, 2:50pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/10 "2019-06-28T14:50:17Z")

</div>

Interesting topic, could someone explain to me what makes a language, a system language and why Julia can not be considered one ?

I’m on Windows 10 and i can call 100% of the Win32 API from Julia and do all sort of stuff, like windows services, some networking stuff, create windows, close them, list installed fonts, get the hostname, etc…

I wouldn’t say i can create kernels in Julia because i don’t know how to create one.

But if somebody could define “System programming language” for me and why Julia is not one, i would appreciate.

---

<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: [June 28, 2019, 3:11pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/11 "2019-06-28T15:11:26Z")

</div>

> [@gabrielfreire](#):
>
> Interesting topic, could someone explain to me what makes a language, a system language and why Julia can not be considered one ?

That’s exactly why I said,

> [@yuyichao](#):
>
> it’s not even clear what **is** a system language

I believe it’s more or less talking about language you can write a OS kernel with or something on that level. It’s definately not about interacting with OS API. You can almost always make them work in any language.

It’s more about a set of features that you need to have to give you enough low level control. I don’t think it’s a sharp line either… That’s why I don’t like talking about “system” language… It’s more useful to say what you want to use julia for and which feature(s) you are missing. There are enough different “systems” that I don’t think it’s useful to talk about them altogether especially without a universal definition of “system”…

---

<div class="post-metadata">

### Author: ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)
#### Post date: [June 28, 2019, 4:11pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/12 "2019-06-28T16:11:24Z")

</div>

I understand the reasoning to keep the GC unexposed, but wouldn’t it be pretty nice if one could annotate code to help the GC be faster. One scenario that springs to mind would be heap-allocated work buffers inside a function that 100% certainly will not be used anywhere outside the function. If I could say at the end of the function `@gc_destroy_allowed buffer1, buffer2` (or whatever variation), wouldn’t that speed up the GC’s work a bit? I’m not really familiar with how the internals of the GC work so I might be wrong.

---

<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: [June 28, 2019, 4:48pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/13 "2019-06-28T16:48:45Z")

</div>

This is indeed a little ot. But anyway, I realized that I haven’t said his for long enough that it’s probably worth putting it up again.

One thing to realize is that freeing is not free. You must do work to free memory, work needed so that you can use the memory again, or else why are you freeing the memory in the first place…

So there are basically two aspects of freeing memory afa the GC is concerned, to mark it as not needed and to actually free it. In a tracing GC, the first is free (dead memory cause no time in marking) and does the second in bulk. Both of these are very important for the performance of the GC. In particular, the bulk freeing is actually one of the main reason, I believe, that a GC can achieve higher throughput than manual memory management. That this means is that if you don’t do freeing in bulk, you can easily loose performance, rather than gaining it and just marking something free is useless since it doesn’t take the GC any time to ffigure that out anyway.

Now this is not to say there’s nothing you can do to help the GC, but it won’t be trivial at all. It would almost have to be a very integrated solution, which might involve changing part of the GC to have different kinds of memory, maybe changing the compiler to take advantage of this (another way of having a different type of memory), and possibly other ways. And even with these, I think the most useful thing you can do is to give the compiler more escape information and then it isn’t necessarily a “help GC” anymore and we’ve certainly done a lot about it.

There are also other ways you could “help” the GC, but I think in general you can’t trivially help the GC in any meaningful way. There are certainly still areas you can improve the GC, but there are very few that doesn’t involve a trade off.

---

<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: [June 28, 2019, 4:51pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/14 "2019-06-28T16:51:41Z")

</div>

Actually, one of the easiest way you can help GC is to declare an allocation perminant so that the GC will never need to look at it. We already do that automatically for some object. I imagine it goes against what most people imaging though… The GC really don’t want to free things when it doesn’t have to…

---

<div class="post-metadata">

### Author: ![louisponet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/louisponet/32/2070_2.png) [@louisponet](https://discourse.julialang.org/u/louisponet)
#### Post date: [June 28, 2019, 5:00pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/15 "2019-06-28T17:00:32Z")

</div>

Nice, thanks for this explanation, I wasn’t aware that finding what memory to free was … free. Then indeed what I was thinking of won’t do anything at all. The bulk freeing argument makes complete sense to me too!

---

<div class="post-metadata">

### Author: ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)
#### Post date: [June 28, 2019, 5:26pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/16 "2019-06-28T17:26:01Z")

</div>

As go was mentioned, it seems a garbage collected language can be used to write a fast interpreter. I think that maybe there is I problem in generating a binary without including the original interpreter. Writing an interpreter in a compiled language seems like an easier task.

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [June 28, 2019, 5:36pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/17 "2019-06-28T17:36:11Z")

</div>

I believe the DLang compiler is written in DLang…and to be fast they disabled the garbage collector…which really makes me worry about their garbage collector implementation. They do have a “lowmem” flag to enable it…

---

<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: [June 28, 2019, 6:18pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/18 "2019-06-28T18:18:26Z")

</div>

Compilers and interpreters can be written in GC language just fine and we basically do. GC is really hard to be written to manage itself though.

And in the end there’s still the why question. Its not impossible to add all the bits to make it possible. We are pretty far from being benefit from any hypothetical advantage writing everything in julia provide anyway…

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [June 28, 2019, 7:04pm UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/19 "2019-06-28T19:04:50Z")

</div>

You may find these previous discussions helpful:

> [@The role of femtolisp in Julia?](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/18):
>
> I’m not sure where you read about a “definite” plan. There are certainly people who expressed an interest, but e.g. as @JeffBezanson [wrote](https://groups.google.com/d/msg/julia-dev/dOAwcwm5iEA/dJFqob5HfNYJ): The fact is that no one appears to be seriously working on making Julia self-hosting right now. There are far too many more interesting problems to work on.

[https://github.com/JuliaLang/julia/issues/32282](https://github.com/JuliaLang/julia/issues/32282)

Note in particular the article Jeff posted:

[https://tratt.net/laurie/blog/entries/the\_bootstrapped\_compiler\_and\_the\_damage\_done.html](https://tratt.net/laurie/blog/entries/the_bootstrapped_compiler_and_the_damage_done.html)

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [June 30, 2019, 10:32am UTC](https://discourse.julialang.org/t/julia-written-in-julia/25781/20 "2019-06-30T10:32:55Z")

</div>

> [@yuyichao](#):
>
> I believe it’s more or less talking about language you can write a OS kernel with or something on that level.

I used to believe that’s what people meant by “systems language” but then at some point people shifted the meaning and started to use the term to refer to languages for writing servers and such, which Julia definitely can do. So if you want to write a kernel, you could do it in Julia but it would be a weird choice. If you want to write servers, Julia is a totally fine choice—the I/O model makes writing concurrent servers pretty simple. Being self hosted has nothing to do with either of these.

[Next page](https://discourse.julialang.org/t/julia-written-in-julia/25781.md?page=2)
