Skip to content
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 a couple of bugs in SG #55032

Merged
merged 3 commits into from
Jul 26, 2021
Merged

Conversation

chsienki
Copy link
Contributor

@chsienki chsienki commented Jul 21, 2021

  • Ensure that .Collect() reports as cached if all the inputs are cached
  • Don't use user comparer for matching inputs

Fixes #54855

- Ensure that .Collect() reports as cached if all the inputs are cached
- Don't use user comparer for matching inputs
@chsienki chsienki added this to the 17.0.P3 milestone Jul 21, 2021
@chsienki chsienki requested a review from a team as a code owner July 21, 2021 23:39
@chsienki chsienki added the Bug label Jul 21, 2021
@chsienki
Copy link
Contributor Author

@dotnet/roslyn-compiler for review please :)

@@ -38,7 +38,7 @@ public NodeStateTable<T> UpdateStateTable(DriverStateTable.Builder graphState, N
var inputItems = _getInput(graphState);

// create a mutable hashset of the new items we can check against
HashSet<T> itemsSet = new HashSet<T>(_comparer);
HashSet<T> itemsSet = new HashSet<T>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we using the custom comparer here?

Copy link
Contributor Author

@chsienki chsienki Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the bug. Because these are 'input' items (compilations / syntax trees / additional files etc) we control their lifetime. If the user comparer is used they can say that two additional files are different when they are not; that breaks our internal assumptions around comparers that they can only be used to change a modified value back to a cached value.

Basically the only time the comparer should be used is if we think the item has changed, the user has to the ability to override it.


AssertTableEntries(table, new[] { (1, EntryState.Cached), (2, EntryState.Cached), (3, EntryState.Cached) });
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

int index = 0;
foreach (var entry in table)
{
Assert.Equal(expected[index].item, (IEnumerable<T>)entry.item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the AssertEx helpers that do nice output diffing to make failures more diagnosable.

@pranavkm
Copy link
Contributor

@chsienki do you still plan on merging this for p3?

@chsienki chsienki changed the title Fixe a couple of bugs in SG Fix a couple of bugs in SG Jul 26, 2021
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 2)

@chsienki chsienki enabled auto-merge (squash) July 26, 2021 21:13
@chsienki chsienki merged commit 25f922c into dotnet:main Jul 26, 2021
@ghost ghost modified the milestones: 17.0.P3, Next Jul 26, 2021
@allisonchou allisonchou modified the milestones: Next, 17.0.P3 Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incremental Source Generators .Collect() caching behaviour
6 participants