Why is Nim translated to C and not to LLVM IR (eg like Rust)? What are the advantages / disadvantages?
I think that as a programmer you can already master C and thus optimize it better than doing it in a completely new language like IR. In addition, the whole LLVM framework is very extensive and complicated. On the other hand, does the IR allow more possibilities as an intermediate language?
Compiling to C(++) gives us C(++)'s portability and a dirty/better way to interop with C(++): features like .emit, .header, .incompleteStruct, .codegenDecl are harder to do with LLVM.
That said, C is a pretty bad compiler target language because it doesn't support precise stack tracing for GCs nor efficient exception handling. Thanks to its preprocessor you never know which identifiers might actually be unusable as object fields (obj->unix can fail to compile...). LLVM doesn't have these problems.
First, Nim generally is not slower than C. You can write Nim code which is translated straight to C. But of course you may use high level constructs, which may be a bit slower, or you may do too many heap allocations for example, which can make your code a bit slower. And maybe some library modules are not yet as fast as they could be.
Advantage of C++ backend can be, that C++ supports exceptions, with no or minimal runtime overhead. Plain C does not, so some people may prefer compiling to C++.
Java-Script backend -- well that is the language of the web, so it is good that Nim supports it. And finally, there is also a LLVM backend available already, with some restrictions.
When you are really looking for disadvantages of Nim compared to C -- well Nim executables are small, but not so tiny as a C hello-world of only about 10k. Because Nim has a small runtime library and Garbage-Collector support in its executable. But thinking about that, my former statement is not really true, as we can compile Nim using runtime and GC as external libs, so executable is indeed only a few kB. So maybe GC is only remaining disadvantages. But with newruntime we may be able to use Nim without GC, and for most apps GC is no problem at all.
That sounds really good and promising! In a nutshell, how does newruntime make the GC obsolete?
I had dealt with Rust and must say, after initial enthusiasm, I found this language far too complicated and extremely painful of syntax; especially the reference concept, borrowing etc. — Regarding NLVM: Is not the effort enormous to write LLVM IR directly? The language does not seem to be very legible.
In a nutshell, how does newruntime make the GC obsolete?
The basic idea was sketched here:
https://nim-lang.org/araq/ownedrefs.html
but it has been revised a few times. For the most important Nim data structures like strings and seqs it seems to work fine, so that many Nim programs just will not need the GC. And other programs, maybe with very complicated data structures, can continue using the old runtime with one of the provided GCs.
cumulonimbus gave you the link to Nim's LLVM backend, it has some restrictions currently.