Skip to content

Check async method builder generic method constraints at call-site#24322

Merged
cston merged 1 commit intodotnet:dev15.6.xfrom
cston:21500
Jan 23, 2018
Merged

Check async method builder generic method constraints at call-site#24322
cston merged 1 commit intodotnet:dev15.6.xfrom
cston:21500

Conversation

@cston
Copy link
Copy Markdown
Contributor

@cston cston commented Jan 18, 2018

Customer scenario

The compiler currently ignores constraints on generic methods of the async method build for custom Task-like types. If those constraints are not satisfied by the awaiter or state machine for the Task-like type, the compiler will generate code does not verify and likely fails at runtime. Instead, the compiler should report compile-time errors for such cases.

Bugs this fixes

#21500
#12616

Workarounds, if any

None

Risk

Low.

Performance impact

Low.

Is this a regression from a previous update?

No.

How was the bug found?

Customer reported.

@cston cston requested a review from a team as a code owner January 18, 2018 22:06
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jan 18, 2018

Choose a reason for hiding this comment

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

, int arity [](start = 92, length = 11)

It looks like we don't need this parameter, the arity should be available from the method #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jan 18, 2018

Choose a reason for hiding this comment

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

ParseConstraints(builder, stream); [](start = 16, length = 34)

Consider keeping constraints as a separate entry in the MemberDescriptor, constraints are not really part of a signature. #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jan 18, 2018

Choose a reason for hiding this comment

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

if (!MatchType(types[i], signature, ref position)) [](start = 16, length = 50)

We probably should not assume that types are always coming in the same order. #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jan 18, 2018

Choose a reason for hiding this comment

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

MatchTypeParameterConstraints [](start = 21, length = 29)

If we start verifying constraints for methods, I think we should also verify them for types. #Closed

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Jan 18, 2018

Choose a reason for hiding this comment

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

attributes [](start = 16, length = 10)

Should we incorporate variance too? #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Jan 18, 2018

I think we should consider to specify required constraints and only check that those are present rather than requiring exact match. Otherwise things might get broken for platforms that omit/add "insignificant" constraints. For example, old frameworks do not have variance constraints, but they do not matter for our scenarios. Alternatively, we should consider simply verifying constraints once we construct symbols. #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Jan 18, 2018

Done with review pass (iteration 1). #Closed

@jcouv jcouv added this to the 15.7 milestone Jan 18, 2018
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Jan 19, 2018

@cston Since the PR is against master, I marked it as 15.7 15.6, but wasn't sure. Fix as appropriate. Thanks #Resolved

@jcouv jcouv modified the milestones: 15.7, 15.6 Jan 19, 2018
@cston cston changed the title Check type parameter constraints on well-known methods Check async method builder generic method constraints at call-site Jan 22, 2018
@cston
Copy link
Copy Markdown
Contributor Author

cston commented Jan 22, 2018

@dotnet/roslyn-compiler please review. #Resolved

@cston
Copy link
Copy Markdown
Contributor Author

cston commented Jan 22, 2018

@dotnet-bot test windows_release_vs-integration_prtest #Resolved

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.

Is it useful to also test case where Awaiter doesn't inherit INotifyCompletion?

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.

Added.

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

Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 4)

@cston
Copy link
Copy Markdown
Contributor Author

cston commented Jan 23, 2018

@MeiChin-Tsai for approval.

@MeiChin-Tsai
Copy link
Copy Markdown

Approved.

@cston cston changed the base branch from master to dev15.6.x January 23, 2018 19:23
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.

4 participants