Skip to content

Avoid stack overflow due to deep recursion on long chain of calls. - #67913

Merged
AlekseyTs merged 6 commits into
dotnet:mainfrom
AlekseyTs:Issue67912
Apr 29, 2023
Merged

AlekseyTs merged 6 commits into
dotnet:mainfrom
AlekseyTs:Issue67912

Conversation

@AlekseyTs

Copy link
Copy Markdown
Contributor

Fixes #67912.

@AlekseyTs
AlekseyTs requested a review from a team as a code owner April 21, 2023 11:49
@ghost ghost added the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 21, 2023
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

2 similar comments
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review

@jcouv jcouv self-assigned this Apr 25, 2023
@jcouv jcouv added this to the 17.7 milestone Apr 25, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Apr 25, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: consider moving this snapshot just before first push (calls.Push(node); on line 5719), so that for each receiver we do snapshot&push together.
nit: then the logic on expressionIsRead could be moved here (just before visitAndCheckReceiver) since the snapshot&push doesn't care about that.
(I understand that you maintained exactly the original ordering, so those are just nits to consider)

@jcouv jcouv Apr 25, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why don't we need to update/track the expressionIsRead value when dealing with a single invocation? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why don't we need to update/track the expressionIsRead value when dealing with a single invocation?

Because the calling Visit does that. Above we are setting it for nested calls.

@jcouv jcouv Apr 25, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ordering for these two calls (CheckReceiverIfField(node.ReceiverOpt) and this.Visit(node.ReceiverOpt)) seems a bit different than in the original code. I'm not sure if it matters...
Is that intentional?

In comparison, the order for single invocation case below matches the previous order:

  1. VisitCall
  2. CheckReceiverIfField
  3. CheckReferenceToMethodIfLocalFunction
  4. Visit receiver
  5. Visit arguments #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand there is no order dependency between Visit and Check methods.

@jcouv jcouv Apr 26, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like we'll push at most two nodes into the invocations queue. Should this be a while loop instead? #Closed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should this be a while loop instead?

Yes, this is a typo.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have a general concern about the repetition that occurs in this PR: If we make a change to a method that is referenced by a "// Method does this before visiting each node", I'm concerned that we will not catch all these other places that should also be updated.
I don't have a great solution for this, but maybe it would be useful to add cref comments from those methods back to all the places that duplicate some of the logic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess there's also the broader question of whether the gain is worth all this additional complexity in the codebase. I'm curious what the team thinks (@dotnet/roslyn-compiler for thoughts).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a general concern about the repetition that occurs in this PR: If we make a change to a method that is referenced by a "// Method does this before visiting each node", I'm concerned that we will not catch all these other places that should also be updated.

We already have to face the same for visiting binary expressions

@jcouv jcouv Apr 26, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't follow where this came from. May be worth a comment #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't follow where this came from. May be worth a comment

Added a comment

@jcouv jcouv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 4) but would like to get team's opinion

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

1 similar comment
@AlekseyTs

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

@jaredpar jaredpar Apr 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be while not if? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't this be while not if?

Yes, the typo has been fixed already

@jaredpar jaredpar Apr 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this is roughly the same code on several derivations of CSharpSyntaxWalker? Did you consider putting a helper directly there that we could access? Probably cost us a Delegate allocation but maybe that's not too much. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

? Did you consider putting a helper directly there that we could access?

There are only two of them and they are slightly different. I do not think it is worth adding an abstraction across them

@jaredpar jaredpar Apr 21, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why isn't this inside the do loop below? Seems like we miss intermediate receiver calls as written. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why isn't this inside the do loop below? Seems like we miss intermediate receiver calls as written.

The intermediate receiver is the previous call and we already visited all interesting parts of it. It is our intention to not call VisitReceiver for them. I'll add a comment.

@AlekseyTs
AlekseyTs enabled auto-merge (squash) April 28, 2023 18:17
@AlekseyTs
AlekseyTs merged commit 53ac77e into dotnet:main Apr 29, 2023
@ghost ghost modified the milestones: 17.7, Next Apr 29, 2023
333fred added a commit to 333fred/roslyn that referenced this pull request May 2, 2023
* upstream/main: (2060 commits)
  implement code folding for anonymous objects
  Cleanup/perf in creating member maps. (dotnet#67997)
  Address feedback, clean the use of ILegacyGlobalOptionsWorkspaceService
  Update Publish.json
  Semantic snippets: Add inline statement snippets (dotnet#67819)
  Update VSSDK Build tools version
  Update doc comment
  Address feedback
  Move declaration near reference
  Address feedback
  Avoid stack overflow due to deep recursion on long chain of calls. (dotnet#67913)
  Check ILegacyGlobalOptionsWorkspaceService is null
  test scout queue
  add test
  update editor
  "Where" clause typo fix (dotnet#68002)
  Use `Keyword` helper method instead of hardcoding keyword help terms
  Move the SyntaxTree and SemanticModel action based analyzers to respect context.FilterSpan
  EnC refactoring: Align wrappers with contracts better (dotnet#67967)
  Include EA.RazorCompiler in source build (dotnet#67996)
  ...
@Cosifne Cosifne modified the milestones: Next, 17.7 P2 May 31, 2023
JoeRobich added a commit that referenced this pull request Jun 11, 2024
The EndToEnd OverflowOnFluentCall test is fixed in #67913, but would be a significant change to backport.
AlekseyTs pushed a commit that referenced this pull request Oct 20, 2026
…86100)

Fixes #86099

Since #67913, `AbstractFlowPass.VisitCall` walks a chain of receiver
calls with an explicit stack, so the receiver calls never go through
`VisitAlways`. When the region passed to `AnalyzeDataFlow` is one of
those receivers, the region is never entered and the analysis returns
`Succeeded == false` with empty results.

This calls `EnterRegionIfNeeded` for each receiver call on the way down
the chain and `LeaveRegionIfNeeded` after each one is visited, like
#76412 did for binary operators. The outermost call still goes through
`VisitAlways`, so its region is left only after the state is restored
for omitted calls.

Added `Repro_86099`, `CallChainReceivers` and
`CallChainReceiverWithOutArgument` to `RegionAnalysisTests`. All three
fail without the change and pass with it. The rest of the Emit3 tests
pass on macOS arm64 (net10.0), except 263 tests that fail to start
`ilasm` because only the osx-x64 binary is available here. I haven't run
the tests on Windows.
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.

Unable to compile project with large amount of grpc proto messages and services

4 participants