-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Clear hoisted locals when disposing iterator and async-iterator state machines #75908
Changes from all commits
accbe6c
04902e1
61ca295
e19d7ab
386a056
cdcadd0
e170504
0d40220
b52733e
3ac0137
37d3b3d
e948e85
b1a5ebb
fdd444c
3eb020f
58ab13e
0df2e4b
0f63ecd
5529fd6
57cafd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,12 +61,13 @@ internal IteratorMethodToStateMachineRewriter( | |
FieldSymbol? instanceIdField, | ||
IReadOnlySet<Symbol> hoistedVariables, | ||
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies, | ||
ImmutableArray<FieldSymbol> nonReusableFieldsForCleanup, | ||
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals, | ||
ArrayBuilder<StateMachineStateDebugInfo> stateMachineStateDebugInfoBuilder, | ||
VariableSlotAllocator slotAllocatorOpt, | ||
int nextFreeHoistedLocalSlot, | ||
BindingDiagnosticBag diagnostics) | ||
: base(F, originalMethod, state, instanceIdField, hoistedVariables, nonReusableLocalProxies, synthesizedLocalOrdinals, stateMachineStateDebugInfoBuilder, slotAllocatorOpt, nextFreeHoistedLocalSlot, diagnostics) | ||
: base(F, originalMethod, state, instanceIdField, hoistedVariables, nonReusableLocalProxies, nonReusableFieldsForCleanup, synthesizedLocalOrdinals, stateMachineStateDebugInfoBuilder, slotAllocatorOpt, nextFreeHoistedLocalSlot, diagnostics) | ||
{ | ||
_current = current; | ||
|
||
|
@@ -160,7 +161,11 @@ internal void GenerateMoveNextAndDispose(BoundStatement body, SynthesizedImpleme | |
if (rootFrame.knownStates == null) | ||
{ | ||
// nothing to finalize | ||
F.CloseMethod(F.Return()); | ||
var disposeBody = F.Block( | ||
GenerateAllHoistedLocalsCleanup(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, see the diff between commits 1 and 2 for VerifyIL differences. |
||
F.Return()); | ||
|
||
F.CloseMethod(disposeBody); | ||
} | ||
else | ||
{ | ||
|
@@ -171,6 +176,7 @@ internal void GenerateMoveNextAndDispose(BoundStatement body, SynthesizedImpleme | |
ImmutableArray.Create<LocalSymbol>(stateLocal), | ||
F.Assignment(F.Local(stateLocal), F.Field(F.This(), stateField)), | ||
EmitFinallyFrame(rootFrame, state), | ||
GenerateAllHoistedLocalsCleanup(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. See |
||
F.Return()); | ||
|
||
F.CloseMethod(disposeBody); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't obvious. It looks like there are two call sites of this method and it is not clear why we want to have this behavior for all of them. Instead of completely ignoring the passed argument, consider adjusting the call sites to construct the right set of locals to clear. We can discuss offline in more details. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behavior could be a source of bugs in the future, since the method doesn't do what a reasonable dev would expect it to do.