Skip to content

Conversation

@pocke
Copy link
Member

@pocke pocke commented Sep 13, 2021

This PR makes a parser that is generated by Racc Ractor compatible.

I've tested this patch works well on parser gem with a patch for parser gem. patch: https://gist.github.com/pocke/dca4bf45d0b3a82ddf86689943ad341d

Ractor.make_shareable(Racc_arg) if defined?(Ractor)

Racc_token_to_s_table = [
"$end",
Copy link
Contributor

Choose a reason for hiding this comment

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

# shareable_constant_value: literal doesn't help?

Copy link
Member Author

@pocke pocke Sep 14, 2021

Choose a reason for hiding this comment

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

Ah, I forgot the magic comment, Thanks for the comment.

I suppose Ractor.make_shareable is more appropriate than the comment.
The generated code includes user-written code, so # shareable_constant_value: literal will change the user-written literals. It may introduce breaking changes unexpectedly.

Racc_ constants are Racc internal constants so we can freeze them safely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. BTW it can be off only for auto-generated code.

# shareable_constant_value: literal
...generated code...
# shareable_constant_value: none
...user code...

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool 👍
I tried the magic comment but unfortunately I had two problems with it so we couldn't use the magic comment 😢

First, a constant does not consist of literals. Racc_arg contains lvars. It raises Ractor::IsolationError on the const assignment.

Second, the generated code is sandwiched by user code.

...user code (inner)...
...generated code...
...user code (actions)...

If the inner has the magic comment, the behavior will be changed by generated magic comment. For example:

...user code (inner)...
# shareable_constant_value: literal

# shareable_constant_value: literal
...generated code...
# shareable_constant_value: none

...user code (actions)...
# The user expects `shareable_constant_value: literal` here, but doesn't.

I guess we can solve the first problem with experimental_everything but it is experimental, and we don't have any way to solve the second problem. So I think Ractor.make_shareable is reasonable at least for now. WDYT?

@hsbt hsbt merged commit 380bd78 into ruby:master Jan 11, 2023
@pocke pocke deleted the Make_racc_Ractor_compatible branch January 11, 2023 08:34
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.

3 participants