This allows for one to take quicker backtraces if they need less information, additionally BacktraceInfo::Bindings and BacktraceInfo::Klass could be added which allow you to gather more information for heavy profiling / diagnostics.
This allows for one to take quicker backtraces if they need less information, additionally BacktraceInfo::Bindings and BacktraceInfo::Klass could be added which allow you to gather more information for heavy profiling / diagnostics.
I want to reject to get bindings and klasses with this API.
As a debugging feature I can support access to arbitrary bindings. As a general, runtime, hot-path feature, there's numerous reasons why it's a terrible idea:
It exposes all method-local state to everyone. Any library anywhere can not only access your local variables but modify them too. A potentially massive security hole.
It requires that all method bodies everywhere in the system maintain all frame/scope state regardless of whether it's used or not, since "Binding.of_caller" style features could access it at any time.
It drastically limits optimization potential for Ruby. On a good day, JRuby can be 10x or more faster than MRI largely because we've been able to eliminate framing/scoping overhead. A Binding.of_caller feature would severely damage our performance and very likely limit forever general Ruby performance.
=begin
Why not introduce a (({$DEBUG})) variable that tells the runtime to enable introspective features like this at the cost of performance? I would love for better_errors to run on JRuby, but at the moment it can't since JRuby leans too far towards the performance side of the argument and there's no way to tell it to disregard performance in favour of debuggability.
A flag that's enabled at runtime would not really work, since optimizations might already have happened. There needs to be a way to specify that optimizations should be off. In JRuby, the simplest way to do that is to turn off the compiler by passing -X-C to JRuby. In that case, all code will remain interpreted with full bindings available at every ruby level of the stack (we do not provide bindings for native methods). Implementing Binding.of_caller in that scenario would be pretty simple.
JRuby currently has a --debug flag that turns on things like trace functions. It might be reasonable for it to turn on full bindings as well, though it would definitely have a major perf impact.