4 ms·
This guy wants to use Rust as a target language for a compiler. He likes that Rust doesn't have too much run-time machinery, such as a GC or a JVM. OK, fine. Co
by Animats 10y ago
This guy wants to use Rust as a target language for a compiler. He likes that Rust doesn't have too much run-time machinery, such as a GC or a JVM. OK, fine. Compilers have been written to target C for similar reasons.
Then he wants a "battle hardened GC", a JVM, access to the internal syntax tree of the compiler, and enough dynamism to allow an interpretive environment. What? Those are all features that Rust deliberately doesn't have. Adding them would drastically change the language and add considerable complexity. They would not contribute to Rust's main goal - provide something in which to write reliable production software.
From the feature list this guy is asking for, what he really wants is Microsoft's ".NET" system. That has all the run-time stuff he wants, and multiple compilers compile to it.
- Manishearth 10y agoThe point, which he outlines in the post, is to be able to mix high level programming with lower level languages. This is already a common pattern in the industry where you write your application in python/ruby and speed up the tight loops with C/C++/Rust. The lingua franca of the interop is C. Which means that the boundary between the two is very stark and unsafe. You can't use advanced typesystems or seamlessly share datatypes. I'm working on something similar these days (C++ and Rust though, no high level language). You lose all template/generics info at the C bindings boundary. Bindgen programs let you get it back to some degree, but forcing monomorphization/etc are all not easy problems to solve without making the compilers talk to each other (also not easy to do). Will's idea seems to be to use Rust as a target for a high level GCd language, which can then (mostly) seamlessly interop with "pure" Rust code, and the interop won't have an unsafe boundary.
- pjmlp 10y agoYou should check how COM and now WinRT (aka 2nd coming of COM+ Runtime) work. You get an OO ABI, with support for generics and OS level interoperability and reference counting as the GC algorithm. Yes, using COM from C is a pain, but it was never intended to be used as such, rather C++, VB, Delphi and any other Windows language able to speak COM.
- Manishearth 10y agoYeah, I'm aware :) I don't like it as much but that's because I've always ended in situations where I need to bind via a C API, which isn't COM's fault.
- mike_hearn 10y agoYou might want to read an article I wrote on a new technique that allows high and low level languages to be mixed (relatively) seamlessly: https://medium.com/@octskyward/graal-truffle-134d8f28fb69 https://medium.com/@octskyward/graal-truffle-134d8f28fb69
- Manishearth 10y agoOoh, this is cool and interesting :) It seems to address a similar need as the one i mentioned above, among others.
- wcrichton 10y agoFirstly, I think that .NET is an excellent reference here. Its platform for language integration is a good model for the kind of thing I want to achieve. Honestly, I don't use it more just because I've never used C#/ASP/any CLI language. I can't give an honest comparison between my vision and what .NET offers, but I'd appreciate it if someone more versed could comment. As for what I want from Rust: when I ask for a GC, this doesn't have to be in the compiler. It can be implemented as a library. Access to ASTs is coming in PRs (see the links in the post). And I don't need Rust to change to get a REPL, I just need to fix the darn JIT. I'm only asking Rust to change to support a few features which greatly improve the experience of using Rust as compile target.
- pjmlp 10y agoThe original idea of .NET was to migrate the whole Windows stack to it, hence why MSIL is much more flexible than JVM bytecode, as it had to be language neutral and even support C++. Initially Microsoft was going to make it fully native and based on COM, it was called Ext-VOS project from Microsoft Research and the runtime COM+ Runtime. Eventually they decided to create the CLR instead and things never fully worked out that way. However with Windows 8 they have gone back to the original idea and WinRT was born. Which is basically the same COM+ Runtime ideas, but using .NET metadata instead of COM type libraries. On Windows .NET follows a similar idea as mainframes do language interoperability by having the runtime being part of the OS. The whole problem with GC and JIT implementations as library is that they will never be as good as the ones that work together with the compiler. There are many types of optimization algorithms that require an helping hand of the compiler how the data structures and specific code patterns get generated. Of course it depends what are the goals in terms of performance, throughput and latency.
- Manishearth 10y agoSee my comment above, Rust may (probably will) get intrinsics and traits that let you write a gc that works with the compiler. Not as awesome as a GC irrevocably designed into the compiler, but good enough.
- electrum 10y agoThe JVM, especially with Graal and Truffle, would also be a good fit: https://medium.com/@octskyward/graal-truffle-134d8f28fb69 https://medium.com/@octskyward/graal-truffle-134d8f28fb69
- wcrichton 10y agoSee my comment [1] on the recent Graal/Truffle piece for why I'm moving away from those frameworks. It just seems too cumbersome to write a compiler in Java. [1] https://news.ycombinator.com/item?id=12123657 https://news.ycombinator.com/item?id=12123657
- mike_hearn 10y agoAnd yet Rust, with its famously awkward borrow checker, isn't cumbersome at all? I find this set of priorities a little odd. But if you want less verbosity, you can write your compiler in Kotlin instead. There's no requirement that Truffle languages be written in Java, they just do it that way because Java gives closest control over the bytecode which is generated. But Kotlin generates bytecode that's very similar to what Java creates, so you could use it and get a more modern syntax. At any rate, I can guarantee you that adjusting an existing language to be less verbose or more to your liking is a lot less effort than building an entire ecosystem of compilers that try to use Rust as their lingua-franca, given that Rust was never designed for this task.