Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Rust interpreter?

I am just starting with Rust and was wondering: is a Rust interpreter? With an interpreter the Rust compiler would not need to compile all the source files every time it is invoked and would only interpret the code as it changed. It's how JavaScript and Python have no real compile time.

There's incremental compilation with Rust but it's still very slow with big projects. It would be a boon to GUI development with rust for the web IMO.

like image 203
SomethingsGottaGive Avatar asked May 16 '19 22:05

SomethingsGottaGive


People also ask

Does Rust have interpreter?

Unlike Python or JavaScript, Rust is not an interpreted language. Instead of an interpreter, a compiler is used, as in C, C++, and Java. In practice, this means that executing code involves two steps: Compiling the source code.

Is Rust interpreted language?

Rust is a systems programming language, and instead of an interpreted language like JavaScript or Ruby, it has a compiler like Go, C or Swift. It combines no active runtime (from C) but offers language ergonomics known from Python and Ruby (see Figure 1.3 for refence).

What compiler does Rust use?

Apple's Swift language uses LLVM as its compiler framework, and Rust uses LLVM as a core component of its tool chain. Also, many compilers have an LLVM edition, such as Clang, the C/C++ compiler (this the name, “C-lang”), itself a project closely allied with LLVM.

What language is Rust closest to?

Rust's type system supports a mechanism called traits, inspired by type classes in the Haskell language.


2 Answers

I think the closest thing to what you'd like to see is the Rust Language Server. Specifically, IDEs use this to feed in just the changes so that code compiles much faster.

There's also work on RLS 2.0 that you might be interested in watching / contributing to.

As far as UI / Web, that's a different ball of wax that I haven't had much luck with yet.

like image 55
RandomInsano Avatar answered Oct 24 '22 13:10

RandomInsano


No, there is currently no Rust interpreter that can simply be used as a replacement for compiling with rustc.

There is miri which is an interpreter for MIR, the Rust "mid-level intermediate representation" (basically defining a control flow graph). The Rust compiler generates MIR code as part of its usual pipeline. This MIR code is usually translated to LLVM-IR next, which is then translated to machine code by LLVM. Miri allows to interpret that MIR code directly.

However, Miri is not really build for programmers to interpret their project instead of compiling it. At least not yet. Instead, it is built mainly to check unsafe code for undefined behavior: a dynamic code analysis tool/sanitizer. Additionally, Miri is still notably limited. In particular, last time I checked, extern "C" calls were not supported.

I would also say that Rust is not as well suited to be completely interpret as other languages. The Rust compiler performs a fair amount of heavy analysis on the source code which has to be done at some point one way or another.

like image 27
Lukas Kalbertodt Avatar answered Oct 24 '22 13:10

Lukas Kalbertodt