Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

Description

Type.GetGenericTypeDefinition() was not intrinsically recognized by ILLink trimming analysis, preventing annotation propagation in patterns like dependency injection where generic type definitions are used for service lookups.

Changes

Core intrinsic recognition:

  • Added Type_GetGenericTypeDefinition to IntrinsicId enum
  • Added pattern matching in Intrinsics.cs to detect GetGenericTypeDefinition() calls
  • Implemented dataflow handler in HandleCallAction.cs that propagates all DynamicallyAccessedMemberTypes annotations

Platform implementations:

  • Linker: GenericInstanceType.ElementTypeTypeDefinition
  • Roslyn Analyzer: INamedTypeSymbol.OriginalDefinition
  • NativeAOT: InstantiatedType.GetTypeDefinition()

Key behavior: Unlike BaseType which selectively propagates annotations, GetGenericTypeDefinition() propagates all annotations since the generic type definition contains identical members to the constructed type.

Example

// Before: IL2072 warning
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Type GetServiceType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type interfaceType)
{
    Type typeDef = interfaceType.IsGenericType ? interfaceType.GetGenericTypeDefinition() : interfaceType;
    // typeDef now correctly carries .All annotations
    return _services[typeDef]; 
}

Testing

  • Added GetGenericTypeDefinitionDataFlow test covering annotation propagation scenarios
  • Verified existing DependencyInjectionPattern test now works correctly
  • All 82 DataFlow tests pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Intrinsically recognize Type.GetGenericTypeDefinition</issue_title>
<issue_description>See suppression added in #94985.

Per the warning this was working around, the problem is that we didn't propagate annotations from _typeParent (annotated as .All).</issue_description>

Comments on the Issue (you are @copilot in this section)

@ Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in [area-owners.md](https://github.com/dotnet/runtime/blob/main/docs/area-owners.md) if you want to be subscribed.
Issue Details

See suppression added in #94985.

Per the warning this was working around, the problem is that we didn't propagate annotations from _typeParent (annotated as .All).

Author: MichalStrehovsky
Assignees: -
Labels:

area-Tools-ILLink

Milestone: -
@MichalStrehovsky > Oops, I didn't see this one when I opened #96898. Should we keep both open, or should we maybe close this one as a duplicate and just use the other one for tracking, since it's also already added to the milestone too?

You're asking for a JIT intrinsic. This is about intrinsic recognition in reflection use analysis. Different things.</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jan 22, 2026
Copilot AI and others added 4 commits January 22, 2026 00:11
Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix propagation of annotations in Type.GetGenericTypeDefinition Add intrinsic recognition for Type.GetGenericTypeDefinition Jan 22, 2026
Copilot AI requested a review from sbomer January 22, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Intrinsically recognize Type.GetGenericTypeDefinition

2 participants