Can someone help fix this bug in the Rust compiler?/Why reloading code is awesome

I've encountered and reported this issue, but without much knowledge of the compiler's internals, (what little I have has been gained through trying to fix this bug!) I don't know what else I can do to fix it. I have already a small example demonstrating the problem, determined the pull request the problem started in, and I've further narrowed down the problem to this short diff. But I don't know how to proceed from here, beyond trying to find someone else with better knowledge of the compiler to help.

Since there hasn't been much attention paid to the issue, no one else must be affected by it, but I think more people should be doing what this bug is preventing me from doing.

What's the problem exactly?

Prior to the bug I was able to load a dynamic library, written in Rust, compile a new version of it and reload the new dynamic library, changing the behaviour of the program, all while the program was running. On the latest versions (1.20.0 and onwards) the behaviour of the program stopped changing.

Why would I want to do that?

Reloading the code like this allows extremely fast feedback. You can experiment with parts of the program it takes a long time to get to from program start-up without performing the same steps over and over or changing the program to jump to that point and having to change it back later.

If that paragraph didn't convince you, this video demonstrates what you can do when you have good, fast feedback, (and I think it's something everyone should watch either way!)

Here's a shorter video demoing a similar system in Clojurescript:

If that's still too long, here's a gif of my minimal example code and an editor configured to compile the code on save.

That's cool, but how does it work?

The two videos above show systems that use Javascript in the browser. The Rust example works quite a bit differently under the hood.

To understand how it works, you can look at my example code, (you currently need to compile on 1.19.0).

Or, you can watch this video which walks through getting a live code reloading system working on windows, in C++, using a dynamic library. (I've linked to the part where the reloading actually works).


I think you would have more luck for this one on

1 Like

I've posted it over there as well now. Here's a link

I have a create I made for this over here: GitHub - emoon/dynamic_reload: Dynamic reloading of shared libraries testing it now it seems to fail to reload in some cases but works fine most of the time (tested on 1.21)

I think the case when it fails is something on my side and not related to the Rust compiler.

Oh yes, I remember seeing your library before I first got this working. I opened this issue back then after trying the example. I just tried the example again using the latest master on 1.21.0, (on the same machine as before even,) and the behaviour was the same. I suppose my setup is still one of the edge cases.

Alright. I will try to setup a Linux VM and see if I get the same issue as well.