Uh oh!
There was an error while loading. Please reload this page.
Allow use of DelegateClass in ractors - #49
Conversation
f2b2c0d to
81ea986CompareTempfile uses DelegateClass and Tempfile should be able to be used by different ractors.
81ea986 to
cad1942Compareluke-gru
commented
Dec 16, 2025
I would like to get this in before ruby 4 release please 🙏 |
Uh oh!
There was an error while loading. Please reload this page.
This causes ruby 4.0 CI to crash.
I claim this should be reverted, if no other rationale. (#52) |
hsbt
commented
Dec 17, 2025
@luke-gru Can you describe what is the use-case of this? I'm wondering this is for your project of something. |
luke-gruber
commented
Dec 17, 2025
The use case is to be able to call I will look into the assertion failure in CI. |
Conclusion: I think it is hard to introduce it now because of essential problem. small repro code: classCdefine_method:gets, &(Ractor.shareable_procdoFile.open("/tmp/foo").gets# $_ is assignedend)endC.new.getsGC.verify_internal_consistencyThe problem is svar (storage of Some possibilities: |
luke-gruber
commented
Dec 17, 2025
Thank you for looking into this. That makes sense, I didn't realize this |
ko1
commented
Dec 17, 2025
For diff --git a/lib/delegate.rb b/lib/delegate.rb
index 838de675f1..79b039af48 100644
--- a/lib/delegate.rb+++ b/lib/delegate.rb@@ -344,11 +344,13 @@ def __setobj__(obj)
end
end
-def Delegator.delegating_block(mid) # :nodoc:- lambda do |*args, &block|+def Delegator.delegating_code(mid)+ <<~RUBY+ def #{mid}(*args, &block)
target = self.__getobj__
- target.__send__(mid, *args, &block)- end.ruby2_keywords+ target.__send__(:'#{mid}', *args, &block)+ end+ RUBY
end
#
@@ -412,11 +414,11 @@ def __setobj__(obj) # :nodoc:
@delegate_dc_obj = obj
end
protected_instance_methods.each do |method|
- define_method(method, Delegator.delegating_block(method))+ eval Delegator.delegating_code(method)
protected method
end
public_instance_methods.each do |method|
- define_method(method, Delegator.delegating_block(method))+ eval Delegator.delegating_code(method)
end
end
klass.define_singleton_method :public_instance_methods do |all=true| |
luke-gruber
commented
Dec 17, 2025
I have made another PR for review after this one gets reverted with the suggestions from ko1. |
eregon
commented
Dec 17, 2025
This is basically what TruffleRuby already does, the svars are never shared across Threads and not even across Fibers, they are always Fiber-local conceptually. And it can still be optimized for the common case of only a single Fiber accessing the svar during a method call. |
Tempfile uses DelegateClass and Tempfile should be able to be used by different ractors.