Project

General

Profile

Actions

Feature #22379

open

Remove prism mismatch warning from `#syntax_tree`

Feature #22379: Remove prism mismatch warning from `#syntax_tree`

Added by Earlopain (Earlopain _) about 3 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126847]

Description

#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:

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. The vendored version in cruby will not be updated and is totally separate from a users gemfile. If a new version of prism is released, it will eventually end up in a users lockfile. Or users don't update prism while bumping to a cruby patch version that vendored a newer version of prism.

If I see 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 (Benoit Daloze) 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.


Related issues 1 (0 open1 closed)

Related to Ruby - Feature #21795: Methods for retrieving ASTsClosedActions

Updated by Earlopain (Earlopain _) about 3 hours ago Actions #1

Actions

Also available in: PDF Atom