New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hot code swapping #68

Open
andrewrk opened this Issue Jan 14, 2016 · 8 comments

Comments

Projects
None yet
7 participants
@andrewrk
Member

andrewrk commented Jan 14, 2016

  • Have the compiler run continuously, watching the file system for source
    changes and automatically perform multithreaded compilation to build projects
    quickly.
  • Hot code swapping. When integrated with the previous feature, you could
    press "save" in your editor and see the change immediately in your running
    software.

Of course this only works for some kinds of changes - obviously if you make changes to your initialization code, you won't see a difference. But it would probably work at the function level, so you could swap out any individual function for a new one.

@PavelVozenilek

This comment has been minimized.

PavelVozenilek commented Feb 9, 2016

This feature (automatic rebuild in background & hot code swapping) is available for C++ in Projucer IDE, built upon LLVM infrastructure.

Old demo 1, old demo 2, few implementation details.

Be aware that it took several years to implement and the implementor said that "it was the most complicated thing I ever did".

@0joshuaolson1

This comment has been minimized.

Contributor

0joshuaolson1 commented May 25, 2018

@PavelVozenilek The Projucer link has died, sadly.

@ccll

This comment has been minimized.

ccll commented Jun 14, 2018

I always wonder how should hot-swap deal with data (data structure layout and long-lived in-memory state), it seems rather difficult compared to hot-swap stateless code (like a pure function).
In some languages which support closure, it's even more complicated.
Are there any articles on this subject?

@isaachier

This comment has been minimized.

Contributor

isaachier commented Jun 14, 2018

@ccll that is the biggest issue. Doing it in C/C++ is currently possible using a dynamically loaded library. See this blog post on the topic.

@themagnet

This comment has been minimized.

themagnet commented Jun 26, 2018

here https://molecular-matters.com/products_livepp.html is a commercial product which realizes hot-reload for c/c++ projects

@jaccarmac

This comment has been minimized.

jaccarmac commented Jun 29, 2018

I wonder if looking at the way Common Lisp deals with these things would be useful at all. Sure, CL has a fatter runtime than Zig at the binary level, but:

  1. If there is a watcher like @andrewrk hints we could possibly have it keep track of the old structure of the code it is watching.
  2. CL contains a full-blown object system and is able to manage updating all live instances of a CLOS class. Updating structs would be comparatively simpler, size changes might be the hardest part to deal with?
@ccll

This comment has been minimized.

ccll commented Jul 11, 2018

@isaachier Thanks, that article is very helpful!
I can see it passes a DLL-specific 'game_state' around, but what if the layout of 'game_state' got changed between reloads? I can imagine there will be lots of crashes/segfaults/misbehavior.

Now i've integrated C live coding successfully with libtcc, which hot-swap pure code flawlessly.

About the state transition, I can think of a solution which serialize the state out (to a layout-agnostic format), allocate new state, then serialize in. It should work, but involves a lot of manual implementation of serializing code and is not very generic/automatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment