Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Aug 7, 2025

...even if there's no member access following the call.

This was found in https://github.com/dotnet/runtime/pull/118060/files#r2247963234 but the test case I'm adding is also failing in .NET 9 and doesn't require an IL-only repro to hit because all we need is a struct.

...even if there's no constructor.

This was found in https://github.com/dotnet/runtime/pull/118060/files#r2247963234 but the test case I'm adding is also failing in .NET 9 and doesn't require an IL-only repro to hit.
@MichalStrehovsky MichalStrehovsky requested a review from sbomer August 7, 2025 08:59
Copilot AI review requested due to automatic review settings August 7, 2025 08:59
Copy link
Contributor

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 fixes a bug in the NativeAOT compiler where types with required constructors weren't being marked as allocated when they have no actual constructor methods. The fix ensures that types requiring constructors (like structs) are properly marked as allocated during reflection analysis, even when no constructor is found.

Key changes:

  • Added explicit allocation marking for types with constructor requirements
  • Added test coverage for struct activation scenarios without constructors
  • Changed a test attribute from conditional to unconditional

Reviewed Changes

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

File Description
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/ReflectionMarker.cs Added allocation marking for types requiring constructors in two methods to ensure they're considered allocated even without explicit constructors
src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs Added comprehensive test case for struct activation scenarios using various methods like Activator.CreateInstance and RuntimeHelpers.GetUninitializedObject
src/libraries/Common/tests/System/Security/Cryptography/MLKemCngTests.NotSupported.cs Changed test attribute from conditional to unconditional

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky
Copy link
Member Author

Ooof, a bit more than expected. The fact that the struct constraint is actually emitted as struct, new() by Roslyn is biting us here.

Size statistics

Project Size before Size after Difference
TodosApi-linux 24208648 24272680 64032
TodosApi-windows 25525760 25611776 86016
avalonia.app-linux 18799408 18870432 71024
avalonia.app-windows 19328000 19403264 75264
hello-linux 1364944 1423456 58512
hello-minimal-linux 1094456 1144776 50320
hello-minimal-windows 840192 888832 48640
hello-windows 1138176 1199616 61440
kestrel-minimal-linux 5201560 5240632 39072
kestrel-minimal-windows 4745728 4785664 39936
reflection-linux 1964096 2006240 42144
reflection-windows 1823232 1870336 47104
webapiaot-linux 9678448 9725760 47312
webapiaot-windows 10244608 10302976 58368
winrt-component-full-windows 6678016 6727168 49152
winrt-component-minimal-windows 1708032 1743360 35328

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Aug 8, 2025
We don't need reflection metadata to answer this.

Change salvaged out of dotnet#118479, rt-sz will decide if we want it.
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Aug 8, 2025
I'm not completely sure this is a fine assumption to make (we're assuming something that RyuJIT should do). Wanted to collect numbers if this is worth pursuing.

Change salvaged out of dotnet#118479, rt-sz will decide if we want to pursue it.
@MichalStrehovsky
Copy link
Member Author

Much better now. Tge regression in Avalonia is caused by tons of Func/Action delegates used with MakeGeneric in S.L.Expressions implementation. It fixes a correctness issue:

Size statistics

Pull request #118479

Project Size before Size after Difference
TodosApi-linux 24212744 24212744 0
TodosApi-windows 25526272 25526272 0
avalonia.app-linux 18799408 18873760 74352
avalonia.app-windows 19328000 19406336 78336
hello-linux 1364944 1364944 0
hello-minimal-linux 1094456 1094456 0
hello-minimal-windows 840192 840192 0
hello-windows 1138176 1138176 0
kestrel-minimal-linux 5201560 5201560 0
kestrel-minimal-windows 4745728 4745728 0
reflection-linux 1964096 1964096 0
reflection-windows 1823232 1823232 0
webapiaot-linux 9678448 9678448 0
webapiaot-windows 10244608 10244608 0
winrt-component-full-windows 6678016 6678016 0
winrt-component-minimal-windows 1708032 1708032 0

@MichalStrehovsky MichalStrehovsky changed the title Ensure we consider types with required constructors allocated Ensure we track MakeGenericType Aug 12, 2025
@MichalStrehovsky MichalStrehovsky merged commit ce10f6f into dotnet:main Aug 12, 2025
95 of 98 checks passed
@MichalStrehovsky MichalStrehovsky deleted the constructedwithoutctor branch August 12, 2025 04:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants