* [ruby-core:100148] [Ruby master Feature#17188] Freeze Encoding objects for Ractor
@ 2020-09-25 14:31 eregontp
2020-10-07 16:02 ` [ruby-core:100331] [Ruby master Bug#17188] " eregontp
0 siblings, 1 reply; 2+ messages in thread
From: eregontp @ 2020-09-25 14:31 UTC (permalink / raw)
To: ruby-core
Issue #17188 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Feature #17188: Freeze Encoding objects for Ractor
https://bugs.ruby-lang.org/issues/17188
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Target version: 3.0
----------------------------------------
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:
```ruby
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
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:100331] [Ruby master Bug#17188] Freeze Encoding objects for Ractor
2020-09-25 14:31 [ruby-core:100148] [Ruby master Feature#17188] Freeze Encoding objects for Ractor eregontp
@ 2020-10-07 16:02 ` eregontp
0 siblings, 0 replies; 2+ messages in thread
From: eregontp @ 2020-10-07 16:02 UTC (permalink / raw)
To: ruby-core
Issue #17188 has been updated by Eregon (Benoit Daloze).
Backport set to 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
ruby -v set to ruby 3.0.0preview1 (2020-09-25 master 0096d2b895) [x86_64-linux]
Assignee set to ko1 (Koichi Sasada)
Tracker changed from Feature to Bug
Changing this to a bug, because it can cause unsafe sharing:
```ruby
irb(main):003:0> Encoding::UTF_8.instance_variable_set(:@foo, Object.new)
=> #<Object:0x00005596506b8a28>
irb(main):004:0> Ractor.new { p "b".encoding.instance_variable_get("@foo") }
#<Object:0x00005596506b8a28>
```
----------------------------------------
Bug #17188: Freeze Encoding objects for Ractor
https://bugs.ruby-lang.org/issues/17188#change-87907
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 3.0
* ruby -v: ruby 3.0.0preview1 (2020-09-25 master 0096d2b895) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
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:
```ruby
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
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-10-07 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 14:31 [ruby-core:100148] [Ruby master Feature#17188] Freeze Encoding objects for Ractor eregontp
2020-10-07 16:02 ` [ruby-core:100331] [Ruby master Bug#17188] " eregontp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).