I’m thinking of making a higher level programming language heavily inspired by Rust, basically adding some extra compiler features and automating of the borrow checker syntax that I’ve always wished Rust had. Where one of the main features is that whether you transfer ownership of, clone, or borrow a value can either be explicitly stated (like Rust) or left to the compiler to decide at compile time, and any functions you write can work with either borrowed values or values whose ownership gets transferred (as in, a function a(param: i32)
can accept either i32
or &i32
as the param and the compiler will use whichever version of the function is appropriate.
I’m also thinking, I obviously don’t know nearly as much about assembly and memory safety as the Rust people, and I’m basically just modifying Rust with some extra features I want, so could I just transpile my language into Rust and let the Rust compiler deal with all the assembly stuff? At least for the version 1 to get something that can start compiling code in that language, with the option to completely implement a compiler in the language itself when I’m ready to take on that task.
How stupid would it be to actually do something like this?
There’s many languages that started by compiling to C (including C++), so it’s an option. As another commenter has already said, it also means that you inherit everything of rust, which can be useful (borrow checker) but also tricky (language decisions, generate correct code). C is a much simpler language (in terms of features), so it’s easier to compile to, but Rust should be as doable.
Long term, probably less good of an idea than using LLVM, especially when you get into the MLIR extensions which let you define super simple transforms, however for just adding extensions to rust, using rust is probably a good idea.
Generally seems an okay idea to me because it allows you to use the rust tool-chain and you can more easily achieve compatibility with other rust code. In fact, there’s other languages which do something similar. I remember F* (f-star) which compiles to OCaml.
It’s certainly possible.
An type system can’t be both sound and cover all cases. Rust had made certain trade offs, and some weird edge cases regarding generic lifetimes still cause UB.
If you compile to rust you’ll be forced to inherit all the decisions Rust had made over the years, and won’t be able to tune then to your use case. That may it may not be a problem for you.