From: "mame (Yusuke Endoh) via ruby-core" Date: 2024-02-14T11:47:34+00:00 Subject: [ruby-core:116743] [Ruby master Misc#20260] ISEQ flag for prism compiler Issue #20260 has been updated by mame (Yusuke Endoh). How about the following API? * Make `RubyVM::AbstractSyntaxTree.of` raise a RuntimeError for objects with iseq complied from Prism. * Introduce `Thread::Backtrace::Location#node_id`, which returns node_id at the current instruction, regardless of compiled from parse.y or Prism. ```ruby begin node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) Spotter.new(node, **opt).spot rescue RuntimeError if $!.message =~ /prism/ node = Prism.parse(loc.path).node_for(loc.node_id) PrismSpotter.new(node, **opt).spot else raise end end ``` The rationale of this API design is as follows. In principle, we don't want to introduce a temporal method outside of RubyVM that will be useless in the near future. `Location#prism?` will become useless when Prism becomes Ruby's parser successfully. `Ruby VM::InstructionSequence.complied_by_prism?(loc)` is a possible option. However, we need to make `RubyVM::AbstractSyntaxTree.of` raise an exception for the Prism-derived iseq anyway. If so, you can use it to determine if the iseq is compiled from Prism without having any extra methods. `Location#iseq` is not good because it returns CRuby's internal data structure. `Location#node_id` is not best too, but it seems acceptable and necessary to tell Prism the node_id. ---------------------------------------- Misc #20260: ISEQ flag for prism compiler https://bugs.ruby-lang.org/issues/20260#change-106762 * Author: kddnewton (Kevin Newton) * Status: Open * Priority: Normal ---------------------------------------- In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process. I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby. Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging. -- 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/