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
Exception#set_backtrace
accept arrays of Backtrace::Location
#10017
Conversation
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.
Looks reasonable to me.
NOTE: Exception's instance variables id_bt and id_bt_locations are a bit inconsistent right now and would deserve a cleanup.
Agree this could use some love. Why do we even have both given that exc_backtrace
seems happy enough for either strings or Thread::Backtrace::Location
s to be in id_bt
?
vm_backtrace.c
Outdated
RB_GC_GUARD(locobj); | ||
} | ||
|
||
RB_GC_GUARD(btobj); |
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 think it's unnecessary to guard this if you're returning it since btobj
obviously must either be in the stack or register state for the entirety of this frame since it's being returned?
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.
Yeah, I started to be a bit liberal with GC_GUARD
...
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 more I learn about how compilers work the more scared I am that on day some compiler will do something really clever like store a pointer to the middle of a struct in a register, rather than the actual VALUE, and break everything :/
I wonder if anybody has tried compiling Ruby with LTO, maybe aggressive enough cross-TU inlining could make this happen…
Yeah, that surprised me as well, I'd need to do some spelunking to see when it was introduced. |
3be24b7
to
b25eb28
Compare
So I dug a bit more into this since various Exceptions and Marshal related tests were failing. I used the following test script:
So it's a bit weird, but This would be hard to cleanup because a bunch of test asserts on the Marshal format of Exception, so changing the type of either ivar would break backward compatibility. And in the end leaning into that format, really cut the PR size, so... |
b25eb28
to
2a12e1e
Compare
Try on Playground: https://ruby.github.io/play-ruby?run=8278867369 |
def foo
raise
end
begin
foo
rescue => e
e.set_backtrace(caller_locations + [""])
end
=begin
-e:8:in 'Exception#set_backtrace': wrong argument type String (expected frame_info) (TypeError)
e.set_backtrace(caller_locations + [""])
^^^^^^^^^^^^^^^^^^^^^^^
from -e:8:in '<main>'
from -e:5:in '<main>'
-e:2:in 'Object#foo': unhandled exception
from -e:6:in '<main>'
=end
----
def foo
raise
end
begin
foo
rescue => e
e.set_backtrace([""] + caller_locations)
end
=begin
-e:8:in 'Exception#set_backtrace': backtrace must be an Array of String or an Array of Thread::Backtrace::Location (TypeError)
e.set_backtrace([""] + caller_locations)
^^^^^^^^^^^^^^^^^^^^^^^
from -e:8:in '<main>'
from -e:5:in '<main>'
-e:2:in 'Object#foo': unhandled exception
from -e:6:in '<main>'
=end can we make them same error?
|
I think so, I'll try. |
0612524
to
2d9f192
Compare
Alright, the error message is now consistent. I'll merge when CI pass. |
[Feature #13557] Setting the backtrace with an array of strings is lossy. The resulting exception will return nil on `#backtrace_locations`. By accepting an array of `Backtrace::Location` instance, we can rebuild a `Backtrace` instance and have a fully functioning Exception. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com>
Head branch was pushed to by a user without write access
2d9f192
to
904e0f2
Compare
Could you modify docs and maybe NEWS? |
Followup: ruby#10017 [Feature #13557]
Of course: #10255 Let me know what you think. |
Followup: ruby#10017 [Feature #13557]
Followup: #10017 [Feature #13557]
Followup: ruby/ruby#10017 [Feature #13557]
Followup: ruby#10017 [Feature #13557]
[Feature #13557]
Setting the backtrace with an array of strings is lossy. The resulting exception will return nil on
#backtrace_locations
.By accepting an array of
Backtrace::Location
instance, we can rebuild aBacktrace
instance and have a fully functioning Exception.NOTE: Exception's instance variablesid_bt
andid_bt_locations
are a bit inconsistent right now and would deserve a cleanup.