getkyo / kyo

Toolkit for Scala Development
https://getkyo.io
Apache License 2.0
481 stars 38 forks source link

prelude: safepoint interceptors #504

Closed fwbrasil closed 5 days ago

fwbrasil commented 6 days ago

I'm working on providing a way to customize Safepoint with additional enter and exit implementations. The mechanism will be used for preemption in fibers but it can be easily extended to provide other features like profiling and debugging. This PR propagates the current value of the computation alongside its frame to Safepoint.enter as preparation. This will allow a custom enter to also inspect the current value. The main use case would be a Debug effect that also presents values that appear during execution.

Edit: I've pushed a commit with the new interceptor mechanism. Safepoint.immediate will be used by fibers to preempt execution in evaluation loop (suspension is managed by the fiber itself) and Safepoint.propagating provides similar functionality but ensuring propagation across suspensions.