salmanahmad / silo

The Silo Programming Language
0 stars 0 forks source link

Exception Handling with Fibers + Actor Migration #9

Open salmanahmad opened 10 years ago

salmanahmad commented 10 years ago

If a resumed Fiber throws an exception that function that catches the exception will not have the local variables initialized correctly and will also not clear the relevant execution frames to prevent replaying the execution over and over again.

The first step is easy - inside all catch blocks I should emit code that re-sets the local variables if the ExecutionContext has a status of THROWING (as opposed to RUNNING or YIELDING).

The second step is much harder - how do I invalidate all of the ExecutionFrames? I need a mechanism that allows me to determine which ExecutionFrame belongs to the current function, find it, and then remove all ExecutionFrames on-top of it. One idea is to embed an interned string with the fully qualified name of the function. I then call a utility method that iterates through the ExecutionFrames in reverse and returns the first frame that matches the fully qualified name. It then "nulls" out the rest.

salmanahmad commented 10 years ago

Another example is with actor thread migrations:

    try({
        actor.lockThread()
        someJavaNativeCallThatDoesBlockingIO()
    } finally {
        actor.unlockThread()
    })
salmanahmad commented 10 years ago

Instead of embedding an interned string with the fully qualified name of the function, Can I just ignore it and carry on? The frames array in the ExecutionContext will hold data but it will just be overwritten eventually, wouldn't it?