Skip to content

Ruby: Introduce With(out)Element MaD input tokens #8938

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

Merged
merged 2 commits into from
May 12, 2022

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Apr 28, 2022

This PR adds two new models-as-data input tokens WithElement and WithoutElement, with arguments similar to Element. They translate directly to SummaryComponent::withContent and SummaryComponent::withoutContent calls, respectively.

The new tokens allow us to

  1. Get rid of SummarizedCallable::clearsContent(ParameterPosition pos, DataFlow::ContentSet c): this can now instead be expressed as a summary with input Argument[pos].WithoutElement[arg] and output Argument[pos], for a suitable arg.
  2. Simplify existing flow summaries that verify that data is stored in a collection, such as Array.new, by replacing read+store with WithElement:
    Before:
        exists(ArrayIndex i |
          input = "Argument[0].Element[" + i + "]" and
          output = "ReturnValue.Element[" + i + "]"
        )
        or
        input = "Argument[0].Element[?]" and
        output = "ReturnValue.Element[?]"

After:

        input = "Argument[0].WithElement[any]" and
        output = "ReturnValue"
  1. Give a proper flow summary for the * (splat) operator:
      // *1 = [1]
      input = "Argument[self].WithoutElement[any]" and
      output = "ReturnValue.Element[0]"
      or
      // *[1] = [1]
      input = "Argument[self].WithElement[any]" and
      output = "ReturnValue"

@hvitved hvitved force-pushed the ruby/with-without-mad-tokens branch from cdca8a6 to 5df87d5 Compare May 11, 2022 13:17
@hvitved hvitved added the no-change-note-required This PR does not need a change note label May 11, 2022
@hvitved hvitved marked this pull request as ready for review May 11, 2022 18:51
@hvitved hvitved requested review from a team as code owners May 11, 2022 18:51
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

C#: Lgtm

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.

LGTM

@hvitved hvitved merged commit 0a78927 into github:main May 12, 2022
@hvitved hvitved deleted the ruby/with-without-mad-tokens branch May 12, 2022 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Java JS 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