-
Notifications
You must be signed in to change notification settings - Fork 13
Show chain of references in Ractor errors #935
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
base: master
Are you sure you want to change the base?
Show chain of references in Ractor errors #935
Conversation
d37bed4 to
89a62f7
Compare
vm.c
Outdated
| !RB_OBJ_SHAREABLE_P(block_self)) { | ||
| if (!rb_ractor_shareable_p_continue(block_self, chain)) { | ||
| if (chain) { | ||
| if (NIL_P(*chain)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we duplicating the chain_append logic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what's the best way to share code here. Should I make the function non-static, prefix it somehow and add it to "ractor_core.h"?
vm.c
Outdated
| "Proc's self is not shareable: %" PRIsVALUE, | ||
| self); | ||
| if (chain) { | ||
| if (NIL_P(*chain)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here?
| " from block self #<Foo @ivar={}>\n" \ | ||
| " from hash default value\n" \ | ||
| " from instance variable @ivar\n" \ | ||
| " from instance variable @foo", %q{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The chain approach makes sense to me, but I'm finding the error message a little hard to parse - it's not immediately obvious to me from the message what objects the ivars are attached to, or where the hash values are coming from. Is it worth using rb_inspect or rb_obj_as_string here or is the performance an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a performance issue, it's more that the output gets really messy really fast.
Even in the simple case of just instance variables, it will cause a huge wall of text with a lot of repetition:
class A; attr_accessor :b; end
class B; attr_accessor :c; end
class C; attr_accessor :d; end
class D; attr_accessor :e; end
a = A.new
a.b = b = B.new
b.c = c = C.new
c.d = d = D.new
d.e = ->{}
Ractor.make_shareable a../../test.rb:12:in 'Ractor.make_shareable': Proc's self is not shareable: #<Proc:0x0000000103731150 ../../test.rb:10 (lambda)> (Ractor::IsolationError)
from block self main
from instance variable @e of #<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>
from instance variable @d of #<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>
from instance variable @c of #<B:0x00000001037313f0 @c=#<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>>
from instance variable @b of #<A:0x00000001037314b0 @b=#<B:0x00000001037313f0 @c=#<C:0x0000000103731300 @d=#<D:0x0000000103731210 @e=#<Proc:0x0000000103731150 ../../test.rb:10 (lambda)>>>>>
from ../../test.rb:12:in '<main>'My first approach always had the object under consideration in addition to the "reference" and it wasn't super readable.
Using this branch I've noticed I usually just need the last line anyway.
Improve the messages of exceptions raised by the Ractor implementation. When an object fails to be made shareable with `Ractor.make_shareable` or when an unshareable object is accessed through module constants or module instance variables, the error message now includes the chain of references that leads to the unshareable value.
89a62f7 to
2e55ee7
Compare
Improve the messages of exceptions raised by the Ractor implementation.
When an object fails to be made shareable with
Ractor.make_shareableor when an unshareable object is accessed through module constants or module instance variables, the error message now includes the chain of references that leads to the unshareable value.