trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
268 stars 13 forks source link

pl_yield_at fixes #570

Closed guregu closed 2 months ago

guregu commented 2 months ago

(Fixes #569)

Background: pl_yield_at is used by the JS port to periodically yield to the main thread, this prevents the browser UI locking up. Previously, this caused the last goal executed before yielding to be run twice, and I think also potentially succeeding when it should have failed. This could cause the JSON-based toplevel to become corrupt among other things.

This PR tweaks it so that the goal is only run once, and a matching succeed or fail choice point can be resumed from. I ran these changes overnight and tested it against some previously flaky cases I had lying around, and it looks good now. I'm happy to finally figure out what was going on with that.

Also reverts some stuff that is not needed anymore discussed in #569. Feel free to rename this stuff, couldn't think of a good function name.