From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-03-09T20:57:43+00:00 Subject: [ruby-core:112805] [Ruby master Feature#19452] `Thread::Backtrace::Location` should have column information if possible. Issue #19452 has been updated by Eregon (Benoit Daloze). mame (Yusuke Endoh) wrote in #note-6: > I think there is a confusion of what the word "reparse" means here. I meant it as `1.` as well. I think copying/keeping the column information is the most reliable way to have this information. Indeed it should be encoded efficiently to avoid too much of a memory increase. I think we should measure, e.g. by how much % does it increase the memory of a Ruby program and a Rails app? I suspect it's not much higher than keeping the node id. In fact if we assumed e.g. no call expression is longer than 2^16 bytes long, we could fit 2 column offsets (from the start of the call) in 32-bit. Or even 4 column offsets if we need more, and then have some fallback encoding if longer than 256 (likely rare) or so. I don't know what CRuby uses currently to keep line information though. > I think it is possible to use four values of first_lineno, etc. as information to connect Thread::Backtrace::Location and AST node. I think this makes sense, although it's even better if we don't need to reparse to find out column information. It's probably more efficient to internally have the first_byteoffset and last_byteoffset, that's just two 32-bit integers and we can derive {first,last}_{lineno,column} from it. It's also how YARP records locations. ---------------------------------------- Feature #19452: `Thread::Backtrace::Location` should have column information if possible. https://bugs.ruby-lang.org/issues/19452#change-102307 * 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/