Update implementation of required record members.#46053
Update implementation of required record members.#46053AlekseyTs merged 6 commits intodotnet:masterfrom
Conversation
Closes dotnet#45296. Closes dotnet#44903. Fixes dotnet#45012.
|
@cston, @jcouv, @RikkiGibson, @dotnet/roslyn-compiler Please review. #Closed |
1 similar comment
|
@cston, @jcouv, @RikkiGibson, @dotnet/roslyn-compiler Please review. #Closed |
|
Looking #Resolved |
| } | ||
|
|
||
| internal override bool SynthesizesLoweredBoundBody => true; | ||
| protected override int GetParameterCountFromSyntax() => _ctor.ParameterCount; |
There was a problem hiding this comment.
GetParameterCountFromSyntax [](start = 31, length = 27)
This is strange. I don't think it makes sense to ask how many parameters the Deconstruct method has in syntax, given that it has no syntax.
I think we should override ParameterCount and throw in this method (unreachable) #WontFix
There was a problem hiding this comment.
There was a problem hiding this comment.
Why "won't fix"?
I find nothing strange in this name. It was not introduced in this PR. This is just an abstraction to give out the number of parameters without creating parameters themselves. Completely makes sense to me for any method. I can see that you might want this method to have a different name, but changing it is not in scope for this PR. Overriding ParameterCount would be the wrong thing to do, because we want it to do exactly what it does today, even for this method.
In reply to: 456689715 [](ancestors = 456689715,456676237)
|
|
||
| internal override ImmutableArray<string> GetAppliedConditionalSymbols() | ||
| => ImmutableArray<string>.Empty; | ||
| static bool modifiersAreValid(DeclarationModifiers modifiers) |
There was a problem hiding this comment.
This should probably be marked as conditional. Consider making it a conditional method or filing a follow-up issue (when attributes on local functions become available for use) #Resolved
There was a problem hiding this comment.
This should probably be marked as conditional. Consider making it a conditional method or filing a follow-up issue (when attributes on local functions become available for use)
Added conditional compilation
In reply to: 456676274 [](ancestors = 456676274)
as far as I could tell, this is the same IL as Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:1662 in 11384c2. [](commit_id = 11384c2, deletion_comment = False) |
| if (this.IsGenericType && !localBase.IsErrorType() && this.DeclaringCompilation.IsAttributeType(localBase)) | ||
| { | ||
| var baseLocation = FindBaseRefSyntax(localBase); | ||
| baseLocation ??= FindBaseRefSyntax(localBase); |
There was a problem hiding this comment.
??= [](start = 29, length = 3)
nit: = seemed fined. Why change? #Closed
There was a problem hiding this comment.
nit: = seemed fined. Why change?
To make it safe to add something above the if later
In reply to: 456676550 [](ancestors = 456676550)
| if (!memberSignatures.ContainsKey(ctor)) | ||
| { | ||
| members.Add(ctor); | ||
| if (deconstruct.ReturnType.SpecialType != SpecialType.System_Void && !deconstruct.ReturnType.IsErrorType()) |
There was a problem hiding this comment.
&& !deconstruct.ReturnType.IsErrorType() [](start = 85, length = 41)
nit: if Deconstruct returns an error type, then clearly it's not returning void. Feels like this check could be removed. #Closed
There was a problem hiding this comment.
Feels like this check could be removed.
I do not see any harm in keeping it, find it better to follow the pattern and not relying on any special treatment/analysis around special types.
In reply to: 456676635 [](ancestors = 456676635)
| } | ||
|
|
||
| internal static MethodSymbol? FindValidCloneMethod(NamedTypeSymbol containingType) | ||
| internal static MethodSymbol? FindValidCloneMethod(TypeSymbol containingType, ref HashSet<DiagnosticInfo>? useSiteDiagnostics) |
There was a problem hiding this comment.
useSiteDiagnostics [](start = 115, length = 18)
nit: consider commenting or renaming (baseUseSiteDiagnostics) to clarify they are for the base type, not for the clone method. Could also be renamed in calling code #Closed
There was a problem hiding this comment.
consider commenting or renaming (baseUseSiteDiagnostics) to clarify they are for the base type, not for the clone method. Could also be renamed in calling code
I do not believe we want play games like that with names. It is intentionally doesn't matter where the errors are coming from, the point is that they should be reported at the use-site and that is exactly what the name is reflecting. We consistently use this name throughout the code base and intentionally do not try to specify the source/reason for the errors.
In reply to: 456676712 [](ancestors = 456676712)
| candidate.ReturnType, | ||
| TypeCompareKind.AllIgnoreOptions, | ||
| ref useSiteDiagnostics)) | ||
| { |
There was a problem hiding this comment.
not blocking this PR: should we check that the return value isn't nullable? (updated the note in test plan with clone method) Also added a note for nullability in user-provided Deconstruct method. #Closed
There was a problem hiding this comment.
should we check that the return value isn't nullable? (updated the note in test plan with clone method) Also added a note for nullability in user-provided Deconstruct method.
I do not believe nullable annotations should matter for the purpose of this method , they do not affect semantics.
In reply to: 456676833 [](ancestors = 456676833)
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 3)
The order got assigned explicitly based on when this member is actually synthesized In reply to: 660340192 [](ancestors = 660340192) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:5666 in 11384c2. [](commit_id = 11384c2, deletion_comment = False) |
In reply to: 660340112 [](ancestors = 660340112) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:1662 in 11384c2. [](commit_id = 11384c2, deletion_comment = False) |
Sorry, I didn't follow. Looking at the logic in SourceMemberContainerSymbol, I don't see how we changed the order of members getting added. In reply to: 660345586 [](ancestors = 660345586,660340192) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:5666 in 11384c2. [](commit_id = 11384c2, deletion_comment = False) |
jcouv
left a comment
There was a problem hiding this comment.
LGTM Thanks (iteration 3). I re-opened two questions, although I don't want to block the PR for that.
Note In reply to: 660353978 [](ancestors = 660353978,660345586,660340192) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:5666 in 11384c2. [](commit_id = 11384c2, deletion_comment = False) |
|
@cston, @RikkiGibson, @dotnet/roslyn-compiler Please review, need a second sign-off. #Closed |
| return; | ||
| } | ||
|
|
||
| Location baseLocation = null; |
There was a problem hiding this comment.
baseLocation [](start = 21, length = 12)
It looks like all code paths assign baseLocation, and always to the same value. Why not assign here? #Closed
| { | ||
| HashSet<DiagnosticInfo>? ignoredUseSiteDiagnostics = null; // This is reported when we bind bases | ||
| NamedTypeSymbol baseType = ContainingType.BaseTypeNoUseSiteDiagnostics; | ||
| return (ReturnType: !baseType.IsObjectType() && FindValidCloneMethod(baseType, ref ignoredUseSiteDiagnostics) is { } baseClone ? |
There was a problem hiding this comment.
!baseType.IsObjectType() && FindValidCloneMethod(baseType, ref ignoredUseSiteDiagnostics) is { } baseClone [](start = 32, length = 106)
Consider extracting a helper method for use here and in MakeDeclarationModifiers(). It looks like the helper method would also encapsulate ignoredUseSiteDiagnostics and baseType locals. #Closed
|
@cston I think I responded to your feedback. |
It is more efficient because it checks against diagnostics that verifier collects anyway, and it also covers any diagnostics reported by emit phase, which regular In reply to: 661276030 [](ancestors = 661276030) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:6163 in 8859145. [](commit_id = 8859145, deletion_comment = False) |
They are not equivalent, but you are correct the previous call can be removed. In reply to: 661274839 [](ancestors = 661274839) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:5517 in 8859145. [](commit_id = 8859145, deletion_comment = False) |
Closes #45296.
Closes #44903.
Fixes #45012.