Fix dataflow analysis for MakeGenericType/MakeGenericMethod in local methods#127152
Open
Fix dataflow analysis for MakeGenericType/MakeGenericMethod in local methods#127152
Conversation
…methods Associate each runtime-determined dependency with the method it originates from (the actual IL method being scanned), rather than treating all dependencies as belonging to the parent user method. In SearchDynamicDependencies, match marked method bodies against the dependency's owning method instead of only the analyzed (parent) method. This ensures that when a local method like MakeGeneric<Atom> is compiled, its MakeGenericTypeSite dependencies are correctly instantiated with the local method's generic arguments. Fixes #115552 Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/81f1c59a-c2ca-4ab8-ae7d-e8edded14d1c Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix dataflow analysis for MakeGeneric use in local methods
Fix dataflow analysis for MakeGenericType/MakeGenericMethod in local methods
Apr 20, 2026
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
This was referenced Apr 20, 2026
MichalStrehovsky
approved these changes
Apr 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes NativeAOT dataflow/runtime-dependency instantiation for MakeGenericType/MakeGenericMethod when the intrinsic call occurs in compiler-generated nested functions (e.g., local methods), by tracking which method a runtime dependency originated from and matching specializations against that method.
Changes:
- Track runtime-determined dependencies as
(OwningMethod, Dependency)pairs and record the calling method when creatingMakeGenericTypeSite/MakeGenericMethodSite. - Update dynamic dependency instantiation to match against each marked method body’s typical definition (including compiler-generated nested functions).
- Add a regression smoke test covering
MakeGenericTypeandMakeGenericMethodfrom static local methods.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/TrimmingBehaviors/Dataflow.cs | Adds regression test exercising MakeGenericType/MakeGenericMethod inside static local methods. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DataflowAnalyzedMethodNode.cs | Matches and instantiates runtime deps based on recorded owning method rather than only the parent analyzed method. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMethodBodyScanner.cs | Updates scan API to return owning-method-tagged runtime dependencies. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMarker.cs | Stores runtime-determined dependencies with their owning method. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/HandleCallAction.cs | Tags MakeGenericTypeSite/MakeGenericMethodSite runtime deps with the calling method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Dataflow analysis associates
MakeGenericTypeSite/MakeGenericMethodSiteruntime dependencies with the parent user method, butSearchDynamicDependenciesonly matches compiled method bodies against that parent. When theMakeGenericTypecall lives in a compiler-generated local method, the local method'sGetTypicalMethodDefinition()differs from the parent, so the dependency is never instantiated.Fix: Track which method each runtime dependency originated from and match against it:
ReflectionMarker.RuntimeDeterminedDependenciesnow stores(MethodDesc OwningMethod, INodeWithRuntimeDeterminedDependencies Dependency)tuplesHandleCallActiontags eachMakeGenericTypeSite/MakeGenericMethodSitewith_callingMethodDataflowAnalyzedMethodNode.SearchDynamicDependenciesmatches each marked method body's typical definition against the dependency's owning method, rather than only the analyzed parent methodAdded regression test
TestMakeGenericDataflowInLocalMethodcovering bothMakeGenericTypeandMakeGenericMethodfrom static local methods.