Skip to content

[release/11.0] ILC: only keep type loader candidate type map entries when their generic arguments are present - #137857

Open
Sergio0694 wants to merge 2 commits into
dotnet:release/11.0from
Sergio0694:user/sergiopedri/ilc-gate-type-map-keys-release-11-0
Open

Sergio0694 wants to merge 2 commits into
dotnet:release/11.0from
Sergio0694:user/sergiopedri/ilc-gate-type-map-keys-release-11-0

Conversation

@Sergio0694

@Sergio0694 Sergio0694 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #137541 to release/11.0

Customer Impact

  • Customer reported
  • Found internally

20+% size regression when compiling Microsoft Store with .NET 11 compared to .NET 10.

Regression

  • Yes
  • No

Interop type maps had an analysis hole where we would not keep type map entries for types that could be loaded dynamically at runtime (as opposed to types that are statically present at compile time). The holes were fixed in #123031 and #126382, however the fix was rather conservative: keep type map entries if a type loader template exists for the type. The conservative choice caused impossible types to be kept, leading to the size regression beyond what's reasonable (it was known these correctness fixes would be size regressions).

This PR further restricts the rule to "type loader template exists and types used as generic arguments could exist".

Testing

Targeted trimming test was added.

Why this was missed: There was no data on Windows Store size with .NET 11 before we shipped GA. We have not seen regressions in other interop scenarios that use type maps (iOS/Android) and we measure, likely because they don't have generics at all.

Risk

The risk is low. The additional restriction makes sense, the fix is obvious, and was validated E2E with Store.

…ric arguments are present

Backport of dotnet#137541 to release/11.0.

Two ILC rules eagerly construct every generic type map key whose canonical form has a type loader template: the proxy type map rule added by dotnet#123031, and RuntimeConstructableTypeDependencies.AddTypeLoaderDependencies, called for external type map entries and unmanaged entry point source types. With a large number of generic instantiations (such as the CsWinRT 3.0 interop type maps) this keeps a large number of types alive.

Only construct such a type if every generic argument is present in the compilation or can itself be created by the type loader. This is expressed with a chain of TypeLoaderArgumentGateNode conditional dependencies, one per argument, since a conditional dependency can only be conditioned on a single node. The element type of an array is treated as its only argument.

This adapts the change to the dependency analysis API in release/11.0 (GetConditionalStaticDependencies returning IEnumerable instead of the DependencySink based API in main) and adds the TestInteropMapTypeLoaderKeys smoke test.

Co-authored-by: Copilot App <[email protected]>
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 18, 2026
@teo-tsirpanis teo-tsirpanis added this to the 11.0.0 milestone Nov 18, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 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.

@MichalStrehovsky

Copy link
Copy Markdown
Member

Could you update this to match the PR in main? Copilot says:

The compiler changes appear equivalent after the API adaptation, but the backport is missing the original PR’s final test updates: multi-argument cases and changes that prevent proxy and external tests from masking each other’s failures.

Not identical: the backport omits the original PR’s final test updates. Its DeadCodeElimination.cs is byte-for-byte identical to the version before those updates.

The unexpected differences are:

  • Missing multi-argument coverage: all ten proxy/external cases covering both arguments present, either argument missing, both loadable, and loadable-plus-missing.
  • Missing test isolation: proxy and external cases share Wrapper<Atom>, Atom[], and GenericStruct<Atom>[]. Main uses distinct arguments so retaining one map’s key cannot mask a failure in the other.

Across the five compiler/project files, I found no differences beyond the expected dependency-analysis API adaptations. The test file can be copied unchanged from the merged original.

Backport of the final test update of dotnet#137541: add the multi-argument cases for the proxy and external type map rules, and use distinct generic arguments for the proxy and external cases so retaining one map's key cannot mask a failure in the other.

Co-authored-by: Copilot App <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants