-
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
Fix throw in generator comparer #76769
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ internal sealed class InputNode<T> : IIncrementalGeneratorNode<T> | |
private readonly Func<DriverStateTable.Builder, ImmutableArray<T>> _getInput; | ||
private readonly Action<IIncrementalGeneratorOutputNode> _registerOutput; | ||
private readonly IEqualityComparer<T> _inputComparer; | ||
private readonly IEqualityComparer<T> _comparer; | ||
private readonly IEqualityComparer<T>? _comparer; | ||
private readonly string? _name; | ||
|
||
public InputNode(Func<DriverStateTable.Builder, ImmutableArray<T>> getInput, IEqualityComparer<T>? inputComparer = null) | ||
|
@@ -35,7 +35,7 @@ public InputNode(Func<DriverStateTable.Builder, ImmutableArray<T>> getInput, IEq | |
private InputNode(Func<DriverStateTable.Builder, ImmutableArray<T>> getInput, Action<IIncrementalGeneratorOutputNode>? registerOutput, IEqualityComparer<T>? inputComparer = null, IEqualityComparer<T>? comparer = null, string? name = null) | ||
{ | ||
_getInput = getInput; | ||
_comparer = comparer ?? EqualityComparer<T>.Default; | ||
_comparer = comparer; | ||
_inputComparer = inputComparer ?? EqualityComparer<T>.Default; | ||
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. Should 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. No, we control the input comparer and all the inputs it compares. If that's throwing it's a real product bug and we don't want to falsely attribute it to a generator. |
||
_registerOutput = registerOutput ?? (o => throw ExceptionUtilities.Unreachable()); | ||
_name = name; | ||
|
@@ -83,7 +83,7 @@ public NodeStateTable<T> UpdateStateTable(DriverStateTable.Builder graphState, N | |
// This allows us to correctly 'replace' items even when they aren't actually the same. In the case that the | ||
// item really isn't modified, but a new item, we still function correctly as we mostly treat them the same, | ||
// but will perform an extra comparison that is omitted in the pure 'added' case. | ||
var modified = tableBuilder.TryModifyEntry(inputItems[itemIndex], _comparer, elapsedTime, noInputStepsStepInfo, EntryState.Modified); | ||
var modified = tableBuilder.TryModifyEntry(inputItems[itemIndex], elapsedTime, noInputStepsStepInfo, EntryState.Modified); | ||
Debug.Assert(modified); | ||
itemsSet.Remove(inputItems[itemIndex]); | ||
} | ||
|
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.
What does the check
_comparer is null
serve here? Thenull
case means it's effectively the default comparer so why are we not trying to use that forTryModifyEntry
?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's an optimization. If we've already determined that one of the two sides is modified then the default comparer will always find the same result. However if there's a custom comparer it's possible that will override the result and return cached.