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

Add Ractor support #57

Merged
merged 2 commits into from
Jan 15, 2025
Merged

Add Ractor support #57

merged 2 commits into from
Jan 15, 2025

Conversation

wanabe
Copy link
Contributor

@wanabe wanabe commented Jan 15, 2025

Hello,

I added some changes to ruby/erb to support Ractor.

  • Make ERB::NOT_GIVEN ractor-shareable
  • Make @scanner_map of ERB::Compiler::Scanner ractor-shareable

And I confirmed that:

  • It doesn't affect to ERB's behavior with ruby-2.7.0
  • It allows us to call ERB.new and ERB#result in Ractor with ruby >= 3.1.0
  • It can't allow us call ERB#result with ruby-3.0.x unfortunately
    • Because of the specification of Ractor on ruby-3.0.x:
      • "can not access instance variables of classes/modules from non-main Ractors"
$ for e in ALL_RUBY_BINS='ruby-2.5.0 ruby-2.6.0 ruby-2.7.0' ALL_RUBY_SINCE=ruby-3.0.0; do docker run -it -v .:/erb --rm rubylang/all-ruby env "$e" ./all-ruby -I/erb/lib -W0 -e 'begin; require "erb"; p [ERB.new("<%= 1 + 2 %>").result, defined?(Ractor) && Ractor.new { ERB.new("<%= 3 + 4 %>").result(binding) rescue [$!, $@[0]] }.take]; rescue; p $!; end'; done
ruby-2.5.0 #<NoMethodError: undefined method `resolve_feature_path' for #<Array:0x00005615de7f43e8>>
ruby-2.6.0 #<NoMethodError: undefined method `resolve_feature_path' for #<Array:0x000055faf5283390>>
ruby-2.7.0 ["3", nil]
ruby-3.0.0          ["3", [#<Ractor::IsolationError: can not access instance variables of classes/modules from non-main Ractors>, "/erb/lib/erb/compiler.rb:102:in `make_scanner'"]]
...
ruby-3.0.7          ["3", [#<Ractor::IsolationError: can not access instance variables of classes/modules from non-main Ractors>, "/erb/lib/erb/compiler.rb:102:in `make_scanner'"]]
ruby-3.1.0-preview1 ["3", "7"]
...
ruby-3.4.1          ["3", "7"]

Copy link
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

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

👌

@k0kubun k0kubun merged commit 12d69fc into ruby:master Jan 15, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants