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: Rework (hash) splat argument/parameter matching #17222

Merged
merged 6 commits into from
Aug 22, 2024

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 14, 2024

Inspired by @asgerf's PR, this PR rewrites the logic for how Ruby handles splat arguments and parameters. Instead of using a separate Content type to perform the matching, we make use of different argument/parameter positions in order to prevent synthetic splat arguments from being matched with synthetic splat parameters.

Not only does this rewrite simplify the code, we also get a significant speedup (12% end-to-end analysis speedup on average). This is because the early data flow pruning stages have precise argument/parameter position matching, wheres precise content matching only happens in later pruning stages.

@github-actions github-actions bot added the Ruby label Aug 14, 2024
@hvitved hvitved force-pushed the ruby/hash-splat-param-arg-matching branch 2 times, most recently from b6fe05b to 3ca4888 Compare August 15, 2024 09:01
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 15, 2024
@hvitved hvitved marked this pull request as ready for review August 15, 2024 09:05
@hvitved hvitved requested a review from a team as a code owner August 15, 2024 09:05
@hvitved hvitved requested a review from asgerf August 15, 2024 09:05
Comment on lines +1492 to +1494
any(SynthSplatArgumentShiftNode shift |
shift = TSynthSplatArgumentShiftNode(_, actualSplat, _)
).storeInto(this, _)

Check warning

Code scanning / CodeQL

Expression can be replaced with a cast Warning

The assignment to
shift
in this any(..) can be replaced with an inline cast.
@hvitved hvitved force-pushed the ruby/hash-splat-param-arg-matching branch from 185836e to f0c761a Compare August 20, 2024 13:32
@hvitved
Copy link
Contributor Author

hvitved commented Aug 20, 2024

I have pushed two new commits:

  • The first commit prevents positional parameters/arguments from being included in data flow, when they are preceded by a splat parameter/argument, as it is generally unsound to do so.
  • The second commit rewrites the confusing parameterMatch logic, and additionally prevents synthetic splat matching when explicit splat matching is possible. e.g. when args in foo(x, *args) can be directly matched with rest in def foo(x, *rest) ... end.

@hvitved hvitved force-pushed the ruby/hash-splat-param-arg-matching branch from f0c761a to d15e1b5 Compare August 20, 2024 14:22
@hvitved
Copy link
Contributor Author

hvitved commented Aug 22, 2024

A note on the additional results reported by DCA: The DCA run before c4b0f81 (which removes some false positive flow) shows a bunch of new results. This is because we now correctly identify more true positive flow, as witnessed by the test added in the last commit (which would fail on main). The extra results matches those that would be introduced by #17278, as seen by the DCA run on that PR.

Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

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

👍

@hvitved hvitved merged commit a213982 into github:main Aug 22, 2024
21 checks passed
@hvitved hvitved deleted the ruby/hash-splat-param-arg-matching branch August 22, 2024 08:54
Copy link

@Ahadchogani Ahadchogani left a comment

Choose a reason for hiding this comment

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

tokens

Choose a reason for hiding this comment

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

__

Choose a reason for hiding this comment

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

yu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants