-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IsRef property to IConditionalOperation and ISimpleAssignmentOperation, add RefKind property to ILocalSymbol. #22933
Conversation
…ation, add RefKind property to ILocalSymbol. Closes dotnet#21311.
CC @jaredpar, @gafter, @AnthonyDGreen For public API change on ILocalSymbol. #Resolved |
{ | ||
AddKeyword(SyntaxKind.ReadOnlyKeyword); | ||
AddSpace(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the SymbolDisplay
change be a separate PR, perhaps post 15.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the SymbolDisplay change be a separate PR, perhaps post 15.5?
Do you have concerns about this change? It feels low risk to me.
@@ -23,11 +23,17 @@ public interface ILocalSymbol : ISymbol | |||
bool IsConst { get; } | |||
|
|||
/// <summary> | |||
/// Returns true if this local is a ref-local. | |||
/// Returns true if this local is a ref local or a ref readonly local. | |||
/// Use <see cref="RefKind"/> to get more detailed information. | |||
/// </summary> | |||
bool IsRef { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep this property if the same information is in RefKind? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep this property if the same information is in RefKind?
We already shipped it, cannot take it back. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary> | ||
/// Is this a ref assignment | ||
/// </summary> | ||
bool IsRef { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool IsRef { get; } [](start = 8, length = 19)
Why not expose RefKind property instead? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not expose RefKind property instead?
Because the kind of the reference is irrelevant here. Even compiler doesn't capture the kind. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary> | ||
/// Is result a managed reference | ||
/// </summary> | ||
bool IsRef { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool IsRef { get; } [](start = 8, length = 19)
Expose RefKind property instead? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose RefKind property instead?
Because the kind of the reference is irrelevant here. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -321,9 +321,9 @@ public object ConstantValue | |||
|
|||
internal abstract ImmutableArray<Diagnostic> GetConstantValueDiagnostics(BoundExpression boundInitValue); | |||
|
|||
public bool IsRef => RefKind == RefKind.Ref; | |||
public bool IsRef => RefKind != RefKind.None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider updating some compiler tests for this. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added new tests along with symbol display. #Closed
|
||
if (operation.IsRef) | ||
{ | ||
LogString(" (IsRef)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see which test exercises this. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see which test exercises this.
None at the moment. Only lowered tree can have nodes like this. Once ref reassignment feature is supported, then we can test this API.
In reply to: 148105993 [](ancestors = 148105993)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one test suggestion.
@@ -23,11 +23,17 @@ public interface ILocalSymbol : ISymbol | |||
bool IsConst { get; } | |||
|
|||
/// <summary> | |||
/// Returns true if this local is a ref-local. | |||
/// Returns true if this local is a ref local or a ref readonly local. | |||
/// Use <see cref="RefKind"/> to get more detailed information. | |||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, "IsRef" is true for readonly references as well.
I do not have a strong opinion on this, but we have similar API for methods/properties, should we make sure it is also "inclusive"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, "IsRef" is true for readonly references as well.
Yes.
I do not have a strong opinion on this, but we have similar API for methods/properties, should we make sure it is also "inclusive"?
IMethodSymbol and IPropertySymbol also have ReturnsByRefReadonly property, I'll let you decide what correlation should be between it and ReturnsByRef property. If any adjustments are needed, I think they are out of scope of this PR.
pre-approved to merge via link |
* dotnet/master: (36 commits) Remove usage of IOperation feature flag in newly added unit tests More fixes for IOperation tree. (dotnet#23028) Address PR feedback and remove unused resource and comment out unused error code Remove IOperation feature flag and internal registration APIs for operations Add unit test for VB Address review feedback and add more unit tests Fix unit tests Fix build errors from merge resolution Revert unintentional newline deletion Address recent feedback and do not generate an IParenthesizedOperation for C#. This change is now just a test-only change that verifies the current behavior. Address PR feedback and use singleton for null instance Address PR feedback Address PR feedback Do not invoke GetStandaloneNode helper in GetOperationWorker Fix InvalidCastException in CSharpOperationFactory for invalid nested member initializer (dotnet#22983) Use ICollection<string>.Contains to avoid Enumerator allocation Add IsRef property to IConditionalOperation and ISimpleAssignmentOperation, add RefKind property to ILocalSymbol. (dotnet#22933) Enable peverify-compat mode for langver < 7.2 (dotnet#22772) Properly detect root of a tree in Operation.SearchParentOperation (dotnet#22974) Fix IArgument and IArrayInitializer to have null types ...
* dotnet/master: (28 commits) Fix the operation verifier code now that getoperationinternal no longer exists. Remove usage of IOperation feature flag in newly added unit tests More fixes for IOperation tree. (dotnet#23028) Address PR feedback and remove unused resource and comment out unused error code Remove IOperation feature flag and internal registration APIs for operations Add unit test for VB Address review feedback and add more unit tests Fix unit tests Fix build errors from merge resolution Revert unintentional newline deletion Address recent feedback and do not generate an IParenthesizedOperation for C#. This change is now just a test-only change that verifies the current behavior. Address PR feedback and use singleton for null instance Address PR feedback Address PR feedback Do not invoke GetStandaloneNode helper in GetOperationWorker Fix InvalidCastException in CSharpOperationFactory for invalid nested member initializer (dotnet#22983) Use ICollection<string>.Contains to avoid Enumerator allocation Add IsRef property to IConditionalOperation and ISimpleAssignmentOperation, add RefKind property to ILocalSymbol. (dotnet#22933) Enable peverify-compat mode for langver < 7.2 (dotnet#22772) Fix IArgument and IArrayInitializer to have null types ...
Closes #21311.
vso : https://devdiv.visualstudio.com/DevDiv/NET%20Developer%20Experience%20Productivity/_workitems/edit/517771