Shizcow/hotpatch

Hotpatching structs

Closed this issue · 5 comments

Can you see a path towards hotpatching structs as well as functions?

I am currently working on a way of hotpatching associated functions (travelling at the moment, will be another week or so). IE methods without a self parameter.

Is that what you mean by hotpatching structs? Or something else?

I mean reloading structs themselves, rather than functions associated with them.
Example:

#[patchable]
struct Reloadable {
    var1: u32,
    var2: String,
}

Then I could add a var3 to the Reloadable struct for example, and it would patch all the places where that struct is used in memory. Kind of what mun is trying to do. Even if was done using serialization, it would be very useful.

TLDR; only some parts and it requires features not yet in nightly.


After checking out mun, I've given this some thought. mun's hotreloading struct features seem to mostly address:

  • Renaming fields (when types match)
  • Moving fields (when types don't match)
  • Remove struct fields
  • Add struct fields

Adding may be possible down the line when trait members are in nightly (and removing when the trait library is no longer in use). I don't think removing the original members is even possible in a static typing system, but that's not super interesting anyway. I do plan on trying this when trait members are a thing, but that's a ways out.

Doing this with dynamic types wouldn't work with Rust's syntax, making it too unweildly for consideration.

Of course I'd be happy to be proven wrong.

That's fair enough, and I do think it's outside the scope of this crate. Although mun was just given as an example and the approach could be completely different i.e., not caring about the individual fields and just wholesale replacing the struct.

mun was just given as an example

Yeah for sure. I totally follow on the fundamental features you presented.

I'll close this as wontfix for now, noting that once trait members are in nightly this will be given another shot. Thanks for bringing this up.