Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 19, 2022

This PR makes use of #7260 to get rid of negative parameter/argument positions. Negative indices were used in two places:

  • -1: representing qualifiers/this parameters.
  • -2 ..: used to model flow through captured variables.

The former are used in flow summaries, which means that Argument[Qualifier] replaces Argument[-1]. The latter are only used internally, but getting rid of those as well means that we can remove some hacky equivalenceRelation-based ranking.

@hvitved hvitved requested a review from a team as a code owner January 19, 2022 16:09
@github-actions github-actions bot added the C# label Jan 19, 2022
@hvitved hvitved force-pushed the csharp/dataflow/no-negative-positions branch from b61ea63 to f178132 Compare January 19, 2022 16:14
@hvitved hvitved marked this pull request as draft January 19, 2022 16:14
@hvitved hvitved force-pushed the csharp/dataflow/no-negative-positions branch from f178132 to 128682b Compare January 19, 2022 17:54
@hvitved hvitved marked this pull request as ready for review January 20, 2022 07:55
michaelnebel
michaelnebel previously approved these changes Jan 20, 2022
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.

Looks good!

newtype TArgumentPosition =
TPositionalArgumentPosition(int i) { i = any(Parameter p).getPosition() } or
TQualifierArgumentPosition() or
TImplicitCapturedArgumentPosition(SsaCapturedEntryDefinition def)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks risky! This might introduce virtual-dispatch-sized blowups in any part of the dataflow lib that work with an argument without having joined that to a call target.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or is this a case where the call-callee relation is 1-1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Performance-wise this should be no different from before, where we translated each SsaCapturedEntryDefinition into a magic number (using equivalenceRelation), and used that magic number as both parameter and argument positions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But now that I think about it, this can probably be made a bit nicer (and smaller) by simply using the variable that is captured as the positions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the bad case requires some sort of convoluted setup where a single call might dispatch to many different lambdas (or other kinds of closures) that each capture some variable, and that this single call somehow provides a value in the corresponding argument-position(s). I don't know if such a construction is even possible - it depends on how these arguments are recognised.

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.

LGTM!

@hvitved hvitved merged commit fdd787b into github:main Jan 25, 2022
@hvitved hvitved deleted the csharp/dataflow/no-negative-positions branch January 25, 2022 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants