Issue #21795 has been updated by Eregon (Benoit Daloze). kddnewton (Kevin Newton) wrote in #note-23:
Unless you're once again suggesting we only rely on line/column, which as already mentioned multiple times and rejected multiple times, won't work.
Do you have a concrete example why it wouldn't work? As you said:
Arguing theoretically is not productive at this point.
So far there has only been theoretical examples of nodes overlapping being mentioned, which seems extremely unlikely to ever become a problem. OTOH I have demonstrated that `node_id` is problematic in real cases (when not exactly the same version). Regarding Rails or `error_highlight`, I looked and they both use `node_id_for_backtrace_location`. If we had start/end line/column for `Thread::Backtrace::Location` I believe that would be a great replacement for that. We should avoid increasing the memory footprint of the bytecode (i.e. not add 4 int's per call bytecode) but I have an idea for that: we can derive the start/end line/column from the `node_id` safely by having some C code using the interpreter parser to convert a node_id to that, and we can do the same with `RubyVM::AbstractSyntaxTree.of`/similar too, the one downside is we need to re-parse the file but it certainly seems worth it to lift the restriction of matching Prism ABI version, and working in `--parser=parse.y` mode too. ---------------------------------------- Feature #21795: Methods for retrieving ASTs https://bugs.ruby-lang.org/issues/21795#change-117129 * Author: kddnewton (Kevin Newton) * Status: Open ---------------------------------------- I would like to propose a handful of methods for retrieving ASTs from various objects that correspond to locations in code. This includes: * Proc#ast * Method#ast * UnboundMethod#ast * Thread::Backtrace::Location#ast * TracePoint#ast (on call/return events) The purpose of this is to make tooling easier to write and maintain. Specifically, this would be able to be used in irb, power_assert, error_highlight, and various other tools both in core and not that make use of source code. There have been many previous discussions of retrieving node_id, source_location, source, etc. All of these use cases are covered by returning the AST for some entity. In this case node_id becomes an implementation detail, invisible to the user. Source location can be derived from the information on the AST itself. Similarly, source can be derived from the AST. Internally, I do not think we have to store any more information than we already do (since we have node_id for the first four of these, it becomes rather trivial). For TracePoint we can have a larger discussion about it, but I think it should not be too much work. In terms of implementation, the only caveat I would put is that if the ISEQ were compiled through the old parser/compiler, this should return `nil`, as the node ids do not match up and we do not want to further propagate the RubyVM::AST API. The reason I am opening up this ticket with 5 different methods requested in it is to get approval first for the direction, then I can open individual tickets or just PRs for each method. I believe this feature would ease the maintenance burden of many core libraries, and unify otherwise disparate efforts to achieve the same thing. -- https://bugs.ruby-lang.org/