Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support node_id #2383

Open
kddnewton opened this issue Feb 8, 2024 · 1 comment
Open

Support node_id #2383

kddnewton opened this issue Feb 8, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@kddnewton
Copy link
Collaborator

We need to support an incrementing node_id integer on every node allocation. This is used to power error_highlight, but also other tools like action view.

@kddnewton kddnewton added the enhancement New feature or request label Feb 8, 2024
@kddnewton kddnewton added this to the Ruby 3.4.0 milestone Feb 8, 2024
@eregon
Copy link
Member

eregon commented Feb 8, 2024

Is there maybe another way these 2 usages could do what they do once they migrate to Prism? (they will need to change anyway since they use the experimental unstable RubyVM::AbstractSyntaxTree).
I guess the fundamental need is to identify a call node from a bytecode.

One idea to avoid the need to take/waste that space for every node would be to implicitly number all nodes by their order in the tree with some defined traversal (e.g. pre-order). Then to find node id N, we'd iterate nodes, incrementing our id counter for every node visited, and assuming they are the same nodes in the same order (which is very much what these usages need to assume to work), then return that nth node. E.g. by having some method on ParseResult making this easy.

https://github.com/rails/rails/blob/1007cc8c033f7713783faa02dc13f845640b464d/actionview/lib/action_view/template.rb#L395 seems to be almost doing this already, except it doesn't have a counter for every node visited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants