Skip to content

C#: Refactor data-flow predicates defined by dispatch#3652

Merged
calumgrant merged 1 commit into
github:masterfrom
hvitved:csharp/dataflow/impl-layer
Jun 11, 2020
Merged

C#: Refactor data-flow predicates defined by dispatch#3652
calumgrant merged 1 commit into
github:masterfrom
hvitved:csharp/dataflow/impl-layer

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Jun 9, 2020

Several data-flow predicates, such as getEnclosingCallable() are defined by dispatch. This PR adds an intermediate implementation layer NodeImpl, whereby the rootdef getEnclosingCallableImpl() can be made abstract. This means that the QL compiler will check that subclasses implement the abstract implementation predicates, but it also allows us to apply the unique aggregate in the exposed predicates where appropriate.

CSharp-Differences job here: https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/208/.

@hvitved hvitved added the C# label Jun 9, 2020
@hvitved hvitved marked this pull request as ready for review June 9, 2020 11:56
@hvitved hvitved requested a review from a team as a code owner June 9, 2020 11:56
@hvitved
Copy link
Copy Markdown
Contributor Author

hvitved commented Jun 10, 2020

CSharp-Differences job here: https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/208/.

g/mono/mono | 10760 | 9532 | 0.88587

🎉

Copy link
Copy Markdown
Contributor

@calumgrant calumgrant left a comment

Choose a reason for hiding this comment

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

Hey @hvitved, this seems like a really nice idea! If I understand things correctly, the performance gain is due to unique rather than dispatch optimization? In that case, I wondered whether we could just fold class NodeImpl into class Node and make class Node abstract? This would avoid the extra classes and the additional downcast to NodeImpl, and I think make things a bit clearer.

@hvitved
Copy link
Copy Markdown
Contributor Author

hvitved commented Jun 10, 2020

If I understand things correctly, the performance gain is due to unique rather than dispatch optimization?

Yes.

In that case, I wondered whether we could just fold class NodeImpl into class Node and make class Node abstract? This would avoid the extra classes and the additional downcast to NodeImpl, and I think make things a bit clearer.

This would expose the internal implementation predicate and make the exposed class abstract, both things are undesirable. I agree that the extra layer is annoying, but it is the best we can do with QL at the moment, I'm afraid.

@calumgrant
Copy link
Copy Markdown
Contributor

Okay, makes sense. My slight reservation is that the cast to NodeImpl also hides the implementation from the maintainers of the library as well!

@calumgrant calumgrant merged commit 5e021c2 into github:master Jun 11, 2020
@hvitved hvitved deleted the csharp/dataflow/impl-layer branch June 11, 2020 09:02
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.

2 participants