Skip to content

JS/Ruby: Represent non-positional arguments with Argument/Parameter tokens#8533

Merged
asgerf merged 13 commits intogithub:mainfrom
asgerf:mad-receiver-token
Mar 28, 2022
Merged

JS/Ruby: Represent non-positional arguments with Argument/Parameter tokens#8533
asgerf merged 13 commits intogithub:mainfrom
asgerf:mad-receiver-token

Conversation

@asgerf
Copy link
Contributor

@asgerf asgerf commented Mar 23, 2022

Previously we had separate tokens for non-positional arguments, like Receiver and BlockArgument.

Now these are represented as operands to Argument/Parameter tokens, as discussed with @hvitved:

Ruby:

  • Argument[self] for the receiver (previously Receiver)
  • Argument[block] for the block argument (previously BlockArgument)
  • Argument[foo:] for a keyword argument named foo (previously not implemented)

JS:

  • Argument[this] for the receiver (previously Argument[-1])

All of the above also apply to the Parameter token.

The names self and this were chosen to coincide with the keyword/convention from the language.

@asgerf asgerf added no-change-note-required This PR does not need a change note Ruby labels Mar 23, 2022
@github-actions github-actions bot added the JS label Mar 23, 2022
@asgerf asgerf force-pushed the mad-receiver-token branch from 68b86df to 69eb24e Compare March 23, 2022 17:11
@asgerf asgerf marked this pull request as ready for review March 23, 2022 17:38
@asgerf asgerf requested review from a team as code owners March 23, 2022 17:38
hmac
hmac previously approved these changes Mar 24, 2022
Copy link
Contributor

@hmac hmac left a comment

Choose a reason for hiding this comment

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

I don't feel qualified to comment closely on the implementation, but it seems straightforward and the test changes are what I'd expect. I think I have a slight preference for Receiver over Argument[self] (shorter and matches better with MethodCall.getReceiver) but having consistency between the languages probably trumps that.

The keyword parameter support is really nice!

erik-krogh
erik-krogh previously approved these changes Mar 24, 2022
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

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

JS 👍
(The JS part is simple).

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.

LGTM; two minor comments.

)
or
pos.isBlock() and
result = Label::blockParameter()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the toString of LabelBlockParameter be updated to getParameter(block) (and similar for LabelKeywordParameter? And are we missing labels for the self parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The toString value of these labels are currently named after predicates on API::Node (not MaD tokens). At least that seemed to be the convention, one that I've tried to continue. So it doesn't need updating.

Copy link
Contributor

Choose a reason for hiding this comment

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

At least that seemed to be the convention

I had to give some value for toString() when I introduced IPA types for API-labels.
I decided to use the previous value of the label (which was a string).

The Python labels were named after their predicates on API::Node, so that's what I used.
In JS the toString() are the original labels that Max defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like having the toString() be the associated predicate on API::Node, so maybe we should update JS to also do that?

sink(x)
})
Foo.intoNamedParameter(tainted, ->(foo:) {
sink(foo)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should document that flow is missing in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dang, I missed that. I'll try to introduce inline assertions to this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use inline test expectations, much better overall, and it's now clear that this flow is missing.

I haven't investigated why the flow is missing, though. I was under the impression that providing the correct ArgumentPosition and ParameterPosition values would be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hvitved would you like it addressed in this PR? Please let me know either way

Copy link
Contributor

Choose a reason for hiding this comment

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

No, let's do that follow-up

@asgerf asgerf dismissed stale reviews from erik-krogh and hmac via 8e2ffc2 March 25, 2022 10:32
erik-krogh
erik-krogh previously approved these changes Mar 25, 2022

from DataFlow::PathNode source, DataFlow::PathNode sink, Conf conf
where conf.hasFlowPath(source, sink)
select sink, source, sink, "$@", source, source.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to actually keep this, in addition to import PathGraph, like we do in other flow tests that use InlineFlowTest.

@asgerf asgerf force-pushed the mad-receiver-token branch from 690069d to 0b30ecf Compare March 28, 2022 11:57
@asgerf asgerf merged commit f22df76 into github:main Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants