Mercury-Language/mercury

Rust backend

Immortalin opened this issue · 10 comments

Should be relatively straightforward?

Relative to what?

Generating Rust instead of high level C would indeed be relatively simple, at the
cost of having to give up pretty much all of the data structure representation
optimisations that the compiler currently uses when generating C. However,
you would also have to provide Rust versions of both the runtime system and all the
predicates in the Mercury system (such as the standard library) that are implemented
in foreign language code. Some of that, such as the library's store module, could be
quite problematic.

And then there is the $64K question: why?

Out of curiosity how good is the C backend right now for stuff like OS dev? Can standalone mode be used to do kernel development?

Mercury is a declarative, garbage collected language. One can theoretically build an OS kernel
using such a language (for example, Peter Henderson wrote about this almost 40 years ago),
but as far as I know, nobody has used such a language to actually build an OS that is used by
a nontrivial number of users. The quality of the language implementation does not matter here.
The point is that when you are writing e.g. a memory manager, using a GC'd language is like
performing repairs on a car while it is moving. It is a solvable problem, but people in general prefer
to solve problems without unnecessarily handicapping themselves.

I thought it can be compiled without GC?

Yes. But then you will run out of memory in a few seconds.

So it's not the Rust-style compile-time GC through static analysis?

No.

Right...any plans to make it more advanced since now the technology is now fairly well-understood? E.g. the Carp language uses Ownerships to avoid GC. Removing the GC limitation would make Mercury a lot more useful.

A student from KUL in Belgium added a prototype region-based memory management system
to Mercury. However, it does not cover the full language, it has some significant flaws, and it has
never been tested on anything bigger than a few toy programs.

There are no plans to take this further, since the current GC works quite well.

I see, Rust has this thing called Chalk.

https://github.com/rust-lang-nursery/chalk