[go: nahoru, domu]

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

Async overloads source generator #1575

Merged
merged 36 commits into from
Aug 24, 2021

Conversation

bash
Copy link
Contributor
@bash bash commented Jul 7, 2021

I took a crack at writing a source generator to replace the AsyncOverloads.t4 template. This is a follow up to my PR #1545.

Details

The source generator looks for methods annotated with the [GenerateAsyncOverload] attribute.
It generates a public method with the same signature, return type, generic parameter constraints, etc. that calls the annotated method.
The generator even copies the XML documentation to the public method. 🤓

API Diff

I used Microsoft.DotNet.GenAPI (the tool generates a C# file representing the API of an assembly) to ensure that I didn't accidentally break the API surface.

A pre-generated diff is available in this gist. The only thing that changed is that the comparer parameter in the generated methods is now marked as nullable too which is a good change I think?

Instructions for verifying the API diff
  1. Install the Microsoft.DotNet.GenAPI package (this requires adding a custom NuGet feed)
    Here's a .patch file that installs Microsoft.DotNet.GenAPI (can be applied using git apply <patch-file>).
  2. Switch to the main branch
  3. Generate an API snapshot before the changes:
    dotnet build /p:GenerateReferenceAssemblySource=true /p:GenAPITargetPath=System.Linq.Async-before --framework netcoreapp3.1 --no-incremental Ix.NET/Source/System.Linq.Async
  4. Switch to this PR's branch
  5. Generate an API snapshot after the changes:
    dotnet build /p:GenerateReferenceAssemblySource=true /p:GenAPITargetPath=System.Linq.Async-after --framework netcoreapp3.1 --no-incremental Ix.NET/Source/System.Linq.Async
  6. Compare the changes:
    git diff --no-index -- Ix.NET/Source/System.Linq.Async/System.Linq.Async-before Ix.NET/Source/System.Linq.Async/System.Linq.Async-after

Unrelated changes

I found that having a solution filter that only opens projects needed for System.Linq.Async to be really helpful while working on System.Linq.Async. I can revert the commit ba8ba26 if you don't want the solution filter checked into the repo.

bash added 30 commits June 22, 2021 18:15
@bartdesmet
Copy link
Collaborator

Thanks for your contribution. This simplifies and modernizes the code significantly and sets a good example for future source generators in this space (e.g. the generation of expression tree based "queryable" variants of operators, which is a bit more involved).

@bartdesmet bartdesmet merged commit 1ff45fb into dotnet:main Aug 24, 2021
@bash bash deleted the async-overloads-source-generator branch August 24, 2021 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants