Skip to content

Support consumption scenarios for checked user-defined operators#60032

Merged
AlekseyTs merged 3 commits intodotnet:features/CheckedUserDefinedOperatorsfrom
AlekseyTs:CheckedUserDefinedOperators_05
Mar 10, 2022
Merged

Support consumption scenarios for checked user-defined operators#60032
AlekseyTs merged 3 commits intodotnet:features/CheckedUserDefinedOperatorsfrom
AlekseyTs:CheckedUserDefinedOperators_05

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

Done review pass (commit 2). A couple of small questions before I sign off.

if (operators.Count != 0)
{
continue;
for (int i = operators2.Count - 1; i >= 0; i--)
Copy link
Copy Markdown
Member

@333fred 333fred Mar 8, 2022

Choose a reason for hiding this comment

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

Do you think there's a reasonable way to share this code between unary and binary resolution? Maybe with a Func<T, MethodSymbol> getSignature parameter for extracting the method from a signature? This is basically the same code between the two locations. #Resolved

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.

Do you think there's a reasonable way to share this code between unary and binary resolution?

Perhaps, but I prefer not going through this trouble for just only two call sites.

}
}

if (SyntaxFacts.IsCheckedOperator(method.Name) &&
Copy link
Copy Markdown
Member

@333fred 333fred Mar 8, 2022

Choose a reason for hiding this comment

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

Interesting. Does this mean that, if I have a dependency that updates to include such an operator and make no other changes, my code stops compiling? Is it worth confirming with LDM that's the desired behavior? #Resolved

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.

Interesting. Does this mean that, if I have a dependency that updates to include such an operator and make no other changes, my code stops compiling? Is it worth confirming with LDM that's the desired behavior?

We have chosen to use the checked operator, not simply detected a presence of such declaration

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.

I do not see anything special about this case by comparison to other features. Adding an operator might break a consumer by changing what it calls or by causing an ambiguity.

}

return new BoundNullCoalescingOperator(syntax, rewrittenLeft, rewrittenRight, leftPlaceholder, leftConversion, resultKind, rewrittenResultType);
return new BoundNullCoalescingOperator(syntax, rewrittenLeft, rewrittenRight, leftPlaceholder, leftConversion, resultKind, @checked: false, rewrittenResultType);
Copy link
Copy Markdown
Member

@333fred 333fred Mar 8, 2022

Choose a reason for hiding this comment

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

Why is false correct to pass here? Shouldn't it be based on whether the original context was checked? #Resolved

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.

Why is false correct to pass here? Shouldn't it be based on whether the original context was checked?

We are in lowering. All conversions have been figured out, the flag is not interesting.

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.

I'll add a comment to BoundNodes.xml


// Note: The trailing expression was already converted to the submission result type in Binder.BindGlobalStatement.
boundStatements.Add(new BoundReturnStatement(lastStatement.Syntax, RefKind.None, trailingExpression));
boundStatements.Add(new BoundReturnStatement(lastStatement.Syntax, RefKind.None, trailingExpression, @checked: false));
Copy link
Copy Markdown
Member

@333fred 333fred Mar 8, 2022

Choose a reason for hiding this comment

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

What if the last expression was a checked expression? Or would that be fine, because the return itself isn't checked, but the expression it contains is? #Resolved

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.

What if the last expression was a checked expression? Or would that be fine, because the return itself isn't checked, but the expression it contains is?

This flag is not interesting post lowering. It is only interesting for inference for lambdas and is supposed to reflect the context to use for a possible conversion if return statement is supposed to perform one. The actual expression in this case makes no impact on the context for conversion.

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.

I'll add a comment to BoundNodes.xml

Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 2). The comment to BoundNodes.xml sounds good, thanks.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@chsienki, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@chsienki, @dotnet/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@chsienki, https://github.com/orgs/dotnet/teams/roslyn-compiler For the second review.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@chsienki, @dotnet/roslyn-compiler For the second review.

@chsienki
Copy link
Copy Markdown
Member

Looking

@AlekseyTs AlekseyTs merged commit 62ac62b into dotnet:features/CheckedUserDefinedOperators Mar 10, 2022
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.

3 participants