Skip to content

Conversation

ysbaddaden
Copy link
Contributor

The resumable property of fiber contexts was wrong in interpreted code: it was never reset to 0.

This patch lets the interpreted fiber read the resumable property of the interpreter's fiber (the real one) though a new primitive. The interpreter is now responsible from reporting the value properly. This avoids having to manipulate resumable in the interpreted code, and allows to act on the actual state.

Alternative: the interpreter could set the resumable properties of the fibers in the interpreter_swapcontext primitive, it would be fake but probably not critical (the interpreter's scheduler would still act on the real property), but we don't have references back into the interpreted fibers (we could add it when interpreted) + I don't know how the interpreter updates values into an interpreted type (I could learn).

Fibers in the interpreted code are backed by real fibers run by the
interpreter. The fiber context is thus fake in the interpreted code, and
the resumable property should directly target the real fiber's context.

Also explains why we call `Fiber#resume`.
Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have a test that should break in the current HEAD but work with this patch?

@Blacksmoke16 Blacksmoke16 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:concurrency topic:compiler:interpreter labels Jan 23, 2024
The spec fails with the interpreter for the current crystal (1.11), but
succeeds with this patch (or when compiled with any older version).
Copy link
Contributor

@Sija Sija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick

@ysbaddaden
Copy link
Contributor Author

@beta-ziliani I just added a test. It fails with the interpreter of crystal 1.11 but succeeds otherwise (this patch, or when compiled).

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
@beta-ziliani beta-ziliani added this to the 1.12.0 milestone Jan 30, 2024
@straight-shoota straight-shoota merged commit 14f69e3 into crystal-lang:master Jan 31, 2024
@ysbaddaden ysbaddaden deleted the fix/set-resumable-in-interpreter-swapcontext branch February 1, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter topic:stdlib:concurrency

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants