Skip to content

Preserve information necessary to validate otherwise unused interface constraints in MakeGeneric - #132592

Open
MichalStrehovsky with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-static-virtual-methods-test-failure
Open

Preserve information necessary to validate otherwise unused interface constraints in MakeGeneric#132592
MichalStrehovsky with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-static-virtual-methods-test-failure

Conversation

CopilotAI commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

The problem was that we didn't preserve information necessary to do the constraint check in MakeGeneric:

  • Need to make sure we have metadata for the constraint (TypeMetadataNode change). Without this, the constraint could end up being an unresolvable TypeRef.
  • Need to make sure interface constraints are tracked as interface type uses. This is done by a small overapproximation: we consider the interface type reflected on. I originally tracked it as InterfaceUse but that only works in modes without scanner since InterfaceUse is not propagated across scanning/compilation boundary. Reflected types are. rt-sz measurement says this doesn't matter. GenericTypeDefinitionNode needed to report interface use to complete the "reflected type" -> "interface use" implication. Other EEType node already did that. rt-sz says this doesn't matter either.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
@MichalStrehovsky

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

CopilotAI 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

Updates the NativeAOT ILCompiler dependency analysis so generic-constraint information (metadata + interface-use tracking) is preserved when reflection-driven MakeGenericType / MakeGenericMethod flows require constraint validation.

Changes:

  • Preserve metadata dependencies for generic parameter constraints when generating type metadata.
  • Ensure reflection-visible generic interface definitions also contribute InterfaceUse so interface usage flows correctly across the scan/compile boundary.
  • Add constraint-driven dependency rooting for MakeGenericType / MakeGenericMethod dataflow handling; update the regression test project to no longer depend on TestLibrary.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/TypeMetadataNode.csAdds metadata dependencies for generic parameter constraint types.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericDefinitionEETypeNode.csEnsures reflection-visible generic interface definitions also record InterfaceUse.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/HandleCallAction.csRoots dependencies based on interface constraints when MakeGeneric* intrinsics are recognized.
src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_130545.csprojRemoves now-unneeded TestLibrary project reference.
src/tests/Loader/classloader/StaticVirtualMethods/Regression/GitHub_130545.csRemoves TestLibrary usage and the ActiveIssue skip.
Suppressed comments (1)

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/HandleCallAction.cs:160

  • Similarly for MakeGenericMethod: AddDependenciesFromConstraintUse runs before the arity check (inst.Length == methodInstantiated.Instantiation.Length). For malformed instantiation arrays that will fail at runtime, this still roots constraint interfaces. Consider moving it into the arity-match block to avoid unnecessary dependency growth.
 else if (!methodInstantiated.OwningType.IsGenericDefinition
&& TryGetMakeGenericInstantiation(_callingMethod, argumentValues[0], out Instantiation inst, out bool isExact))
{
AddDependenciesFromConstraintUse(_reflectionMarker, methodInstantiated.Instantiation);
if (inst.Length == methodInstantiated.Instantiation.Length)
{
methodInstantiated = methodInstantiated.MakeInstantiatedMethod(inst);

Comment on lines 77 to 83
else if (TryGetMakeGenericInstantiation(_callingMethod, argumentValues[0], out Instantiation inst, out bool isExact))
{
AddDependenciesFromConstraintUse(_reflectionMarker, typeInstantiated.Instantiation);

if (inst.Length == typeInstantiated.Instantiation.Length)
{
typeInstantiated = ((MetadataType)typeInstantiated).MakeInstantiatedType(inst);
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants

@MichalStrehovsky@jkotas