Awesome! vlang has it too: https://github.com/vlang/v/blob/master/doc/docs.md#hot-code-...
Nice! V does it the same way as Nim though, right? From quickly browsing over the sources, it looks like it is based on dynamic library hot swapping https://github.com/vlang/v/tree/master/vlib/v/live
Hot-code reloading on macOS/arm64 with Zig
51–57 of 57 posts
Re: Hot-code reloading on macOS/arm64 with Zig
#52Earlier quoted context omitted.
Nice! V does it the same way as Nim though, right? From quickly browsing over the sources, it looks like it is based on dynamic library hot swapping https://github.com/vlang/v/tree/master/vlib/v/live
V author here. Yes, dynamic library hot swapping, but we're also planning to implement a more sophisticated way to do this.
Re: Hot-code reloading on macOS/arm64 with Zig
#53Earlier quoted context omitted.
JITs don’t need to reload code, they run the same code and tier it up to an optimized implementation when it gets hot. No execution context is lost, at least semantically.
> JITs don’t need to reload code If I've inlined a method, and someone redefines that method in a language that allows that, then I'm going to need to reload that code.
Re: Hot-code reloading on macOS/arm64 with Zig
#54Mach for Zig looks interesting too, but it's very new.
Re: Hot-code reloading on macOS/arm64 with Zig
#55Earlier quoted context omitted.
I have implemented live reload (in a much simpler and naive way) for my little game engine/framework written in C a few years ago, as a "scene" is essentially a reloadable shared library there. When it worked it was a huge productivity booster and time saver indeed, but I've eventually stopped using this feature that much once I started relying more and more on passing function pointers around as callbacks - so thing…
Optional late binding - function pointers that go through a lookup step (string or slot) before finding their destination.
Re: Hot-code reloading on macOS/arm64 with Zig
#56Earlier quoted context omitted.
The only entitlement that is relevant here is get-task-allow. But that would allow anyone to get a control task port for your application and do with it as they may. This functionality was not designed to be used in production — except for debugging. The debugger entitlement is even more powerful, but once again since you’re modifying your own memory you don’t need it.
Wait, but what about debuggers then? Plus hot-code reloading should only ever be used for quick development cycles when prototyping your app in debug mode, so very much what a debugger is used for, right? Additionally, I actually based the implementation of this PoC on lldb's debugserver for macOS.
What about evolutionary/genetic programming? That can definitely take advantage of this as well.
Re: Hot-code reloading on macOS/arm64 with Zig
#57Earlier quoted context omitted.
If that matters, you probably shouldn't be using hot code reloading regardless of the language or implementation.
> If that matters, you probably shouldn't be using hot code reloading regardless of the language or implementation. Why not? Perhaps I'm missing the point, but can't this be mutex'd away? Or perhaps you're refering to the fact that the hot code reloading mechanism should provide the mutex implicitly?
But if you write
result = 0
while true:
result += 2 * do_something()
and change that to this and reload: result = 1
while true:
result -= 2 * do_something()
then even "ideal, correct behavior" at a reload level can give you end result values that are not possible to get while running either version of the code end-to-end. It's not possible to "fix" that because it's doing exactly what you told it to do - either it preserves values and can produce impossible values, or it does not and it's not really hot-swapping any more. Or it does some mix of that and it has even more surprising / wrong edge cases.There are of course uses for systems with hot-swap boundaries/transactions to prevent swapping during critical regions, or to do something like stop and replace actors rather than touching their internal state, and they exist (e.g. erlang). But that requires your code to already be adopting those semantics, and it inherently defines boundaries on what is swapped and what is not. In that case the root "inconsistent transaction state" concern is not really a hot swapping issue, it's a failure to define your boundaries and semantics correctly - a normal bug / relying on undefined behavior.