Skip to content

Generate less metadata for generic compositions - #130842

Merged
MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:genericcompo
Sep 3, 2026
Merged

MichalStrehovsky merged 2 commits into
dotnet:mainfrom
MichalStrehovsky:genericcompo

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Something I noticed as I was working on #129609. I don't think we need fully constructed MethodTable for composition information (neither for types, nor for generic virtual methods).

Something I noticed as I was working on dotnet#129609. I don't think we need fully constructed `MethodTable` for composition information (neither for types, nor for generic virtual methods).
Copilot AI lite review requested due to automatic review settings July 16, 2026 04:37
@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.

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 adjusts NativeAOT (ILCompiler) dependency analysis so “generic composition” data can be emitted without forcing fully constructed EEType / MethodTable nodes, by introducing a “metadata-enabled” path for generic compositions and type arguments.

Changes:

  • Renamed the “constructed” generic composition cache/API to “metadata-enabled” and routed relevant emit sites to use it.
  • Added MaximallyMetadataEnabledType to pick metadata-capable EEType symbols for generic composition arguments without requiring fully constructed types.
  • Updated EEType instantiation detail emission and GVM dispatch cell info emission to use metadata-enabled compositions/types.

Reviewed changes

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

File Description
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs Adds MaximallyMetadataEnabledType, renames/rewires generic composition caches to “metadata-enabled”.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GvmDispatchCellInfoSectionNode.cs Switches GVM instantiation info emission/deps to metadata-enabled generic composition.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericCompositionNode.cs Renames flag to metadataEnabled and uses MaximallyMetadataEnabledType for arg EEType selection.
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs Uses metadata-enabled generic composition/types when emitting reflection-visible instantiation details.

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines

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

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "a08f92830065e3817b4a0837cb0f4093ea235efc",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "f2281d59e62aa6a75e53055b8f842bac108b9887",
  "last_reviewed_commit": "a08f92830065e3817b4a0837cb0f4093ea235efc",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "f2281d59e62aa6a75e53055b8f842bac108b9887",
  "last_recorded_worker_run_id": "29684896025",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "a08f92830065e3817b4a0837cb0f4093ea235efc",
      "review_id": 4730669188
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: MethodTables referenced by generic composition information (for generic types and generic virtual methods) were being emitted as fully constructed types, which pulls in more metadata than is actually needed. Composition info only needs enough of a MethodTable to be metadata-enabled, not fully constructed. The author noticed this while working on #129609, so the goal is a straightforward size/metadata optimization for NativeAOT output.

Approach: The PR renames the constructed concept in generic composition to metadataEnabled and introduces two new NodeFactory helpers: MaximallyMetadataEnabledType(TypeDesc) (returns NecessaryTypeSymbol for canonical-definition types, otherwise MetadataTypeSymbol) and MetadataEnabledGenericComposition(Instantiation). Call sites in EETypeNode, GvmDispatchCellInfoSectionNode, and GenericCompositionNode are switched from the Constructed* variants to the new MetadataEnabled* variants, and the backing node cache/field (_constructedGenericCompositions → _metadataEnabledGenericCompositions) plus the GenericCompositionNode._constructed flag are renamed consistently.

Summary: This is a focused, low-risk change confined to the NativeAOT (ILCompiler) dependency-analysis layer. The renames are applied consistently across the node, factory, cache, and comparison (CompareToImpl) paths, so node identity/ordering semantics are preserved. The new MaximallyMetadataEnabledType correctly mirrors MaximallyConstructableType's canonical-type fallback via IsCanonicalDefinitionType, and generic-composition type arguments are concrete or canonical instantiation types — not generic definitions or synthetic AsyncContinuationTypes — so the tightened Debug.Asserts inside MetadataTypeSymbol are not expected to trip. The author has run runtime-nativeaot-outerloop to exercise the affected code paths, which is the appropriate validation for a metadata-reduction change of this kind. No correctness or maintainability concerns were found. LGTM.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 54.3 AIC · ⌖ 10.3 AIC · ⊞ 10K

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 1, 2026 04:28

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.

🔵 Needs a closer look

Review details

Suppressed comments (1)

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:831

  • MaximallyMetadataEnabledType unconditionally calls MetadataTypeSymbol for non-canonical types, but MetadataTypeSymbol asserts that AsyncContinuationType is not passed (see Debug.Assert in MetadataTypeSymbol). Prior code paths using MaximallyConstructableType would route AsyncContinuationType to ConstructedTypeSymbol, so this introduces a potential debug-build assert/regression if an instantiation/composition contains AsyncContinuationType. Consider mirroring the existing special-case handling to keep behavior consistent and avoid the assert.
        public IEETypeNode MaximallyMetadataEnabledType(TypeDesc type)
        {
            if (type.IsCanonicalDefinitionType(CanonicalFormKind.Any))
                return NecessaryTypeSymbol(type);
            else
                return MetadataTypeSymbol(type);
        }
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@MichalStrehovsky

Copy link
Copy Markdown
Member Author

@jkotas could you please reapprove? there was a merge conflict and the approval got reset :(

@MichalStrehovsky
MichalStrehovsky merged commit 8d1b156 into dotnet:main Sep 3, 2026
105 of 107 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the genericcompo branch September 3, 2026 00:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants