From: "mame (Yusuke Endoh) via ruby-core" Date: 2023-03-07T14:31:21+00:00 Subject: [ruby-core:112719] [Ruby master Feature#19452] `Thread::Backtrace::Location` should have column information if possible. Issue #19452 has been updated by mame (Yusuke Endoh). @eregon Thank you for your comment. Eregon (Benoit Daloze) wrote in #note-5: > That would avoid the need to reparse, at the cost of having to store 2 extra uint32 "byte offsets" per call node. I think there is a confusion of what the word "reparse" means here. 1. When CRuby compiles a AST to a bytecode, it copies just node_id and lineno to each instruction but discards the column information. (@ko1 is not willing to copy column information due to memory consumption concerns.) So `RubyVM::AST.of` needs to "reparse" the whole source code to recover the whole AST. 2. CRuby's `RubyVM::AST` does not keep the column information of the method name because it converts the name to a symbol. It needs to "reparse" (or "re-tokenize"?) the code to identify where the method name is. Here I am talking about 1, which will not change even if YARP is introduced. If YARP's AST keeps the method name column information, 2 will be unnecessary, which is good. > I like the proposed API because it's straightforward. > I think it's also enough to identity which call it is, e.g. for `foo(1).bar(2).baz(3)`, i.e. it's always the rightmost call inside `first_column...last_columns`. > But that's indeed not as clear or obvious as underlining the operator + method name alone. This is somewhat a matter of taste, but since this is a user interface, I believe it is important to provide pinpoint information at a glance. So I think it is worthwhile to elaborate it, even if it is somewhat tedious. ---------------------------------------- Feature #19452: `Thread::Backtrace::Location` should have column information if possible. https://bugs.ruby-lang.org/issues/19452#change-102175 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- I discussed this with @mame and it would be pretty useful if we could also get the column information from exception backtrace location, even if it was slow. A POC: ```ruby class Thread::Backtrace::Location if defined?(RubyVM::AbstractSyntaxTree) def first_column RubyVM::AbstractSyntaxTree.of(self, keep_script_lines: true).first_column end else def first_column raise NotImplementedError end end end ``` It would be good to have a standard interface, so we follow the same interface as https://bugs.ruby-lang.org/issues/19451 and vice versa where it makes sense. I'll investigate it. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/