Conversation
| Ractor.make_shareable(Racc_arg) if defined?(Ractor) | ||
|
|
||
| Racc_token_to_s_table = [ | ||
| "$end", |
There was a problem hiding this comment.
# shareable_constant_value: literal doesn't help?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I see. BTW it can be off only for auto-generated code.
# shareable_constant_value: literal
...generated code...
# shareable_constant_value: none
...user code...There was a problem hiding this comment.
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?
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