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

[ruby] Ignore "Throwaway" AST Structures #4982

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

DavidBakerEffendi
Copy link
Collaborator

@DavidBakerEffendi DavidBakerEffendi commented Oct 1, 2024

Sometimes AST trees would be thrown away, specifically when long chained expressions would be compressed into temporary cache variables. Sometimes the ASTs that are thrown away, have nodes directly written to the diff graph. This only happens with expressions, and closures typically write directly to the diff graph.

This PR minimizes what is written directly to the diff graph from function creation, and extends x2cpg.Ast to also include CAPTURE edges. This also introduces closureToRefs map to track which Block nodes already have live method ASTs in the diff graph.

Sometimes AST trees would be thrown away, specifically when long chained expressions would be compressed into temporary cache variables. This only happens with expressions, and closures typically write directly to the diff graph.

This PR minimizes what is written directly to the diff graph from function creation, and extends `x2cpg.Ast` to also include `CAPTURE` edges. This also introduces `closureToRefs` map to track which `Block` nodes already have live method ASTs in the diff graph.
@DavidBakerEffendi DavidBakerEffendi added the ruby Relates to rubysrc2cpg label Oct 1, 2024
@DavidBakerEffendi DavidBakerEffendi self-assigned this Oct 1, 2024
case _ =>
astForExpression(baseNode).nodes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we removed this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be attributed to quite the performance slowdown for these long chained calls, especially as base and receiver are often the same long tree for these chained calls. I initially found it to be the cause for generating about 250 TypeRefs that were thrown away, so I think we can simply rely on non-nested nodes to give us the type hint.

@DavidBakerEffendi DavidBakerEffendi merged commit 3c27bf6 into master Oct 1, 2024
5 checks passed
@DavidBakerEffendi DavidBakerEffendi deleted the dave/ruby/writing-throwaway-ast-nodes branch October 1, 2024 12:17
@DavidBakerEffendi
Copy link
Collaborator Author

Seems this may have introduced Implicits$: iterator was expected to have exactly one element, but it actually has more

DavidBakerEffendi added a commit that referenced this pull request Oct 1, 2024
DavidBakerEffendi added a commit that referenced this pull request Oct 1, 2024
DavidBakerEffendi added a commit that referenced this pull request Oct 2, 2024
DavidBakerEffendi added a commit that referenced this pull request Oct 2, 2024
This correctly prevents re-use of nodes that are already being used elsewhere by ensuring deep copies.
DavidBakerEffendi added a commit that referenced this pull request Oct 2, 2024
)

* Revert "Revert "[ruby] Ignore "Throwaway" AST Structures (#4982)" (#4983)"

This reverts commit 464480d.

* [ruby] Re-implemented "Ignore "Throwaway" AST Structures (#4982)"
This correctly prevents re-use of nodes that are already being used elsewhere by ensuring deep copies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Relates to rubysrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants