5 ms·
I wonder how much effort would it take to add a rust code generator. I'm guessing we can't add a C code generator because idris seems to need a garbage collecto
by madushan1000 6y ago
I wonder how much effort would it take to add a rust code generator. I'm guessing we can't add a C code generator because idris seems to need a garbage collector.
- gnulinux 6y agoHaskell used to be compiled to C. (not sure if they still use this backend, I think main GHC backend compiles to LLVM). "Doesn't have garbage collector" is not a good reason not to be able to compile to C, surely garbage collection can be implemented in C.
- iso8859-1 6y agoJust because it is possible doesn't mean it's easy. If you implement garbage collection in C, you are using your own garbage collector, the C ecosystem doesn't support you in any way. When people make the argument of preferring a compilation target because it has a specific feature, they are not saying "target is not Turing complete, you can't implement this feature". They say "not natively supported and I would rather not implement this myself". And no, -fllvm exists, but it is not the default: https://downloads.haskell.org/~ghc/8.8.3/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm https://downloads.haskell.org/~ghc/8.8.3/docs/html/users_gui...
- pjmlp 6y agoGHC uses its own backend with C-- as intermediate language. The LLVM is just yet another one.
- andrepd 6y ago? Why shouldn't a garbage collector be able to be implemented in C?
- madushan1000 6y agosomeone definatly can, but better programmers than I, have worked for years to get jvm, v8 GCs to get where they are. So I don't even want to try.
- kryptiskt 6y agoIdris 1 compiles via C, it just has to implement a garbage collector in its runtime system. It should be noted that Idris 1 has much worse performance than Idris 2 compiled to Chez Scheme, it would take a serious effort to do better than the current Chez backend. The logical target for a high-performance backend would be LLVM instead of rust. After elaboration Idris 2 has a series of intermediate languages, from lambda calculus to a simple register machine. Creating LLVM code from the least abstract of them wouldn't be any harder than creating Rust code.
- madushan1000 6y agoI was thinking of rust specifically because of GC, I don't know how to write a GC and I don't even want to try. But if I use rust, I won't have to because of rust's zero cost abstractions.
- icen 6y agoThere seems to be a bit of confusion here. Idris doesn't provide the same tools and guarantees as Rust does to manage memory, and instead requires that implementations provide a garbage collector. If you're producing code for a collected language, you can forward on all of the allocations to that language, and if not, you will need to implement one. Zero-cost abstractions or not, Idris needs a GC from somewhere.
- kryptiskt 6y agoReference counting would go a long way though as there is very little mutation in a typical Idris program, so you could probably sew something together in Rust with Rc cells and a simple cycle detector. But basically, having true closures requires some kind of GC. That was already recognized in Steele's Lambda papers in the 70s. Rust has to make compromises with its closures to avoid that.
- madushan1000 6y agoI was hoping I could get by without resolving to to GC, utilizing the rust allocation model(RAII with syntactic sugar and compiler helping out basically). If I "have to" write a GC because idris programming model requires is, I don't think there is a lot of value in writing a rust code generator.
- saurik 6y agoI somehow (incorrectly I guess) thought Idris was strict (as opposed to Haskell) specifically to avoid a requirement on a garbage collector :(.
- sfvisser 6y agoThese things are unrelated. Idris is strict and performs heap allocations so does require a GC.
- senorsmile 6y agoNaive question: does the new linear type support in Idris 2 get it closer to possibly not needing garbage collection?