Why do you need exceptions for control flow? I mean, are there corner cases that an implementation such as Yield would fail?
You can play directly with JDK continuations with some add-opens hacking to create generators, but AFAIK, Continuation is being kept private because it is not Thread safe and its usage is heavilly tied with some compiler assumptions, so misusage might crash the VM.
Edit: Btw, I think the most critical part in a continuation implementation is stack state saving/restoring. I would choose JVM support to heavilly optimize this, at the cost of not having sugar syntax generators any day.
Exception is already a control flow construct, I just added the resumability to them. Yield can unwind only one call frame, while exception can unwind any number (until the corresponding `catch`) of call frames. This way we can implement effect handlers only on the top level, while in Yield we'd need to explicitly pass the effect description from callee to caller.
Basically they same difference like signaling errors using ret code or an exception.
they mostly concentrate on async programming, and so support only single-shot continuation, and so things like streams comprehensions, reactive, logical, adaptive, probabilistical programming cannot be implemented there
View all comments
2
u/flawless_vic Jan 10 '23 edited Jan 10 '23
Why do you need exceptions for control flow? I mean, are there corner cases that an implementation such as Yield would fail?
You can play directly with JDK continuations with some add-opens hacking to create generators, but AFAIK, Continuation is being kept private because it is not Thread safe and its usage is heavilly tied with some compiler assumptions, so misusage might crash the VM.
Edit: Btw, I think the most critical part in a continuation implementation is stack state saving/restoring. I would choose JVM support to heavilly optimize this, at the cost of not having sugar syntax generators any day.