Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed May 27, 2022
1 parent 1f798f4 commit c58cbe1
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected override BoundBinaryOperator ShouldEnterFinallyBlock()
// We don't care about state = -2 (method already completed)

// So we only want to enter the finally when the state is -1
return F.IntEqual(F.Local(cachedState), F.Literal(StateMachineStates.NotStartedStateMachine));
return F.IntEqual(F.Local(cachedState), F.Literal(StateMachineStates.NotStartedOrRunningState));
}

#region Visitors
Expand All @@ -244,7 +244,7 @@ protected override BoundStatement VisitBody(BoundStatement body)
return F.Block(
F.Label(resumeLabel), // initialStateResumeLabel:
GenerateJumpToCurrentDisposalLabel(), // if (disposeMode) goto _exprReturnLabel;
GenerateSetBothStates(StateMachineStates.NotStartedStateMachine), // this.state = cachedState = -1;
GenerateSetBothStates(StateMachineStates.NotStartedOrRunningState), // this.state = cachedState = -1;
rewrittenBody);
}

Expand Down Expand Up @@ -288,7 +288,7 @@ public override BoundNode VisitYieldReturnStatement(BoundYieldReturnStatement no

blockBuilder.Add(
// this.state = cachedState = NotStartedStateMachine
GenerateSetBothStates(StateMachineStates.NotStartedStateMachine));
GenerateSetBothStates(StateMachineStates.NotStartedOrRunningState));

Debug.Assert(_currentDisposalLabel is object); // no yield return allowed inside a finally
blockBuilder.Add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal void GenerateMoveNext(BoundStatement body, MethodSymbol moveNextMethod)
bodyBuilder.Add(F.Label(_exprReturnLabel));

// this.state = finishedState
var stateDone = F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedStateMachine));
var stateDone = F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedState));
var block = body.Syntax as BlockSyntax;
if (block == null)
{
Expand Down Expand Up @@ -235,7 +235,7 @@ protected BoundCatchBlock GenerateExceptionHandling(LocalSymbol exceptionLocal,

// _state = finishedState;
BoundStatement assignFinishedState =
F.ExpressionStatement(F.AssignmentExpression(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedStateMachine)));
F.ExpressionStatement(F.AssignmentExpression(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedState)));

// builder.SetException(ex); OR if (this.combinedTokens != null) this.combinedTokens.Dispose(); _promiseOfValueOrEnd.SetException(ex);
BoundStatement callSetException = GenerateSetExceptionCall(exceptionLocal);
Expand Down Expand Up @@ -497,7 +497,7 @@ private BoundBlock GenerateAwaitForIncompleteTask(LocalSymbol awaiterTemp)

blockBuilder.Add(
// this.state = cachedState = NotStartedStateMachine
GenerateSetBothStates(StateMachineStates.NotStartedStateMachine));
GenerateSetBothStates(StateMachineStates.NotStartedOrRunningState));

return F.Block(blockBuilder.ToImmutableAndFree());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private BoundExpressionStatement GenerateCreateAndAssignBuilder()
protected override void InitializeStateMachine(ArrayBuilder<BoundStatement> bodyBuilder, NamedTypeSymbol frameType, LocalSymbol stateMachineLocal)
{
// var stateMachineLocal = new {StateMachineType}({initialState})
int initialState = _isEnumerable ? StateMachineStates.FinishedStateMachine : StateMachineStates.InitialAsyncIteratorState;
int initialState = _isEnumerable ? StateMachineStates.FinishedState : StateMachineStates.InitialAsyncIteratorState;
bodyBuilder.Add(
F.Assignment(
F.Local(stateMachineLocal),
Expand Down Expand Up @@ -323,7 +323,7 @@ private void GenerateIAsyncEnumeratorImplementation_MoveNextAsync()

BoundStatement ifFinished = F.If(
// if (state == StateMachineStates.FinishedStateMachine)
F.IntEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.FinishedStateMachine)),
F.IntEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.FinishedState)),
// return default;
thenClause: F.Return(F.Default(moveNextAsyncReturnType)));

Expand Down Expand Up @@ -433,13 +433,13 @@ private void GenerateIAsyncDisposable_DisposeAsync()

BoundStatement ifInvalidState = F.If(
// if (state >= StateMachineStates.NotStartedStateMachine /* -1 */)
F.IntGreaterThanOrEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.NotStartedStateMachine)),
F.IntGreaterThanOrEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.NotStartedOrRunningState)),
// throw new NotSupportedException();
thenClause: F.Throw(F.New(F.WellKnownType(WellKnownType.System_NotSupportedException))));

BoundStatement ifFinished = F.If(
// if (state == StateMachineStates.FinishedStateMachine)
F.IntEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.FinishedStateMachine)),
F.IntEqual(F.InstanceField(stateField), F.Literal(StateMachineStates.FinishedState)),
// return default;
thenClause: F.Return(F.Default(returnType)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected override BoundStatement GenerateStateMachineCreation(LocalSymbol state
bodyBuilder.Add(
F.Assignment(
F.Field(F.Local(stateMachineVariable), stateField.AsMember(frameType)),
F.Literal(StateMachineStates.NotStartedStateMachine)));
F.Literal(StateMachineStates.NotStartedOrRunningState)));

// local.$builder.Start(ref local) -- binding to the method AsyncTaskMethodBuilder<typeArgs>.Start()
var startMethod = methodScopeAsyncMethodBuilderMemberCollection.Start.Construct(frameType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IteratorFinallyFrame(

public IteratorFinallyFrame()
{
this.finalizeState = StateMachineStates.NotStartedStateMachine;
this.finalizeState = StateMachineStates.NotStartedOrRunningState;
}

public bool IsRoot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal void GenerateMoveNextAndDispose(BoundStatement body, SynthesizedImpleme
Dispatch(isOutermost: true),
GenerateReturn(finished: true),
F.Label(initialLabel),
F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineStates.NotStartedStateMachine)),
F.Assignment(F.Field(F.This(), stateField), F.Literal(StateMachineStates.NotStartedOrRunningState)),
newBody);

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected override void InitializeStateMachine(ArrayBuilder<BoundStatement> body
{
// var stateMachineLocal = new IteratorImplementationClass(N)
// where N is either 0 (if we're producing an enumerator) or -2 (if we're producing an enumerable)
int initialState = _isEnumerable ? StateMachineStates.FinishedStateMachine : StateMachineStates.InitialIteratorState;
int initialState = _isEnumerable ? StateMachineStates.FinishedState : StateMachineStates.InitialIteratorState;
bodyBuilder.Add(
F.Assignment(
F.Local(stateMachineLocal),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ protected SynthesizedImplementationMethod GenerateIteratorGetEnumerator(MethodSy
makeIterator = F.If(
// if (this.state == -2 && this.initialThreadId == Thread.CurrentThread.ManagedThreadId)
condition: F.LogicalAnd(
F.IntEqual(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedStateMachine)),
F.IntEqual(F.Field(F.This(), stateField), F.Literal(StateMachineStates.FinishedState)),
F.IntEqual(F.Field(F.This(), initialThreadIdField), managedThreadId)),
thenClause: F.Block(thenBuilder.ToImmutableAndFree()),
elseClauseOpt: makeIterator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal static class StateMachineStates
{
internal const int FirstIteratorFinalizeState = -3;

internal const int FinishedStateMachine = -2;
internal const int NotStartedStateMachine = -1;
internal const int FinishedState = -2;
internal const int NotStartedOrRunningState = -1;
internal const int FirstUnusedState = 0;

/// <summary>
Expand All @@ -30,7 +30,7 @@ internal static class StateMachineStates
internal const int FirstResumableIteratorState = InitialIteratorState + 1;

/// <summary>
/// Used for async-iterators to distinguish initial state from running state (-1) so that DisposeAsync can throw in latter case.
/// Used for async-iterators to distinguish initial state from <see cref="NotStartedOrRunningState"/> so that DisposeAsync can throw in latter case.
/// </summary>
internal const int InitialAsyncIteratorState = -3;

Expand Down
41 changes: 0 additions & 41 deletions src/Compilers/Core/Portable/CodeGen/StateMachineStates.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public abstract bool TryGetPreviousHoistedLocalSlotIndex(
public abstract int? GetFirstUnusedStateMachineState(bool increasing);

/// <summary>
/// For a given node associated with a entering a state of a state machine in the new compilation,
/// For a given node associated with entering a state of a state machine in the new compilation,
/// returns the ordinal of the corresponding state in the previous version of the state machine.
/// </summary>
/// <returns>
Expand Down

0 comments on commit c58cbe1

Please sign in to comment.