Skip to content
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

Fix DataFlowsOut for certain local function situations #41802

Merged
merged 4 commits into from
Mar 11, 2020

Conversation

agocke
Copy link
Member

@agocke agocke commented Feb 20, 2020

There are two problems here, the first of which is the most important.

First, certain data flow analyses use "normalization" to adjust an existing
state variable for more variables declared after that state was created.
The default behavior is to extend that state to the "top" state, meaning
the starting state for that data flow analysis. This is usually the
right extension. However, some analysis requires extending the
variables the other way, to the bottom state. This PR adds functionality
for that customization.

The second problem is that data flow for local functions may include
variables that are not captured. This is by filtering the transfer function
to only include captured variables.

This PR is structured into two commits, each of which fix the associated
problem.

Fixes fixes #41600

Certain data flow analyses use "normalization" to adjust an existing
state variable for more variables declared after that state was created.
The default behavior is to extend that state to the "top" state, meaning
the starting state for that data flow analysis. This is usually the
right extension. However, some analysis requires extending the
variables the other way, to the bottom state.

This PR adds functionality for that customization and also fixes dotnet#41600.
@agocke agocke force-pushed the localfunc-data-flow branch from 70c922b to a6a0f3c Compare February 20, 2020 02:33
There's no strict design, but it seems reasonable that region analysis
consumers would only expect captured variables to show up in the
input/output variables when calling a local function.
@agocke agocke force-pushed the localfunc-data-flow branch from a6a0f3c to 869353b Compare February 20, 2020 18:47
@agocke agocke marked this pull request as ready for review February 20, 2020 21:55
@agocke agocke requested a review from a team as a code owner February 20, 2020 21:55
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 2)

@AlekseyTs
Copy link
Contributor

Does this PR fix #41853 as well?

@agocke
Copy link
Member Author

agocke commented Feb 22, 2020

No, that looks like an issue specific to DataFlowsIn.

@agocke agocke requested a review from gafter February 25, 2020 18:21
{
BitVector mask = BitVector.Empty;
for (int slot = 1; slot < state.Capacity; slot++)
BitVector mask = BitVector.AllSet(1);
Copy link
Member

@gafter gafter Mar 2, 2020

Choose a reason for hiding this comment

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

1 [](start = 46, length = 1)

nextVariableSlot (so the internal array doesn't have to be reallocated). Then in the loop,
mask[slot] = IsCapturedInLocalFunction(slot) #Closed

@gafter
Copy link
Member

gafter commented Mar 2, 2020

    internal sealed class LocalFunctionState : AbstractLocalFunctionState

I would have expected this to override NormalizeToBottom to return true. Can you please explain why that's not correct?


Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs:8552 in 64a4c6a. [](commit_id = 64a4c6a, deletion_comment = False)

@@ -4131,6 +4131,125 @@ static void Main(string[] args)

#region "lambda"

[Fact]
[WorkItem(41802, "https://github.com/dotnet/roslyn/pull/41802")]
Copy link
Member

@gafter gafter Mar 2, 2020

Choose a reason for hiding this comment

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

41802 [](start = 18, length = 5)

41600 #Closed

@gafter
Copy link
Member

gafter commented Mar 2, 2020

Done reviewing Iteration 3.

@agocke
Copy link
Member Author

agocke commented Mar 3, 2020

@gafter For nullable, we do a slightly different analysis since it's not possible to be flow dependent, as only one type can be reported in the semantic model. The design is to track a single "StartingState" that's Joined at every local function invocation and the starting state for the local function is the Join of every use site. I think the right behavior here is to treat undeclared variables as unassigned, since effectively they are at that point in the code.

Copy link
Member

@gafter gafter left a comment

Choose a reason for hiding this comment

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

:shipit:

@agocke agocke merged commit d4c9c7e into dotnet:master Mar 11, 2020
@ghost ghost added this to the Next milestone Mar 11, 2020
@agocke agocke deleted the localfunc-data-flow branch March 11, 2020 20:28
@sharwell sharwell modified the milestones: Next, 16.6.P2 Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect result is produced by DataFlowAnalysis.DataFlowsOut when local functions are involved
4 participants