-
Notifications
You must be signed in to change notification settings - Fork 45
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 missing incremental generator caching #38
Fix missing incremental generator caching #38
Conversation
Thanks for flagging this, I really need to understand it properly - have you flagged this to the .NET team in https://github.com/dotnet/runtime? Because if this is the case, I think every single Source Generator currently shipping (and due to ship in .NET 7) has this problem 😬 |
Yes, I have made the following issue dotnet/runtime#74557, and PR dotnet/runtime#74558. From comments in the PR it sounds like it is a well known issue - and from the comments it seems like the comparer shouldn't be used but instead the logic you have in the execute step should be moved to the predicate. |
Hi @andrewlock So looking at this comment dotnet/runtime#64579 (comment) and dotnet/runtime#68353 (comment), one clearly shouldn't use combine with compilation and use custom comparer. Looking at how implemented in this PR dotnet/runtime#64579 code in I have refactored the PR such that it follows the same principles - hence moved code from You can validate the cache is indeed used correctly by doing the following changes in
and following in
now if you create a new console project, create some enums with the attribute and reference the generator project you can see it increment correctly, and only when changes to the respective enum has been made (when looking in dependencies->analysers->..). Hope you have the time for a review :-) |
Hey @3schwartz, sorry for the delay, I've been very busy so the OSS has taken a back seat! I took a look at the new API in .NET 7, and I think there's a better approach to this now: the PR is here if you'd like to take a look 🙂 #41 |
Hopefully fixed in #41, but let me know if you think I've missed something! |
Agree :-) |
Hi,
First of all thank you for a awesome post (and i general great) post regarding incremental generators.
I was reading this blog and the main documentation and both describes one shouldn't combine with the whole compilation, since this will trigger the flow of every key stroke in the IDE.
As an example, create a new library
ExampleGenerator
and haveExampleGenerator.csproj
look likeCreate file
ExampleGenerator.cs
with the following incremental generatorThanks to Pawel Gerr for the counter idea and you for example how find enums with attributes.
Now create a console project
ExampleConsole
and haveExampleConsole.csproj
look likeCreate three files with enums, two which have the attribute.
SomeOther.cs
Bar.cs
Foo.cs
Now if you do ANY changes to any file, you can see in Dependencies->Analyzers->ExampleGenerator that both
Example.Bar.cs
andExample.Foo.cs
have their counter increased.The best solution would be to avoid the
.Collect()
and just provideIncrementalValuesProvider
instead of aIncrementalValueProvider
. Since you are already creating a new file for each syntax, the change is just to avoid the loop.Hope you have the time to look at my PR - please let me now any comments and thoughts.