-
Notifications
You must be signed in to change notification settings - Fork 68
Do not initialize caml_parent_stack in caml_interprete #30
Conversation
If caml_parent_stack was reset to NULL, then the link between parent and child fiber is severed if the child performs a C call which in turn calls back into OCaml.
Did you leave out the link "[1]"? I don't see it. [edited comment, what I wrote didn't make much sense] Does your example attempt to perform an effect from within a callback to a handler outside the callback, or use a handler entirely within the callback? |
Do not initialize caml_parent_stack in caml_interprete
Sorry. Edited the comment to include [1]. Example performs callback from within a handler with a callback outside the handler. Specifically, there are intervening C frames. Do you think it is not possible to provide sensible semantics for |
Ah, right. No, I think the original behaviour was more correct. In this example, there is a sensible semantics for the effect, but that's because the effect is so simple - it's essentially a function call. If the effect handler chose to capture the continuation, there's nothing useful we can do. For instance, if the effect handler captured the continuation, and then ran another fiber which also did C calls and performed a similar effect, and then tried to reinstate the first continuation, we'd be left trying to move C stack frames around (which doesn't work, as C coders fill datastructures with pointers to their stack). I think we should give a better error message than "Unhandled", though - we don't know whether there's a handler or not, but we give up searching because of a C frame in the way. |
Yes, breaking the parent chain in the original code was deliberate since we cannot capture C stack frames. I also think that raising Unhandled is the correct behaviour. The semantics of calling into the OCaml runtime from C are to run the OCaml call in its own context with no existing effect (or exception) handlers in place. So an effect performed within such a call should perform its default action (which is currently always raising Unhandled). |
Right. I agree. This merge should be reverted. Regarding the more sane error message, I think this problem case can be distinguished from typical unhandled effect by the fact that the |
In the current implementation that appears to be true for effects, but not for exceptions. |
On Thu, Oct 1, 2015 at 11:34 AM, yallop notifications@github.com wrote:
To make effects work, C callbacks would have to handle the possibility of I really think this should be a separate error from "Unhandled", to avoid |
I thought exceptions raised in the callback were returned to the calling C specially (by setting the second bit). |
The problem is if there is a sensible default action (for example using blocking read for all the basic read operations) then it really should be executed in this case. If we don't do that then we can't change the Stdlib to use effects as it will destroy backwards compatibility. And I am very reluctant to special-case the "default default". |
Oh I see. I had |
Actually, I think we could manage a better message. Once we allow people to set their own default handler then we really don't want to encourage catching |
I like Unhandled of string. We can also shove in the name of the effect,
|
Rebalance the clocking of the major_gc for sweeping
If caml_parent_stack was reset to NULL, then the link between parent and child fiber is severed if the child performs a C call which in turn calls back into OCaml. See the example here [1]. Build the example as
make COMP=MULTI
. With the fix you should see:and without it:
[1] https://github.com/kayceesrk/ocaml-eff-example/tree/master/callbacks
[edit: Added missing link]