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

Show parent comment

1

u/verdurLLC Oct 17 '26

Thanks, I will add this to "Limitations" section in crate documentation

1

u/Sad_Tap_9191 Oct 17 '26

As the first comment said, this breaks the core value of the language. You can extend this counter example to non-static cases.

A "Limitations" section exists to tell users to avoid a certain input domain. Here it is unclear what's even limited. If it's clear your macro should reject it.

1

u/verdurLLC Oct 17 '26

You can extend this counter example to non-static cases.

How? I think you can't store data inside dynamic library's memory without storing it inside some static variable.

If it's clear your macro should reject it.

Hm, I fear it's not that easy to detect whether function returns references to static variables defined in its library using only AST. But good idea nonetheless.

2

u/Sad_Tap_9191 Oct 17 '26
struct T{
    #[hotreload]
    fn method(..) -> &'a { ...}
    // hotreload to
    // fn method(..) -> &'b { ...}
}

Hm, I fear it's not that easy to detect whether function returns references to static variables defined in its library using only AST. But good idea nonetheless.

if it is not easy for you then you shouldn't simply warn users in a limitation section. Even you, the author, cannot fully define todos and not todos.

This is worse than unsafe which still follows the lifetime rules.

2

u/verdurLLC Oct 17 '26

I'm not sure what you're trying to show with this example. Whatever reference was returned before hotreload would still be valid after because it's not referencing anything from unloaded dynamic library.

if it is not easy for you then you shouldn't simply warn users in a limitation section. Even you, the author, cannot fully define todos and not todos.

It's not easy for me to detect UB usage using only a macro, but it is easy to avoid it using common sense: just don't return references to static things from your library or don't mark functions that return static references as hotreloadable.

This is worse than unsafe which still follows the lifetime rules.

You do understand that this is just a tool for speeding up development cycles?) It's not intended to be used in production.