JIT style dynamic compiler

I have seen some stuff like Java or C# compiler running some optimizations at compile time. Can something similar be added, like a macro? Like unsafe but with dynamic compiling for purely that section? It might improve performance in some of those cases.

MIRI is an interpreter, not a JIT.

Running optimizations at compile time is exactly what Rust does as AOT compiler.

What do you mean with "like unsafe"?

5 Likes

I think what is being suggested here is a block that instructs the compiler to compile the contained code to some form of bytecode or other IR that would then be JIT-compiled at runtime.

Such a thing would take a great deal of work, but there's no fundamental reason why it couldn't be done. It wouldn't even need to be built into the compiler; procedural macros could accomplish this, combined with a JIT-compiler built as a crate.

If OP wants this, I would recommend building it yourself; I expect it will be very difficult to persuade others to do the large amount of work involved on a volunteer basis.

1 Like

Rust has been jokingly referred to as "the new C++". I guess the reasons there are no Jit compilers for Rust are similar to why there are no Jit compilers for C++ or C.

1 Like

For incorporating runtime information into how Rust code is optimized, check out profile-guided optimization.

That's not a JIT, of course, but it can get you some benefits similar to ones a JIT gives you, namely runtime analysis of what optimizations should be performed.

Edit: as it were, there's a new Inside Rust post on PGO:

9 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.