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: Model more flow from splat arguments #13974

Closed
wants to merge 3 commits into from
Closed

Conversation

hmac
Copy link
Contributor

@hmac hmac commented Aug 15, 2023

Allow flow from a splat argument to a positional parameter in cases
where there are positional arguments left of the splat. For example:

def foo(x, y, z); end

foo(1, *[2, 3])

Allow flow from a splat argument to a positional parameter in cases
where there are positional arguments left of the splat. For example:

    def foo(x, y, z); end

    foo(1, *[2, 3])
@hmac hmac marked this pull request as ready for review August 23, 2023 13:21
@hmac hmac requested a review from a team as a code owner August 23, 2023 13:21
@hmac hmac added the no-change-note-required This PR does not need a change note label Aug 23, 2023
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

I can see that this approach works, but it has the downside the each relevant callable will get n SynthSplatParameterNodes, where n is the number of possible splat argument positions. Instead, I think it would be better to adjust the indices at the call sites. That is, for a call

foo(x, *args)

we

  • don't assign *arg a parameter position
  • instead read each element out of *args into an intermediate node, and store from that node into SynthSplatArgumentNode, in this case subtracting 1 from each index.

@hmac
Copy link
Contributor Author

hmac commented Aug 30, 2023

@hvitved I put together an alternative approach that follows my interpretation of what you said, though it may not exactly match: #14090

The results look roughly the same except we catch this additional case:

def posargs(p1, *posargs)
  sink(posargs[0])
end

args = [1, taint(2)]
posargs(*args)

Analysis time for the alternative PR looks worse in general.

@hmac
Copy link
Contributor Author

hmac commented Sep 25, 2023

Superseded by #14090

@hmac hmac closed this Sep 25, 2023
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.

2 participants