-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[semi-auto-props]: Rename ContainsFieldKeyword, revise cases that should handle FieldKeywordBackingField #61310
[semi-auto-props]: Rename ContainsFieldKeyword, revise cases that should handle FieldKeywordBackingField #61310
Conversation
src/Compilers/CSharp/Test/Semantic/Semantics/PropertyFieldKeywordTests.cs
Outdated
Show resolved
Hide resolved
@333fred @AlekseyTs For initial review. |
@AlekseyTs In 1d040e5, I introduced a simple generalized approach for reporting diagnostics that depend on accessor binding. Can you take a look and see if things are good? Thanks! |
@@ -215,6 +215,7 @@ private FieldSymbol GetActualField(Symbol member, NamedTypeSymbol type) | |||
return (!eventSymbol.HasAssociatedField || ShouldIgnoreStructField(eventSymbol, eventSymbol.Type)) ? null : eventSymbol.AssociatedField.AsMember(type); | |||
case SymbolKind.Property: | |||
// PROTOTYPE(semi-auto-props): Review other event associated field callers and see if we have to do anything special for properties. | |||
// Everything is reviewed except FlowAnalysis. |
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 prefer this to be carefully reviewed to make sure I'm not missing anything, as we later will rely on the prototype update that only FlowAnalysis is left.
Can someone restart the build? Thanks! |
It seems there is a real failure:
I'll try to investigate |
There are now different test failures. I'm addressing them separately in #61344 |
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs
Outdated
Show resolved
Hide resolved
Are we doing the same for the field keyword somewhere? In reply to: 1127829708 Refers to: src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs:1263 in 1d040e5. [](commit_id = 1d040e5, deletion_comment = False) |
public unsafe struct S1 | ||
{ | ||
public S1* s; | ||
public object P { get => field; } |
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 adding a test where this is a pointer and the other field is object. #Closed
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.
And flipping the types in the other struct too.
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.
The new test is resulting in extra binding. I haven't yet investigated why this is the case.
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.
It looks like the extra binding comes from the StartPropertyType
phase. For field symbols, the constraints check was moved to the AfterAccessorBindingChecks
call, but in property symbols constraint checks occur as part of binding the property type (SourcePropertySymbolBase.cs:1658 in this branch).
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.
There is no longer extra binding here. It's fixed in last few commits, but not sure the approach is good.
Done with review pass (commit 4) |
Not yet. A test for this will be related to applying Currently |
No. In reply to: 1128044671 |
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.
Done review pass (commit 6)
@333fred @AlekseyTs I don't quite understand why the used assemblies test fail, and what's the visible user issue is. Are you able to help? I'm not sure if it's a case where we can safely use |
Ok it looks like the last two commits are breaking things badly. The change wasn't reasonable anyway 😄 @AlekseyTs @333fred Any suggestions? |
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberFieldSymbol.cs
Outdated
Show resolved
Hide resolved
// This check prevents redundant ManagedAddr diagnostics on the underlying pointer field of a fixed-size buffer | ||
if (!IsFixedSizeBuffer) | ||
var type = Type; | ||
if (type.Kind != SymbolKind.PointerType && !IsFixedSizeBuffer) |
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.
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.
Which check? IsFixedSizeBuffer
? Given the existing code comment, it shouldn't be necessary here. But my thought was to keep it for two reasons:
- Simply making sure we align with the existing behavior (but removing shouldn't affect anything given the comment)
- The check is very light, it's just
(Modifiers & DeclarationModifiers.Fixed) != 0
, so we avoid the need to do more work with this small check.
Let me know if you prefer not checking it here.
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.
It is not obvious why do we still want to perform the check here under this condition?
Which check?
Sorry for the confusion. I was referring to the Type.CheckAllConstraints
that is duplicated between the two methods and performed in this method under the referenced condition.
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.
@AlekseyTs At some point I had only AfterAccessorBindingChecks
, but for some reason I can't understand, there was a test failure in used assemblies tests. I was asking about that in #61310 (comment).
// public S1* P { get => field; } | ||
Diagnostic(ErrorCode.ERR_ManagedAddr, "P").WithArguments("S1").WithLocation(5, 16)); | ||
|
||
Assert.Equal(1, accessorBindingData.NumberOfPerformedAccessorBinding); |
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.
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 think it's because I'm delaying CheckAllConstraints
call for pointer types in fields only.
I'll need to do special case too many other symbols using one of these approaches:
- current approach (meaning updating the code in symbols and also special case them in MethodCompiler)
- updating code in symbols but get back to the virtual AfterAccessorBindingChecks that you requested to revert. The reason it was reverted is we cared only about limited types of symbols, which will no longer be the case now. (my personal preference is using this approach)
Do you like any of these approaches? Is there a completely different approach you'd like me to follow?
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.
updating code in symbols but get back to the virtual AfterAccessorBindingChecks that you requested to revert. The reason it was reverted is we cared only about limited types of symbols, which will no longer be the case now.
I'm now using this approach. @AlekseyTs Let me know what do you think. Thanks!
Done with review pass (commit 13) |
var typeParameters = member switch | ||
{ | ||
MethodSymbol m => m.TypeParameters, | ||
NamedTypeSymbol nt => nt.TypeParameters, | ||
_ => ImmutableArray<TypeParameterSymbol>.Empty, | ||
}; | ||
|
||
foreach (var typeParameter in typeParameters) | ||
{ | ||
(typeParameter as SourceTypeParameterSymbolBase)?.AfterAccessorBindingChecks(); | ||
} |
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'm not much confident about this.
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.
It looks like PartialMethodWithArgumentConstraint
is now flaky. 😕
@AlekseyTs @333fred Any suggestion on how to correctly avoid extra binding for type parameters constraints checks, and why the current approach is flaky?
@333fred Reverted some changes per our conversation. I'll take another look once required members feature is merged. |
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 (commit 16). We should have the required members branch merged to main later this week, and when you're done with exams we can look at using the new phase in that branch to address the extra bindings from type constraint checking.
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 (commit 16)
@Youssef1313 Thanks for the contribution! |
Test plan: #57012