From: "kddnewton (Kevin Newton) via ruby-core" Date: 2024-02-13T18:58:23+00:00 Subject: [ruby-core:116712] [Ruby master Misc#20260] ISEQ flag for prism compiler Issue #20260 has been updated by kddnewton (Kevin Newton). Yes, the user-facing part for iseq is only changing `RubyVM::InstructionSequence.to_a` to include `prism: true/false`. For error highlight to know, we will either need to change `RubyVM::AST.of` to know that it is coming from prism or we will need to add something to `Thread::Backtrace::Location` like `prism?`. This code here: https://github.com/ruby/error_highlight/blob/80ede6b8ca3219310f30cff42cd17177a7e47f25/lib/error_highlight/base.rb#L55C7-L59 does: ```ruby return nil unless Thread::Backtrace::Location === loc node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) Spotter.new(node, **opts).spot ``` That would need to be either: ```ruby return nil unless Thread::Backtrace::Location === loc if loc.prism? node = Prism.node_for(loc) PrismSpotter.new(node, **opts).spot else node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) Spotter.new(node, **opts).spot end ``` or it would need to be: ```ruby return nil unless Thread::Backtrace::Location === loc node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true) if node.is_a?(Prism::Node) PrismSpotter.new(node, **opts).spot else Spotter.new(node, **opts).spot end ``` or maybe some other kind of API change. Either way we would need to access the prism flag that is on the iseq associated with the backtrace location. I'm fine with any kind of API that gets us there. ---------------------------------------- Misc #20260: ISEQ flag for prism compiler https://bugs.ruby-lang.org/issues/20260#change-106728 * 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/