Skip to content

Use 'checked' names for synthesized vb intrinsic operators#63604

Merged
CyrusNajmabadi merged 19 commits intodotnet:mainfrom
CyrusNajmabadi:vbCheckedNames
Aug 29, 2022
Merged

Use 'checked' names for synthesized vb intrinsic operators#63604
CyrusNajmabadi merged 19 commits intodotnet:mainfrom
CyrusNajmabadi:vbCheckedNames

Conversation

@CyrusNajmabadi
Copy link
Contributor

@CyrusNajmabadi CyrusNajmabadi commented Aug 25, 2022

This brings VB in line with C#, which is nice for consistency, and helps the effort to add an API to generate intrinsic operators from a compilation (#63186)

Draft to see what breaks.

@ghost ghost added the Area-Compilers label Aug 25, 2022
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review August 25, 2022 23:18
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner August 25, 2022 23:18

public SynthesizedIntrinsicOperatorSymbol(TypeSymbol leftType, string name, TypeSymbol rightType, TypeSymbol returnType, bool isCheckedBuiltin)
{
Debug.Assert(SyntaxFacts.IsCheckedOperator(name) == isCheckedBuiltin);
Copy link
Contributor

@AlekseyTs AlekseyTs Aug 25, 2022

Choose a reason for hiding this comment

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

SyntaxFacts.IsCheckedOperator(name) == isCheckedBuiltin

This assumption might not hold true for operators that do not have checked form. For cases like this, we should simply adjust the boolean to reflect the fact. Doing that here should be fine. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hrmm... that surprises me. The way we get the name at the callsite is to feed this same boolean into the helper that produces the name. So i would expect these to match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

basically, teh caller does this:

                    symbols = ImmutableArray.Create<Symbol>(new SynthesizedIntrinsicOperatorSymbol(objectType,
                                                                                             OperatorFacts.BinaryOperatorNameFromOperatorKind(op, isChecked: binaryOperator.OperatorKind.IsChecked()),
                                                                                             objectType,
                                                                                             binaryOperator.Type,
                                                                                             binaryOperator.OperatorKind.IsChecked()));

(or the unary equivalent). So the same binaryOperator.OperatorKind.IsChecked() feeds into determining the name and passing the isCheckedBuiltIn flag through.

We could even consider not passing the boolean in and just determining it from the name if that works for you.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could even consider not passing the boolean in and just determining it from the name if that works for you.

Yes, that would work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Note: tehre was an interesting change here (but as this only affects tehse 'ide' symbols i think it's fine). Specifically, it used to be possible to get 'IsCheckedBuiltin=true' methods even for a non-checked method name. This would happen with virtually all dynamic operators, even for operators that have no checked version.

Now, by using hte name, the checked-ness or not is based only on the name alone. This led to some changes in test behavior, but i think it's acceptable/appropriate.


default:
expectChecked = type.IsDynamic();
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now, no other op-types ever expect to be checked.


default:
isChecked = isDynamic;
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now, no other op-types ever expect to be checked.

var symbols2 = (from node2 in nodes select (IMethodSymbol)semanticModel.GetSymbolInfo(node2).Symbol).ToArray();
foreach (var symbol2 in symbols2)
{
Assert.False(symbol2.IsCheckedBuiltin);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these equality operator methods are not checked anymore.


for (int i = 0; i < symbols1.Length; i++)
{
Assert.Equal(symbols1[i], symbols2[i]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because they're not checked, they are equal to the non-checked versions always.

void Test(dynamic x)
{
var z1 = x + 0;
var z2 = 0 + x;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added this new test with dynamic and operators to show where 'checked' might actually appear.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Aug 26, 2022

            Return _isCheckedBuiltin

Let's make it a calculated property, name is available.


In reply to: 1228555745


Refers to: src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedIntrinsicOperatorSymbol.vb:168 in 7823890. [](commit_id = 7823890, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Aug 26, 2022

        If _isCheckedBuiltin = other._isCheckedBuiltin AndAlso

It looks like this condition can be removed now.


In reply to: 1228557421


Refers to: src/Compilers/VisualBasic/Portable/Symbols/SynthesizedSymbols/SynthesizedIntrinsicOperatorSymbol.vb:78 in 7823890. [](commit_id = 7823890, deletion_comment = False)

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 17)

@CyrusNajmabadi CyrusNajmabadi requested a review from 333fred August 26, 2022 18:34
Copy link
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 19)

@CyrusNajmabadi
Copy link
Contributor Author

@AlekseyTs ptal when you have time :)

Copy link
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 (commit 19).Please squash commits in the process of merging.

@CyrusNajmabadi
Copy link
Contributor Author

Please squash commits in the process of merging.

Will do.

@CyrusNajmabadi CyrusNajmabadi merged commit f22d054 into dotnet:main Aug 29, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the vbCheckedNames branch August 29, 2022 16:40
@ghost ghost added this to the Next milestone Aug 29, 2022
@dibarbet dibarbet modified the milestones: Next, 17.4 P2 Sep 1, 2022
AlekseyTs added a commit to AlekseyTs/roslyn that referenced this pull request Sep 17, 2022
…perators for the target language.

Also ensure SymbolDisplay for VB can handle symbols for VB checked built-in operators after the
recent change in dotnet#63604. This fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1615080.
AlekseyTs added a commit that referenced this pull request Sep 21, 2022
…perators for the target language. (#64109)

Also ensure SymbolDisplay for VB can handle symbols for VB checked built-in operators after the
recent change in #63604. This fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1615080.
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