ciao icon indicating copy to clipboard operation
ciao copied to clipboard

(playground) Aborts cause state loss.

Open Jean-Luc-Picard-2021 opened this issue 2 years ago • 6 comments

Hi,

Not sure whether this ticket is redundant to "(ciaowasm) make '$yield'/0 interact with JS async" what is seen in the commits?

There is some state loss in manual abort:

?- assertz(foo).
yes

?- foo.
yes

?- repeat, fail.
{ Execution aborted }

?- foo.
{ERROR: No handle found for thrown exception error(
existence_error(procedure,'user:foo'/0),'user:foo'/0)}
aborted

And in timeout:

?- assertz(foo).
yes

?- repeat, fail.
{ABORTED: Time limit exceeded.}

?- foo.
{ERROR: No handle found for thrown exception error(
existence_error(procedure,'user:foo'/0),'user:foo'/0)}
aborted

https://ciao-lang.org/playground/

Expectation would be rather that this doesn't happen.

Jean-Luc-Picard-2021 avatar Aug 05 '22 10:08 Jean-Luc-Picard-2021

Thank you. This is a known limitation similar to blocking IO. Timeouts are hard without asyncify or shared array buffers because there is no way for the executing thread to know that it has been asked to abort. Asyncify should be able but we've not measured the performance impact yet. Right now aborts restart the engine.

jfmc avatar Aug 05 '22 11:08 jfmc

Works in Jan W prototype, but his prototype is still a little slow.

https://dev.swi-prolog.org/wasm/shell

?- assertz(foo).
true.

?- foo.
true.

?- repeat, fail.
ERROR: Execution Aborted

?- foo.
true.

The version I am reporting uses a setTimout() driven auto yielding loop. Through setTimeout() you give the browser the chance to work its task queues, it will do all kind of stuff, in the above

example the browser stays responsive during repeat, fail, please try it, it does all that without a Worker. I guess this is a nice first proof of concept and one of the goals of this work.

Jean-Luc-Picard-2021 avatar Aug 08 '22 17:08 Jean-Luc-Picard-2021

You also see here that it doesn’t have any Workers, there is no Threads tab in the debugger. But interesting find, SWIPL itself got promisified, and the very first next() call goes through toplevel():

2f6e0188abff96c680da7a91d0af4f29fc849c62

Jean-Luc-Picard-2021 avatar Aug 08 '22 18:08 Jean-Luc-Picard-2021

Thanks. Sorry, I was confused with the long thread at SWI discourse. We'll try automatic yield but if there is some serious impact on performance, we will consider also other options (maybe optionally). For some workers losing the state is not an issue.

jfmc avatar Aug 08 '22 19:08 jfmc

Now Jan W prototype got faster, but I don't have yet a live link to share.

Jean-Luc-Picard-2021 avatar Aug 08 '22 20:08 Jean-Luc-Picard-2021

Not fixed yet.

jfmc avatar Jul 29 '23 14:07 jfmc