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

[ractor] shareable_constant_value: literal makes constants shareable between ractors #892

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions language/fixtures/shareable_constant_value_magic_comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# shareable_constant_value: literal

A = [1, 2]
H = {a: "a"}

Ractor.new do
A
H
en.take
josacar marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions language/ractor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require_relative '../spec_helper'

describe "Magic comments" do
josacar marked this conversation as resolved.
Show resolved Hide resolved
ruby_version_is "3.0" do
it 'makes constants shareable between ractors' do
-> { ruby_exe(fixture(__FILE__, 'shareable_constant_value_magic_comment.rb'), options: '-W0')}.should_not raise_error
josacar marked this conversation as resolved.
Show resolved Hide resolved
end

it 'makes constants shareable between ractors' do
a, b, c = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
josacar marked this conversation as resolved.
Show resolved Hide resolved
# shareable_constant_value: experimental_everything
A = [[1]]
# shareable_constant_value: none
B = [[2]]
# shareable_constant_value: literal
C = [["shareable", "constant#{nil}"]]
[A, B, C]
end;
Ractor.shareable?(a).should == true
Ractor.shareable?(b).should == false
Ractor.shareable?(c).should == true
end

it 'raises an error whenn shared constant is not a literal' do
josacar marked this conversation as resolved.
Show resolved Hide resolved
-> { Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}", /unshareable expression/) }.should raise_error
josacar marked this conversation as resolved.
Show resolved Hide resolved
begin;
# shareable_constant_value: literal
C = ["Not " + "shareable"]
end;
end
end
end