Project

General

Profile

Actions

Bug #17188

closed

Freeze Encoding objects for Ractor

Added by Eregon (Benoit Daloze) about 4 years ago. Updated about 4 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 3.0.0preview1 (2020-09-25 master 0096d2b895) [x86_64-linux]
[ruby-core:100148]

Description

Currently Encoding objects are not frozen:

$ ruby -ve 'p Encoding::US_ASCII.frozen?'
ruby 3.0.0dev (2020-09-25T08:28:42Z master 81dc37b1b4) [x86_64-linux]
false

That means they cannot be accessed in a Ractor:

irb(main):001:0> Encoding::US_ASCII
=> #<Encoding:US-ASCII>

irb(main):002:0> Ractor.new { Encoding::US_ASCII }
<internal:ractor>:38: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
=> #<Ractor:#2 (irb):2 running>
#<Thread:0x00005567521d81e8 run> terminated with exception (report_on_exception is true):
(irb):2:in `block in irb_binding': can not access non-sharable objects in constant Encoding::US_ASCII by non-main Ractor. (NameError)

And Ractor.new { p "".encoding } is likely violating the Ractor guarantees.

I think we can make all Encoding instances frozen.

Making them frozen is also useful for code sharing, which TruffleRuby aims to support via the GraalVM Engine/Context API.

cc @ko1 (Koichi Sasada)

Actions

Also available in: Atom PDF

Like0
Like0Like0