It's interesting that GCC has a custom GC.
It's interesting that GCC has a custom GC.
Yes: memory management in the compiler is interesting. There's a complicated graph of pointer references. Most of the time the compiler is building something relatively small, so we don't need to bother cleaning up, we just exit without freeing it all (for speed). But when e.g. building with Link Time Optimization, we can use large amounts of RAM, so a garbage-collection can be needed.
When I first started writing compilers, I learned the craft from people who happened to also be GC zealots, and they insisted that it was not possible to write a compiler any other way.
I remember once talking to a VM hacker who wrote compilers in C++ and was shocked that it was even possible to write a compiler in Java.
Then I saw LLVM, which mostly just relies on new/delete and an intuitive ownership model. I've done that ever since.
But as a memory management nerd I have to say that there are some advantages to every approach. Arenas are cheap and intuitive. GCs mean you don't have to care about lifetimes. Malloc/free minimizes object drag. Pick what you like and don't let anyone tell you that any one of these approaches is inherently better than the others.
The RTL dump format does look a lot like Lisp, FWIW; see: https://gcc.gnu.org/onlinedocs/gccint/RTL.html or this article I wrote a while back on it: http://developerblog.redhat.com/2014/09/16/improving-gccs-in...
(This aspect of GCC is probably the oldest, written by RMS back in the late 1980s, I believe).
GCC wanted to run on anything that had enough RAM, so it's written in C (and now I think C++). I think a language with garbage collection and ML style pattern matching would be nicer for writing a compiler, and I don't think porting the GC runtime to every platform is that much work, but Microsoft didn't rewrite their compilers in F# and Oracle didn't rewrite the Java compilers in Scala, so maybe I'm missing something.