-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Partial properties: duplicate membersByName
before merging accessors
#74969
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3668,12 +3668,7 @@ void mergePartialMethods(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Sym | |
} | ||
else | ||
{ | ||
if ((object)membersByName == _lazyEarlyAttributeDecodingMembersDictionary) | ||
{ | ||
// Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel. | ||
membersByName = new Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>>(membersByName, ReadOnlyMemoryOfCharComparer.Instance); | ||
} | ||
|
||
DuplicateMembersByNameIfCached(ref membersByName); | ||
membersByName[name] = FixPartialMember(membersByName[name], prevMethod, currentMethod); | ||
} | ||
} | ||
|
@@ -3692,40 +3687,23 @@ void mergePartialProperties(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray< | |
} | ||
else | ||
{ | ||
var (currentGet, prevGet) = ((SourcePropertyAccessorSymbol?)currentProperty.GetMethod, (SourcePropertyAccessorSymbol?)prevProperty.GetMethod); | ||
if (currentGet != null || prevGet != null) | ||
{ | ||
var accessorName = (currentGet ?? prevGet)!.Name.AsMemory(); | ||
mergeAccessors(ref membersByName, accessorName, currentGet, prevGet); | ||
} | ||
|
||
var (currentSet, prevSet) = ((SourcePropertyAccessorSymbol?)currentProperty.SetMethod, (SourcePropertyAccessorSymbol?)prevProperty.SetMethod); | ||
if (currentSet != null || prevSet != null) | ||
{ | ||
var accessorName = (currentSet ?? prevSet)!.Name.AsMemory(); | ||
mergeAccessors(ref membersByName, accessorName, currentSet, prevSet); | ||
} | ||
|
||
if ((object)membersByName == _lazyEarlyAttributeDecodingMembersDictionary) | ||
{ | ||
// Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel. | ||
membersByName = new Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>>(membersByName, ReadOnlyMemoryOfCharComparer.Instance); | ||
} | ||
|
||
DuplicateMembersByNameIfCached(ref membersByName); | ||
mergeAccessors(ref membersByName, (SourcePropertyAccessorSymbol?)currentProperty.GetMethod, (SourcePropertyAccessorSymbol?)prevProperty.GetMethod); | ||
mergeAccessors(ref membersByName, (SourcePropertyAccessorSymbol?)currentProperty.SetMethod, (SourcePropertyAccessorSymbol?)prevProperty.SetMethod); | ||
membersByName[name] = FixPartialMember(membersByName[name], prevProperty, currentProperty); | ||
} | ||
|
||
void mergeAccessors(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>> membersByName, ReadOnlyMemory<char> name, SourcePropertyAccessorSymbol? currentAccessor, SourcePropertyAccessorSymbol? prevAccessor) | ||
void mergeAccessors(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>> membersByName, SourcePropertyAccessorSymbol? currentAccessor, SourcePropertyAccessorSymbol? prevAccessor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also seems like this function could take |
||
{ | ||
Debug.Assert(currentAccessor != null || prevAccessor != null); | ||
if (currentAccessor != null && prevAccessor != null) | ||
if (currentAccessor is { } && prevAccessor is { }) | ||
{ | ||
var name = currentAccessor.Name.AsMemory(); | ||
var implementationAccessor = currentProperty.IsPartialDefinition ? prevAccessor : currentAccessor; | ||
membersByName[name] = Remove(membersByName[name], implementationAccessor); | ||
} | ||
else | ||
else if (currentAccessor is { } || prevAccessor is { }) | ||
{ | ||
var (foundAccessor, containingProperty, otherProperty) = prevAccessor != null ? (prevAccessor, prevProperty, currentProperty) : (currentAccessor!, currentProperty, prevProperty); | ||
var (foundAccessor, containingProperty, otherProperty) = prevAccessor is { } ? (prevAccessor, prevProperty, currentProperty) : (currentAccessor!, currentProperty, prevProperty); | ||
// When an accessor is present on definition but not on implementation, the accessor is said to be missing on the implementation. | ||
// When an accessor is present on implementation but not on definition, the accessor is said to be unexpected on the implementation. | ||
var (errorCode, propertyToBlame) = foundAccessor.IsPartialDefinition | ||
|
@@ -3737,6 +3715,15 @@ void mergeAccessors(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>> | |
} | ||
} | ||
|
||
private void DuplicateMembersByNameIfCached(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>> membersByName) | ||
{ | ||
if ((object)membersByName == _lazyEarlyAttributeDecodingMembersDictionary) | ||
{ | ||
// Avoid mutating the cached dictionary and especially avoid doing this possibly on multiple threads in parallel. | ||
membersByName = new Dictionary<ReadOnlyMemory<char>, ImmutableArray<Symbol>>(membersByName, ReadOnlyMemoryOfCharComparer.Instance); | ||
} | ||
} | ||
|
||
/// <summary>Links together the definition and implementation parts of a partial method. Returns a member list which has the implementation part removed.</summary> | ||
private static ImmutableArray<Symbol> FixPartialMember(ImmutableArray<Symbol> symbols, SourceOrdinaryMethodSymbol part1, SourceOrdinaryMethodSymbol part2) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Previously,
membersByName
was modified inmergeAccessors
before duplicating.