D
D
Dima Sokolov2018-03-12 16:59:33
Rust
Dima Sokolov, 2018-03-12 16:59:33

Does Rust use a virtual machine?

Does Rust compile to native code or to bytecode and use a virtual machine?! There is no information anywhere about this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Ariox41, 2018-03-12
@dimka11

Rust is a programming language, a virtual machine is a runtime. You can compile Rust to wasm and run it under a virtual machine (node.js or in a browser), or you can compile to native code and run like a normal application. True, so far the wasm ecosystem has not yet been developed, but in general it works, and the language itself is still not up to maturity.
The difference from languages ​​originally designed for the VM is that Rust itself doesn't make any assumptions about it and doesn't provide extra features based on the VM's capabilities. In particular, it does not have the ability to control jit compilation. However, the same can be said about C ++, but there it has historically developed that for a long time there was simply no virtual machine for it (now it can also be compiled in wasm or JavaScript).
In practice, Rust compiles to LLVM - byte code that you can do anything with - compile to machine code, run directly on a virtual machine (theoretically), or translate somewhere else.

K
Konstantin Kitmanov, 2018-03-12
@k12th

Apparently, this question arose due to the fact that Rust code is first compiled into LLVM bytecode, and then this bytecode is compiled into machine code for a given system. This is how LLVM works: source code → frontend (language compiler) → LLVM → backend (translator from LLVM bytecode to target platform mashcode) → binary in target system mashcodes.
Thus, the finished binary is native code and does not use a virtual machine or bytecode.
PS Well, of course, when we compile to wasm, we get code for a virtual machine, because WebAssembly is one, but for this machine, the resulting code is native. It's so simple and clear! :)

D
devalone, 2018-03-12
@devalone

No, does not use

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question