Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a type-aligned SplitSeq to store the continuation frames #3

Merged
merged 26 commits into from
Oct 12, 2024
Merged

Conversation

kyay10
Copy link
Owner

@kyay10 kyay10 commented Oct 12, 2024

Every item of such a sequence is either a mark (Reader/Prompt) or real stack frames (which are now only copied when absolutely necessary).
Technically, there's a one-shot core that can be extracted here that uses no reflection, but I'll leave that to the future.
This is based on java-effekt's implementation, but with added types, and explicit tail-rec-ness. I also added kotlin-specific optimizations here to "trampoline" resumptions into frames. That code should ideally be extracted into a smaller component.
Also, this implementation takes O(1) time for pushPrompt, O(k) time for takeSubCont, and O(k) time for pushSubCont, where k is the amount of marks from here to the relevant Prompt (so it's the amount of marks separating us from the Prompt in takeSubCont, and the amount of marks in the stored SubCont in pushSubCont). I doubt that takeSubCont can be made faster (unless we use a hashmap or something), but pushSubCont can definitely be made constant-time, although that'll make the code more complex (the likely way to do so is using the "Reflection without Remorse" technique of using a sequence that'll have amortized constant-time access to the "current" continuation frame, but IIRC this has horrible constants involved).
This also implements delayed copying for Reader's values.
This doesn't currently support a dynamic-wind style operation, also it hasn't needed to exist just yet.

kyay10 added 26 commits August 7, 2024 10:06
Change sentinel WrapperCont values to failures for type safety
Introduce *once and *withFinal methods for capturing continuations
Use UnconfinedTestDispatcher and SingleShotSegment for long tests
Inline WrapperContContext
Inline CanSuspend in FibersTest
Introduce fast aborting that doesn't use exceptions (was causing problems on JS)
Add more Skynet variations
Introduce cleaner deleteReader method for deleteBinding
@kyay10 kyay10 merged commit 486d0ef into main Oct 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant