News for hackers. Stuff that matters.
Re:No Compiler – On LLVM, and writing software without a com... by exDM69 on Friday March 04, 2016 @03:54AM (#11222722)
> I would have said this too a few years ago, but Go is a huge counterexample.

I've been wondering about this ever since Go came out. If I recall correctly, LLVM was already a viable option back then.

The latest release of Go earlier this week featured a pretty big revamp of their backend with a new SSA-based middle/backend. I wonder how much work went into that and could they have achieved that faster had they been on LLVM since day 1.

Re:No Compiler – On LLVM, and writing software without a com... by akavel on Friday March 04, 2016 @06:28AM (#11223097)
There's an "official answer" in the FAQ [1] ("We considered using LLVM for gc but we felt it was too large and slow to meet our performance goals." Note: lowercase gc refers to Go compiler, whereas uppercase GC would refer to Garbage Collector). That said, I seem to recall other additional/more detailed reasons were given on various occasions too, including:

- ease of iteration and freedom to make huge breaking changes (and they did make use of it, see e.g. various generations of the GC, or the SSA work);

- thorough knowledge of the internals of the compiler they used (given they were it's authors; also this is linked to the reason I listed above);

- one of the explicit goals for the Go toolchain was that it must compile very fast (which I believe is also somewhat at odds with advanced optimizations, like those used in LLVM) - they even quipped something like "we designed Go while waiting for C++ to compile";

- additionally, though I'm not sure if it was ever spelled explicitly, I suppose they wouldn't want to get tied to the LLVM as a huge dependency, including having to adjust to each and every change in LLVM API, regardless if sensible or not (I seem to recall from so me articles that LLVM does introduce breaking changes in API from time to time?);

[1] https://golang.org/doc/faq#What_compiler_technology_is_used_...

Re:No Compiler – On LLVM, and writing software without a com... by exDM69 on Friday March 04, 2016 @08:36AM (#11223585)
Yes, GC is a big issue... or was back when Go was just getting started. GC support in LLVM should be MUCH better now. Ie. it has everything you need to hook up a GC in it, but there isn't a built-in GC in it.

And the fact that the first people working on Go have a good knowledge of the Plan9 toolchain probably gave them a head start. But that benefit has probably eroded long ago.

And I completely disagree with the Go team's emphasis on compile times. Fast result programs are far more important than fast compile times. Fast compile times are nice to have, but not much more than that. But this is just my opinion, it's as good as anyone else's.

Re:No Compiler – On LLVM, and writing software without a com... by iampims on Friday March 04, 2016 @12:29PM (#11225282)
Fast compile times let you use Go as a scripting language, which has been key to its adoption from the python/ruby community.

Fast compile times also let you run your test suite every time you hit ctrl + s.

Fast compile times also let you run tools like gomft without feeling like it is slowing you down.

I agree that fast programs are essential and (ideally) not mutually exclusive with fast compile times.

Re:No Compiler – On LLVM, and writing software without a com... by pcwalton on Friday March 04, 2016 @03:56PM (#11226793)
> I agree that fast programs are essential and (ideally) not mutually exclusive with fast compile times.

They are. It is always a tradeoff.

Re:No Compiler – On LLVM, and writing software without a com... by witty_username on Friday March 04, 2016 @08:11AM (#11223481)
> which I believe is also somewhat at odds with advanced optimizations, like those used in LLVM

You can configure the optimization level to 0, then only constant folding is performed when the IR is built, and nothing else is done.

Re:No Compiler – On LLVM, and writing software without a com... by amelius on Friday March 04, 2016 @04:14AM (#11222778)
I'd like to know what is the downside of using LLVM. Why did they choose to write their own optimizer?

Anyway, the most difficult part of writing the compiler was probably the garbage collector.

Re:No Compiler – On LLVM, and writing software without a com... by fmstephe on Friday March 04, 2016 @08:03AM (#11223454)
Russ Cox gave a really good answer to this question. I have to paraphrase because I can't find the original comment.

It was done for implementation speed. They had a compiler backend which they, the early Go team, were all familiar with. It was small so they could quickly change it to suit Go, rather than the other way around.

Russ Cox expressed the sentiment that if they had tried to use LLVM there would have been a lot of up front work that would have taken a long time and the Go project probably would have fizzled out. Using the plan 9 tool chain they were up and running very quickly allowing them to focus on the most important work, designing the language itself.

(Probably shouldn't attribute this to Russ Cox, I've probably read into his (rather briefer than what I wrote above) comments)

In my opinion this was the right choice. If LLVM turns out to be the best backend for Go it's easy to use it later. However, the language itself is largely fixed after 1.0. Better to focus on the language than the compiler backend which can be swapped out later.

Re:No Compiler – On LLVM, and writing software without a com... by pjmlp on Friday March 04, 2016 @08:14AM (#11223494)
> I'd like to know what is the downside of using LLVM.

Depending on C++ code and keep alive the belief that you can only create compilers in C and C++?

As many without experience in compiler development think.

Also, and this is specially painful when compiling Rust or Swift from source, saving themselves the pain of waiting around 4h for a clean compile.

Re:No Compiler – On LLVM, and writing software without a com... by kibwen on Friday March 04, 2016 @04:18PM (#11226931)
LLVM does take a long time to compile, but four hours is an exaggeration. A mid-range computer can compile it in 30 minutes with -j4, and a good computer can compile it in 10 with -j8.
Re:No Compiler – On LLVM, and writing software without a com... by pjmlp on Saturday March 05, 2016 @03:03AM (#11228834)
Core duo netbook with 4GB RAM and 5400 RPM hard disk.

I can assure you it really does take 4 hours.

And to bring the point home, I can link you to the Swift issue where I was discussing this matter.

Re:No Compiler – On LLVM, and writing software without a com... by Manishearth on Sunday March 06, 2016 @11:48PM (#11237156)
Heh, I was in this same boat two years ago. Servo used to build its own Rust back then, and that involved building llvm. I hadn't yet discovered ccache[1] and I had an old 4GB RAM laptop with a Core something processor. Took 4-6 hours total IIRC. This was also a really old laptop, so that was understandable. But very very annoying, since sometimes I'd need to rebase over a rustup and then wait hours for the build to work. This was a large part of my impetus to move servo to a state where we download Rust snapshots.

[1]: Btw, if LLVM compile times are getting to you, Use. Ccache. It is amazeballs.

Re:No Compiler – On LLVM, and writing software without a com... by bitJericho on Saturday March 05, 2016 @03:08AM (#11228845)
A core duo isn't even in the realm of mid-range. That's very nearly a 10 year old processor!
Re:No Compiler – On LLVM, and writing software without a com... by pjmlp on Saturday March 05, 2016 @05:16AM (#11229059)
Yeah, but it works perfectly well as a travel netbook for coding on the go.

Also I never had 4h builds with single core processors back when I was working full time with C++. The slowest ones were around 2h.

A core duo would run circles around those computer systems, hence my dismay how much hardware LLVM requires for building.

Re:No Compiler – On LLVM, and writing software without a com... by bitJericho on Saturday March 05, 2016 @05:28AM (#11229082)
I would imagine compiler design has become much more complex in 10 years, and a low end i3 is something like at least 3 times faster than a core duo.
Re:No Compiler – On LLVM, and writing software without a com... by pjmlp on Saturday March 05, 2016 @06:07AM (#11229147)
I would agree if other compilers, not LLVM based, took as much to compile.

Also that is surely a side effect how they are using C++, which desperately needs modules.

Re:No Compiler – On LLVM, and writing software without a com... by pcwalton on Sunday March 06, 2016 @06:08PM (#11236049)
Those compilers don't do nearly as much optimization as LLVM does. It's hard to overstate how wide the gap between the classical compilers you like and LLVM/GCC truly is. LLVM has no fewer than three IRs, each with a full suite of compiler optimizations (four if you count ScheduleDAG). LICM, just to name one example, runs at each stage (see MachineLICM.cpp). Turbo Pascal did nowhere near that level of optimization, and it produced unacceptably slow programs by modern standards.
Re:No Compiler – On LLVM, and writing software without a com... by markokrajnc on Friday March 04, 2016 @05:28AM (#11222934)
Maybe the biggest issue is optimizing register allocation while providing the information for all roots for the garbage collection... For non-GC languages you don't need to care about it and just agressively optimize register allocation. For GC languages you have to be careful, because the GC must know 1) which registers are holding references and which not 2) which of those registers are "alive" and which are not in use anymore (and therefore ready for garbage collection)...
Re:No Compiler – On LLVM, and writing software without a com... by pcwalton on Friday March 04, 2016 @11:12AM (#11224669)
LLVM has full support for precise garbage collection.
Re:No Compiler – On LLVM, and writing software without a com... by aikah on Friday March 04, 2016 @04:35AM (#11222823)
Is LLVM that well supported on windows ? Go aims at running on as much platforms and it seems to me a lot of languages built with LLVM don't run on windows (Swift,Crystal,...).
Re:No Compiler – On LLVM, and writing software without a com... by kryptiskt on Friday March 04, 2016 @05:02AM (#11222888)
LLVM works well on Windows and can even be built with Visual Studio.