Skip to content

Track async variants when generating generic dictionaries - #121573

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:genericasyncfixes
Nov 13, 2025
Merged

MichalStrehovsky merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:genericasyncfixes

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

In GenericDictionaryNode we have a piece of code that ensures whenever a canonical method body of a method on a type depends on something and we have a concrete instance of such type, the specialized thing is also created.

For example, class Foo<T> { Type GrabType() => typeof(List<T>); }: when we compile Foo<__Canon>.GrabType we find out we need List<T>. Elsewhere we find out we need Foo<object>. The code in GenericDictionaryNode that I'm modifying ensures we also generate List<object>.

We do this by walking all methods on the type and generating special ShadowConcrete dependencies for any canonical bodies of the methods on the type. We were missing async variants from this reporting.

The change in EETypeNode is related, but only affects multifile compilation that we don't care much about. I'm fixing it because it has the same problem.

Cc @dotnet/ilc-contrib

In `GenericDictionaryNode` we have a piece of code that ensures whenever a canonical method body of a method on a type depends on something and we have a concrete instance of such type, the specialized thing is also created.

For example, `class Foo<T> { Type GrabType() => typeof(List<T>); }`: when we compile `Foo<__Canon>.GrabType` we find out we need `List<T>`. Elsewhere we find out we need `Foo<object>`. The code in GenericDictionaryNode that I'm modifying ensures we also generate `List<object>`.

We do this by walking all methods on the type and generating special `ShadowConcrete` dependencies for any canonical bodies of the methods on the type. We were missing async variants from this reporting.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors and extends the handling of async method variants in the AOT compiler's dependency analysis to ensure that async variants are properly tracked when generating generic dictionaries and type dependencies.

Key Changes:

  • Introduces a new extension method GetAllMethodsAndAsyncVariants() to make async variant enumeration reusable
  • Updates GenericDictionaryNode and EETypeNode to include async variants in their dependency tracking
  • Refactors WithAsyncVariants from a nested loop into a standalone internal method for broader reusability

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
CompilerTypeSystemContext.Async.cs Adds GetAllMethodsAndAsyncVariants() extension method and refactors WithAsyncVariants() into a reusable internal method with enhanced logic to handle both virtual and non-virtual async methods
GenericDictionaryNode.cs Updates dependency tracking to use GetAllMethodsAndAsyncVariants() instead of GetAllMethods(), ensuring async method variants are included in generic dictionary dependencies
EETypeNode.cs Updates multifile compilation dependency tracking to use GetAllMethodsAndAsyncVariants(), ensuring async variants are exported when types are shared across modules

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/ba-g timeouts

@MichalStrehovsky
MichalStrehovsky merged commit 824a87f into dotnet:main Nov 13, 2025
@MichalStrehovsky
MichalStrehovsky deleted the genericasyncfixes branch November 13, 2025 20:57
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants