From: "rkh (Konstantin Haase) via ruby-core" Date: 2026-11-06T11:21:27+00:00 Subject: [ruby-core:127346] [Ruby Feature#22444] Ractor.new should use Ractor.shareable_proc semantics for the block Issue #22444 has been updated by rkh (Konstantin Haase). Eregon (Benoit Daloze) wrote in #note-4: > Nice and agreed, this seems far more convenient and already envisioned in #21557. > > Maybe we should do the same for `define_method`, but just fallback to current behavior if not possible to make the block shareable (clearly not for this ticket though). I think this would be great, especially for making it easier for existing libraries to become Ractor compatible. ---------------------------------------- Feature #22444: Ractor.new should use Ractor.shareable_proc semantics for the block https://bugs.ruby-lang.org/issues/22444#change-119779 * Author: jhawthorn (John Hawthorn) * Status: Closed ---------------------------------------- #21557 introduced very well considered rules for `Ractor.shareable_proc`, where locals can be referenced so long as they are shareable and never reassigned. However `Ractor.new { ... }` continues to use a more restrictive rule that no local variable access is allowed at all. I'd like to propose that `Ractor.new` follow the same rules as `Ractor.shareable_proc`. This simplifies implementation, and should be simpler for users both because of what it allows and because of consistency. ```ruby outer_var = :ok Ractor.new { puts outer_var }.join # raise on 4.0, I propose we allow this Ractor.new(outer_var) { |inner_var| puts inner_var }.join # old way to do this, still works # This doesn't add any new abilities, as one could already emulate this with the following on 4.0 pr = Ractor.shareable_proc { puts outer_var } # allowed, because no reassignment to outer_var Ractor.new(pr){ |pr| pr.call }.join # allowed, because pr is shareable unshareable = Object.new reassigned = :bad Ractor.new { puts unshareable }.join # still raises because unshareable Ractor.new { puts reassigned }.join # still raises due to reassignment reassigned = :still_bad ``` `self` continues to be the new `Ractor` object. One additional change here is that previously the proc passed to `Ractor.new(&some_proc)` would actually be mutated to be shareable. I don't think this was intentional and we should remove this behaviour. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/