Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate unconstructed EEType for arrays that have a template #113951

Merged
merged 1 commit into from
Mar 28, 2025

Conversation

MichalStrehovsky
Copy link
Member

Fixes #113750

When CanonFormTypeMayExist was written, it was okay for arrays to return false since arrays were always compared structurally (it was allowed to have multiple MethodTables for a single array type).

We stopped allowing this some time ago and we now have to maintain the same invariant as for any other MethodTable - the address of the MethodTable is the unique identity. We cannot allow the compiler to generate unconstructed MethodTable for something that can be template-constructed at runtime.

Cc @dotnet/ilc-contrib

When `CanonFormTypeMayExist` was written, it was okay for arrays to return false since arrays were always compared structurally (it was allowed to have multiple `MethodTable`s for a single array type).

We stopped allowing this some time ago and we now have to maintain the same invariant as for any other `MethodTable` - the address of the `MethodTable` is the unique identity. We cannot allow the
compiler to generate unconstructed `MethodTable` for something that can be template-constructed at runtime.
@Copilot Copilot bot review requested due to automatic review settings March 26, 2025 22:11
Copy link
Contributor

@Copilot Copilot AI left a comment

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 addresses issue #113750 by ensuring that unconstructed EETypes for arrays with a template are not generated, maintaining the invariant that a MethodTable's address uniquely identifies it. Key changes include adding a new regression test in the SmokeTests to cover this scenario and modifying the EETypeNode logic to correctly handle array types.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs Adds the Test113750Regression to validate array behavior under the new invariant
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs Replaces a generic instantiation check with a specific array type check to enforce the invariant
Comments suppressed due to low confidence (1)

src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs:1217

  • Throwing a plain Exception without a message can make debugging harder. Consider including a descriptive message to clarify the failure condition.
if (!(arr is Atom[]))

Comment on lines +1208 to +1209
class Atom;

Copy link
Preview

Copilot AI Mar 26, 2025

Choose a reason for hiding this comment

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

The declaration 'class Atom;' is incomplete in C# and may cause a compilation error. It should be defined with a body, e.g., 'class Atom { }'.

Suggested change
class Atom;
class Atom { }

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@@ -253,7 +253,7 @@ private bool CanonFormTypeMayExist
{
get
{
if (!_type.HasInstantiation)
if (_type.IsArrayTypeWithoutGenericInterfaces())
Copy link
Preview

Copilot AI Mar 26, 2025

Choose a reason for hiding this comment

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

Consider adding a clarifying comment here to explain why array types without generic interfaces should immediately return false, aiding future maintenance.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@MichalStrehovsky
Copy link
Member Author

/ba-g timeouts in unrelated leg

@MichalStrehovsky MichalStrehovsky merged commit 156b92d into dotnet:main Mar 28, 2025
101 of 103 checks passed
@MichalStrehovsky MichalStrehovsky deleted the fix113750 branch March 28, 2025 07:42
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.

[NativeAOT] Bug: Array.CreateInstance method not working as expected
2 participants