From: "mame (Yusuke Endoh) via ruby-core" Date: 2026-10-08T02:59:12+00:00 Subject: [ruby-core:127004] [Ruby Feature#22379] Remove prism mismatch warning from `#syntax_tree` Issue #22379 has been updated by mame (Yusuke Endoh). Thank you, @Eregon! I mostly agree. 1) Agreed. I added the following to the RDoc of `Ruby::Prism` in the PR: > Ruby::Prism is the prism parser built into the interpreter, i.e., the very > parser that compiles the running program. > > Its API follows the version of prism bundled with this Ruby, and may change > incompatibly between Ruby minor versions: not only the node definitions but > also the other APIs, as the bundled prism may move to a new major version. > > In most cases, use the prism gem instead. Use Ruby::Prism only when you need > the very parser of the running interpreter. https://github.com/ruby/ruby/pull/19248/changes/5dc5ac93f3a09f100213536491de166699b16754 2) I'm not sure which is better. The note about compatibility added in (1) should discourage casual use of `Ruby::Prism`, and maybe we can trim it later if needed. 3) True. If the rewrite turns out to break often, we may add a CI job in ruby/prism that runs the tests on the rewritten code. 4) Yes, please! As for your additional worry about gems using `Ruby::Prism`, I think the note in (1) also helps here: it tells most gems to use the prism gem instead. The remaining users are gems closely tied to the interpreter (error_highlight, syntax_suggest, irb, debuggers, ...), which need to keep up with each maintained Ruby version anyway. So, @matz, what do you think about this change? If it looks good, I'll move forward to merge it. ---------------------------------------- Feature #22379: Remove prism mismatch warning from `#syntax_tree` https://bugs.ruby-lang.org/issues/22379#change-119397 * Author: Earlopain (Earlopain _) * Status: Open ---------------------------------------- #21795 added `#syntax_tree` for a few objects. Currently it is implemented in a way that uses the prism gem, using node_id. Because it is theoretically possible that node_ids from the internal cruby version of prism don't match with the node_ids from the installed prism gem, a warning is emitted when the two versions don't match: ```rb def x = nil pp method(:x).syntax_tree # => syntax_tree: a prism gem other than the default gem is loaded; the result may not correspond exactly to the compiled code # => @ DefNode (location: (1,0)-(1,11)) # ... ``` That this version-mismatch happens is basically a given. As soon as the user has prism in their lockfile for any reason it will be triggered. When I encounter a warning I assume that I have to make some change in the code to avoid it but there is nothing realistic for me to do, except to stop using the method alltogether. The warning is verbose-only. However it's good practise to run test suites with warnings enabled to keep up on deprecations, so even there it does not fit. I would like this warning to become documentation only for the above reasons. @eregon also suggested to only warn when we can prove that the node_id doesn't match. That should be possible as well, since we have the code location from the iseq and can check if the node we found via prism lines up. However, that doesn't guarantee that the contents of the node are also the same. -- 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/lists/ruby-core.ml.ruby-lang.org/