Async-streams: disposal should continue without jump within a finally#46188
Async-streams: disposal should continue without jump within a finally#46188jcouv merged 5 commits intodotnet:masterfrom
Conversation
There was a problem hiding this comment.
📝 this additional condition is the core of the change.
We don't want to generate a jump when inside a finally. We achieve that by stacking a null disposal label when visiting finally blocks (both real and extracted ones).
There was a problem hiding this comment.
That last line "We don't want... We achieve..." would be a great comment here.
In reply to: 458340690 [](ancestors = 458340690)
|
Taking a look this morning. |
RikkiGibson
left a comment
There was a problem hiding this comment.
Welp, forgot to submit my pending review yesterday. LGTM.
| node = node.Update( | ||
| tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)), | ||
| node.CatchBlocks, F.Block(node.FinallyBlockOpt, F.Label(finallyExit)), node.FinallyLabelOpt, node.PreferFaultHandler); | ||
| tryBlock: F.Block(node.TryBlock, F.Label(finallyEntry)), |
There was a problem hiding this comment.
nit: indentation is off here
| finally | ||
| { | ||
| Console.Write(""BEFORE ""); | ||
| try { Console.Write(""INSIDE ""); } finally { Console.Write(""INSIDE2 ""); } |
There was a problem hiding this comment.
Consider formatting this in a conventional style so it is easier to scan.
| // goto _enclosingFinallyOrExitLabel; | ||
| // goto currentDisposalLabel; | ||
|
|
||
| return F.Block( |
There was a problem hiding this comment.
put a similar assertion: Debug.Assert(CurrentDisposalLabel is object); // no yield return allowed inside a finally
| finally | ||
| { | ||
| Console.Write(""BEFORE ""); | ||
| try { Console.Write(""INSIDE ""); } finally { Console.Write(""INSIDE2 ""); await Task.Yield(); } |
| private readonly AsyncIteratorInfo _asyncIteratorInfo; | ||
|
|
||
| /// <summary> | ||
| /// Where should we jump to to continue the execution of disposal path. |
There was a problem hiding this comment.
Where [](start = 12, length = 5)
We usually implement a "stack" using the compiler's execution stack (i.e. "previous=current; current=newvalue; dostuff; current=previous;" and a simple variable rather than a stack data structure.
I have no problem using an explicit stack data structure - it is certainly more clear. But please say that it is a stack in the doc here.
There was a problem hiding this comment.
Now that you mention it, I think I'll change to use a simple variable (typical pattern) rather than an explicit stack data structure.
gafter
left a comment
There was a problem hiding this comment.
😷 Looks good with minor comments about comments.
|
|
||
| // When exiting the try statement, we restore the previous disposal label. | ||
| _enclosingFinallyEntryOrFinallyExitOrExitLabel = _previousDisposalLabels.Pop(); | ||
| if (changedDisposalLabel) |
There was a problem hiding this comment.
changedDisposalLabel [](start = 16, length = 20)
You don't need to track whether or not it changed. You can just unconditionally set it to what it used to be.
gafter
left a comment
There was a problem hiding this comment.
😷 Looks good, with a small suggestion to further simplify.
…-pointers * upstream/master: (207 commits) Update argument state when parameter has not-null type (dotnet#46072) Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal (dotnet#46344) Update README (dotnet#46136) Revert "Revert "Support nullable annotations on unconstrained type parameters"" Revert "Support nullable annotations on unconstrained type parameters (dotnet#45993)" Fix type in publish data Update VSIXExpInstaller version to one available on ADO Update publish data for 16.8 Update version of RichCodeNav.EnvVarDump A fixed initializer must be bound to its natural type (dotnet#46293) Update features merged into 16.7p4 (dotnet#46229) Async-streams: disposal should continue without jump within a finally (dotnet#46188) Recommend default in type constraint, but not record (dotnet#46311) Add use site diagnostics to IsUnmanaged (dotnet#46114) Add another flaky test. Ensure NuGet connections use TLS 1.2 Update to Microsoft.CodeAnalysis.Testing 1.0.1-beta1.20374.2 Skip flaky test. Fix build break. (dotnet#46303) Skip a flaky test Relates to dotnet#46304 ...
…to function-pointer-type-lookup * upstream/features/function-pointers: (212 commits) Correct public API number. Update argument state when parameter has not-null type (dotnet#46072) Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal (dotnet#46344) Update README (dotnet#46136) Revert "Revert "Support nullable annotations on unconstrained type parameters"" Revert "Support nullable annotations on unconstrained type parameters (dotnet#45993)" Fix type in publish data Update VSIXExpInstaller version to one available on ADO Update publish data for 16.8 Update version of RichCodeNav.EnvVarDump A fixed initializer must be bound to its natural type (dotnet#46293) Update features merged into 16.7p4 (dotnet#46229) Async-streams: disposal should continue without jump within a finally (dotnet#46188) Recommend default in type constraint, but not record (dotnet#46311) Add use site diagnostics to IsUnmanaged (dotnet#46114) Add another flaky test. Ensure NuGet connections use TLS 1.2 Update to Microsoft.CodeAnalysis.Testing 1.0.1-beta1.20374.2 Skip flaky test. Fix build break. (dotnet#46303) ...
When we lower a
finallyin an async-iterator method, we follow it with aif (disposeMode) goto <nextDisposalLabel>;.But when we're inside an outer
finally, then we should have no jump. We just want to execute the remainder of the outerfinally.Fixes #43936