Skip to content

Add dependency for generic array interface type - #127278

Closed
MichalStrehovsky wants to merge 2 commits into
mainfrom
MichalStrehovsky-patch-1
Closed

MichalStrehovsky wants to merge 2 commits into
mainfrom
MichalStrehovsky-patch-1

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings April 22, 2026 13:36
@MichalStrehovsky MichalStrehovsky added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Apr 22, 2026
@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.

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

Adds a missing dependency edge in the AOT compiler’s EEType dependency analysis so that constructed generic interface EETypes that are specially implemented by arrays also ensure the corresponding array EEType is present.

Changes:

  • When emitting a constructed EEType for a “generic array interface type” (e.g., interfaces implemented by T[]), add a dependency on the constructed EEType for T[].

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings April 22, 2026 14:04
@MichalStrehovsky
MichalStrehovsky deleted the MichalStrehovsky-patch-1 branch April 22, 2026 14:07

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

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

Comment on lines +36 to +39
if (factory.TypeSystemContext.IsGenericArrayInterfaceType(_type) && _type.Instantiation[0].IsEnum)
{
dependencyList.Add(factory.ConstructedTypeSymbol(_type.Instantiation[0].MakeArrayType()), "Generic interface implemented by arrays");
}

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a new dependency edge for generic array interfaces instantiated over enums, but there doesn't appear to be a regression test that would fail without this change (e.g., an ILCompiler.Compiler.Tests DependencyGraph test asserting that using IList roots the constructed EEType for MyEnum[] even when MyEnum[] is never otherwise referenced). Adding a targeted test would help prevent future dependency analysis regressions in this area.

Copilot uses AI. Check for mistakes.
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Copilot Code Review — PR #127278

Note

This review was generated by GitHub Copilot using Claude Opus 4.6, with a GPT-5.3-codex sub-agent contributing additional analysis. A Claude Sonnet 4.6 sub-agent timed out and did not contribute.

Holistic Assessment

Motivation: The change addresses a NativeAOT dependency graph gap where constructing a generic array interface type (IList<MyEnum>, ICollection<MyEnum>, etc.) for an enum type argument does not automatically pull in the corresponding array type (MyEnum[]). This can cause runtime failures when the array type's full MethodTable is needed for variant interface casting or dispatch. Enum types are uniquely prone to this because enum arrays are rarely constructed by other dependency paths, unlike primitive arrays (int[], byte[]) which are almost always present.

Approach: The fix is minimal, well-placed in ComputeNonRelocationBasedDependencies, and follows the established pattern (identical to the rank-1 MdArray → SzArray dependency at line 55-59). The commit history shows the author first added an unconditional dependency for all generic array interfaces, then deliberately narrowed it to enum-only in a second commit — a reasonable binary-size tradeoff.

Summary: ⚠️ Needs Human Review. The code change is correct and consistent with codebase patterns, but the .IsEnum filter is narrower than the filter used in related code paths (VariantInterfaceMethodUseNode, IsArrayVariantCastable). A human reviewer should confirm whether the enum-only restriction is sufficient or whether the broader IsArrayElementTypeCastableBySize || reference-type filter is needed for completeness. Additionally: no linked issue, no PR description, and no regression test. Note that this PR is labeled NO-REVIEW, NO-MERGE, is a draft, and was closed without merging — it appears to be experimental.


Detailed Findings

✅ Correctness — Instantiation[0] access is safe

IsGenericArrayInterfaceType (in CompilerTypeSystemContext.Aot.cs:142-165) validates the type is an interface with exactly one instantiation argument before returning true. This makes _type.Instantiation[0] unconditionally safe in the guarded block. The resulting .MakeArrayType() produces a valid SzArray — types that cannot be array elements (void, ByRef, pointers, function pointers) cannot instantiate generic interface definitions, so they are excluded by construction. factory.ConstructedTypeSymbol() is the correct method to ensure a full MethodTable is emitted.

Both models confirmed this finding.

✅ Consistency — Pattern matches existing codebase conventions

The same ConstructedTypeSymbol(...MakeArrayType()) pattern is already used at line 59 for rank-1 MdArray → SzArray dependencies. The IsGenericArrayInterfaceType check is used in 5+ locations across EETypeNode.cs, VariantInterfaceMethodUseNode.cs, GenericDefinitionEETypeNode.cs, and CorInfoImpl.RyuJit.cs. The placement within ComputeNonRelocationBasedDependencies is correct for non-relocation dependencies.

Both models confirmed this finding.

⚠️ .IsEnum filter is narrower than related code — warrants verification (advisory)

The new check uses _type.Instantiation[0].IsEnum, but the closely related variant-casting code uses a broader filter:

// VariantInterfaceMethodUseNode.cs:134-137 and IsArrayVariantCastable:93-94
CastingHelper.IsArrayElementTypeCastableBySize(elementType) ||
    (elementType.IsDefType && !elementType.IsValueType);

This broader check covers:

  • All integer primitives (int, uint, byte, etc.) via IsArrayElementTypeCastableBySize
  • All enums (since UnderlyingType.Category maps to their backing integer)
  • All reference types via !elementType.IsValueType

The .IsEnum check covers only the enum subset. The author deliberately narrowed from unconditional to enum-only (visible in commit history), suggesting this was an intentional binary-size optimization targeting the specific failure case. However, if the same dependency-graph gap could theoretically affect other types (e.g., an obscure program with IList<nuint> constructed but no nuint[]), this filter would miss it.

Both models flagged this as a point for human verification.

💡 Missing regression test and linked issue

There is no linked issue describing the failing scenario and no regression test. For NativeAOT dependency graph fixes, a regression test that exercises the specific cast scenario (e.g., int[] is IList<SomeEnum> under NativeAOT) would help prevent regressions. The src/tests/nativeaot/ directory has precedent for such tests.

Both models suggested adding a test.

⚠️ Correction to prior automated review

The prior automated review on this PR stated the dependency is "unconditional" and could pull IList<MyStruct> → MyStruct[]. This is incorrect — the .IsEnum check on the second condition restricts this to enum types only. Non-enum value types like MyStruct would not trigger this dependency.


Models contributing: Claude Opus 4.6 (primary), GPT-5.3-codex (sub-agent). Claude Sonnet 4.6 sub-agent timed out.

Generated by Code Review for issue #127278 · ◷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclr NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants