Skip to content

Fix emit of param-nullchecking on async methods#58822

Merged
RikkiGibson merged 4 commits intodotnet:mainfrom
RikkiGibson:pnc-emit-async
Jan 18, 2022
Merged

Fix emit of param-nullchecking on async methods#58822
RikkiGibson merged 4 commits intodotnet:mainfrom
RikkiGibson:pnc-emit-async

Conversation

@RikkiGibson
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson commented Jan 13, 2022

Closes #58796
Related to #36024

Spec update: dotnet/csharplang#5642

It seems we neglected to test the feature in combination with regular async methods. We do have some existing coverage for async iterators.

I found it was simplest to insert null checks after the last rewriting pass for both regular and synthesized methods. I found that when I added the checks before running the iterator rewriter they would actually get dropped in some scenarios.


var builtBody = bodyBuilder.ToImmutableAndFree();
ImmutableArray<BoundStatement> newBody = LocalRewriter.TryConstructNullCheckedStatementList(method.Parameters, builtBody, F);
return newBody.IsDefault ? F.Block(builtBody) : F.Block(ImmutableArray.Create(stateMachineVariable), newBody);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ImmutableArray here specifically was the cause of the crash. newBody already contained a block with the stateMachineVariable in it, so adding it again here made us crash in code generation.

}
SetGlobalErrorIfTrue(nullCheckStatements.HasErrors() || diagnosticsThisMethod.HasAnyErrors());

if (_emitMethodBodies && !diagnosticsThisMethod.HasAnyErrors() && !_globalHasErrors)
Copy link
Copy Markdown
Contributor

@cston cston Jan 13, 2022

Choose a reason for hiding this comment

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

!diagnosticsThisMethod.HasAnyErrors()

Is this check redundant now?

Never mind, it's probably better to be explicit here about checking for diagnostics from this method.

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2) with a test suggestion to consider

@jcouv jcouv self-assigned this Jan 13, 2022
@RikkiGibson RikkiGibson enabled auto-merge (squash) January 18, 2022 18:40
Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 4)

@RikkiGibson RikkiGibson merged commit 6be7f04 into dotnet:main Jan 18, 2022
@ghost ghost added this to the Next milestone Jan 18, 2022
@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P1 Feb 4, 2022
@RikkiGibson RikkiGibson deleted the pnc-emit-async branch March 7, 2022 22:14
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.

Param nullchecking emit crash with async method

3 participants