From: "Eregon (Benoit Daloze) via ruby-core" Date: 2026-10-08T09:59:18+00:00 Subject: [ruby-core:127011] [Ruby Feature#22379] Remove prism mismatch warning from `#syntax_tree` Issue #22379 has been updated by Eregon (Benoit Daloze). Two more thoughts on this: 1. Should there be a `version:` keyword argument for `Ruby::Prism.parse(code, version:)`? Because the point of Ruby::Prism is to use the current version always. The default is actually `"latest"`, which by chance in this setup is equivalent to `"current"` (otherwise that would be a big footgun). I think one reason to keep it is gems wanting to use `Ruby::Prism` but having to support Ruby <= 4.0 too, in that case they'll already do `Prism.parse(code, version: "current")` (or `"nearest"`) and it's nice if they can just: ```ruby module MyGem Prism = defined?(Ruby::Prism) ? Ruby::Prism : Prism def self.ast(code) Prism.parse(code, version: "current") end end ``` It's however a bit weird that e.g. `Ruby::Prism.parse(code, version: "3.4")` is allowed. It might also lead some gems to use `Ruby::Prism` when they should use `Prism` (e.g. to avoid the extra dependency), the added docs above hopefully help with that. 2. TruffleRuby so far has regularly imported ruby/prism from master because there were not many `prism` gem releases and we needed some extra fixes not in any release (e.g. fixes for the FFI backend). This might not fly anymore with `Ruby::Prism` as users might expect for a given `RUBY_VERSION` a fixed `Ruby::Prism::VERSION` across Ruby implementations (though they can't expect that across RUBY_VERSION so maybe it's fine enough? I think concretely we might hit some issue with incompatible changes from Prism master sooner if TruffleRuby ships with a newer Prism than CRuby). If so, it means such fixes would need to be backported to the Prism release branch, that way we can have fixes for alternative Ruby implementations without also taking every other change on master since then. I think that makes a lot of sense, just something to be aware of, Prism release branches wouldn't be for CRuby only anymore but all Ruby implementations. ---------------------------------------- Feature #22379: Remove prism mismatch warning from `#syntax_tree` https://bugs.ruby-lang.org/issues/22379#change-119409 * 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/