On 10/7/2017 at 11:45 AM, suliman said:
Strange thing is sometimes it allows me to change something like that. What am I missing? I really like this feature and want it to work!
The trick is understanding what can be changed while running and what cannot.
Internally the magic works by hot-swapping out parts of a function body which is done by a little padding secretly added by the compiler when the code is built. That is the key to remember. Over time you can figure out what items inside a function body can be swapped out and and what cannot.
Internally on each function the compiler adds a little padding, then it replaces or modifies the padding with one of several options to accommodate your change. Maybe it will a jump to a new location for the hot-swapped code, returning back to the end of the padding when finished, or use it for space for your new variables, or maybe some other options depending on your change.
You cannot make changes that are outside a function body, like adding or removing a function, adding a global variable, or modifying a signature such as changing parameters the function takes. Essentially these are adding a completely new item so there is no existing padding to modify.
You can add some variables inside a function body, but anything more than fundamental types that the compiler understands has a risk of having issues. Also the amount of space to hot-swap in a function is limited, you can only add a small number of stack-allocated objects. The details has to do with how much padding was added to enable edit and continue to work, and how much padding is available to be used for those variables. If you're adding an object requiring 32 bytes and only 16 bytes of padding remain, you will need to recompile.
There are limits on changing functions that you're currently calling or inside of. If the system thinks you are modifying a function in the call stack, it probably won't let you. If you can cope with the side effects of the code you might be able to step out of the function, make the change, then move the instruction pointer back to the function to call it again.
You also can't make changes in code that is scattered rather than a single location. Functions that have been inlined, certain lambda uses, or template code that gets generated under the hood, these are not proper function bodies with little bits of padding around them. If they are scattered then the code can't be easily distributed. If they don't have the little block of padding they don't have the ability to be hot-swapped. Either way, those changes are out.
But if you follow the rules, only modify the internals of a function with new calls and limit the amount of new variables being created, it should work okay.
From what you described for your change, it doesn't look like that renumbering would modify the object type, so there is probably more than you included in your post that is critical. If the change did modify the type (and the compiler would know immediately if that was the case) then it would require changing a signature, and changing signatures is beyond the scope of the system.