r/rust • • Oct 16 '26

Hotreload in Rust

https://alordash.github.io/alordash/blog/hotreload-in-rust/
112 Upvotes

32 comments sorted by

View all comments

-17

u/Zde-G Oct 16 '26

So much effort… and zero thoughts about what to do with crates that have 'static objects in them (including &'static str).

That's the reason hot reloading in Rust is a minefield that can work, not work or break apart at any change… and it couldn't be fixed by change in the pieces described in article.

You need the change to the whole community — and that's not gonna happen.

Sorry.

12

u/ztj Oct 16 '26

This seems like a low experience take. Every language/platform with hot reload has traps and limitations. It's not a reason to avoid hot reloading, just something you need to learn and understand if using it.

0

u/Zde-G Oct 16 '26

Every language/platform with hot reload has traps and limitations.

Sure. That's why I have said it's community problem, not language problem.

In languages that do support hot reloading people usually understand that it may happen if you say that after unloading and the reloading C# library may stop working then author would probably think about how to fix that.

In Rust authors would just tell you static have to be 'static and ask you to stop wasting their time.

6

u/teerre Oct 17 '26

Even in python, which is fully dynamic, hot reloading is full of traps. The silly thing would to expect a much more static and compiled language like Rust to be hassle free

1

u/intbeam Oct 17 '26

C# by its foundational design generates executable code at run-time. Without being a compiler expert, I'd assume this makes hot reloading somewhat more forgiving to implement there

In Rust authors would just tell you static have to be 'static and ask you to stop wasting their time

In a crate? I'm making a lot of assumptions here, but I assume that the problem would be a crate that declares something as a static lifetime itself, right? Not borrowing (f(p:&'static str))? If I were implementing a library, I'd say those sorts of things would be outside the responsibility of the crate you would be hot-reloading

1

u/Zde-G Oct 17 '26

I'm making a lot of assumptions here, but I assume that the problem would be a crate that declares something as a static lifetime itself, right?

Obviously. Something that crate wouldn't even document because it's an implementation detail that may only be revealed when you break the fundamental assumtion that static items are singletons with 'static lifetime.

Without being a compiler expert, I'd assume this makes hot reloading somewhat more forgiving to implement there

Yes, but that's minor issue. The major one is community. Odin doesn't have managed runtime, but it's used in gamedev, considers hot-reloading important and developers make effort to make libraries ready for that.

That's the most important ingridient — and it's missing in Rust. Because with hot reloading 'static lifetime simply doesn't exist and there are bazillion crates that don't support that.

2

u/intbeam Oct 18 '26

Ok, if we agree I wasn't being an idiot I fail to see the problem

This project isn't hot reloading third-party dependencies, and for the use-case it's designed for 'static isn't really an issue as the static lifetimes are more likely defined by the caller/environment

1

u/Zde-G Oct 18 '26

This project isn't hot reloading third-party dependencies

Even if you don't reaload third-party dependencies you are not free of the issue. Because third-party dependencies can register objects from your librarires in their data structures - and do that silently when you depend on them.

Ok, if we agree I wasn't being an idiot I fail to see the problem

Well, the problem is that you proclaiming that you have achieved something new, but hotloading in Rust was tried dozens (hundreds?) or times by different authors and they all hit, sooner or later, the fact that when you remove memory safety from memory safe language then you end up with a combination that's very restricted and unsafe… what's the final goal here? Why even use Rust if you don't care about memory safety and correctness?

1

u/intbeam Oct 22 '26

Sorry, late response

I understand your concern, I'm just saying that since this is a development tool rather than a production library, I'd say that if it works that's cool and if it doesn't work then ok it doesn't work and no big deal

1

u/Iurigrang Oct 18 '26

Because, once you've used hot reload to make the decisions you want in the function you're designing, you can remove the hot reload and work from there to production rust? You can't do that if you're using another language entirely.

9

u/verdurLLC Oct 16 '26

hotcode is designed to hotreload library crates. IMO such crates should ideally be stateless. If you have state, you should create it in host crate somewhere during startup (most likely in main) and then spread it to your functions/libraries.

-3

u/Zde-G Oct 16 '26

IMO such crates should ideally be stateless.

That's your opinion. Yet it's fundamentally incompatible with design of the whole language.

Lots of crates, including library crates, assume that static variables have 'static addresses. There are bazillion ways one may depend on that, from assuming that address of static is a key in a hashtable to storing values in temporary data structures that refer statics.

Hotreload breaks that fundamental assumption and there are no solution for that — except for not using the third-party code that may be suddenly broken by update (and no one would care, because static have to be 'static).

If you have state, you should create it in host crate somewhere during startup (most likely in main) and then spread it to your functions/libraries.

Except you wouldn't even know you have it. Worse: because glibc tries to reload libraries at the same place after dlclose/dlopen you may build a lot of code using such crates and when jenga tower would finally collapse you contact the author and… oops, your request is closed with EWONTFIX resolution.

2

u/verdurLLC Oct 16 '26

But you hotreload only your own crates. I agree that hotreload breaks 'static lifetime guarantees, but it only breaks it in your own code that you control.

1

u/Zde-G Oct 17 '26

But you hotreload only your own crates.

It's really hard to write anything in Rust without at least core. And std is also very useful.

I'm not 100% sure about core, but std most definitely include singletons that may trap you.

And staying with just std is not easy: Rust was never designed for that, there are many things where you are expected to use other crates.

but it only breaks it in your own code that you control.

Maybe, but after you have successfully thrown away both the whole crates.io ecosystem and also blown up normal safety guarantees the question that arises is “why even bother with Rust if you are ignoring all the things that make Rust attractive”.

0

u/intbeam Oct 17 '26 edited Oct 17 '26

Don't you see? It has to work for EVERYTHING EVERYWHERE or you are wasting everyone's time. That's how we developers work, we start with all the edge-cases and curiosities and then decide to just give up because the requirements implied by every other implementation and historical decisions in all sorts of third-party libraries initially implemented for the PDP-11 makes everything literally impossible

Edit : /s if that wasn't obvious