Skip to content

C#: Additional tracking of lambdas through fields and properties #15489

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
Feb 12, 2024

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jan 31, 2024

This PR adds support for tracking lambdas through fields and (field-like) properties, but (currently) limited to assignments in constructors and uses in instance methods:

class C
{
    private Action a;

    public C(Action a)
    {
        this.a = a; // (1)
    }

    public void CallAction()
    {
        this.a(); // (2)
    }

    public void SetAction(Action a)
    {
        this.a = a; // (3)
    }
}

That is, we will track lambdas from (1) to (2), but not from (2) to (3). This restriction is because the data flow algorithm for tracking lambdas is not field-sensitive, hence we need to model field stores/reads as jump steps, and therefor apply the conservative restriction above.

I spot checked a few of the new results, and they are indeed the result of more lambda calls being resolvable.

@github-actions github-actions bot added the C# label Jan 31, 2024
@hvitved hvitved force-pushed the csharp/lambda-field-flow branch 4 times, most recently from 669fef6 to 5c2a323 Compare February 1, 2024 07:51
@hvitved hvitved force-pushed the csharp/lambda-field-flow branch from 5c2a323 to bfe4a4b Compare February 1, 2024 10:51
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Feb 9, 2024
@hvitved hvitved marked this pull request as ready for review February 9, 2024 09:31
@hvitved hvitved requested a review from a team as a code owner February 9, 2024 09:31
Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

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

Looks plausible to me.

@hvitved hvitved merged commit 9634511 into github:main Feb 12, 2024
@hvitved hvitved deleted the csharp/lambda-field-flow branch February 12, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants