Repository navigation
Managed ilasm: avoid unused ValueType references - #136679
Merged
jkoritzinsky merged 1 commit intoOct 30, 2026
Merged
Conversation
For an unsealed class, the unsealed value type check read EntityRegistry.SystemValueTypeType. That getter creates a TypeRef to System.ValueType on first use, so an image with an unsealed class carried the reference even when nothing used it. Native ilasm does not create the reference just to check a class. Recognize System.ValueType by name and check its scope against the core library references. Find those references with the registry's lookup, which creates nothing. The old check compared against the getter's single cached reference. It missed an unsealed value type whose base type used a different core library reference, such as one declared later. The new check reports it.
|
Azure Pipelines: Successfully started running 4 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. |
jkoritzinsky
approved these changes
Oct 30, 2026
jkoritzinsky
enabled auto-merge (squash)
October 30, 2026 04:13
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
Contributor
Author
|
Thank you for the review and merge! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The managed ilasm adds a
TypeReftoSystem.ValueTypeto every image that declares an unsealed class, even when nothing in the image uses it. Native ilasm does not create the reference just to check a class.I found the difference while comparing managed and native ilasm output for #135314. The extra reference is valid metadata. In images that do not need it, it adds an unnecessary
TypeRefrow and name. It also adds a difference between the two assemblers' output.The cause is the unsealed value type check in
InitializeTypeDefinition. For an unsealed class, it compares the base type withEntityRegistry.SystemValueTypeType, and that getter creates the reference on first use. The check now calls a newEntityRegistry.IsSystemValueType. It recognizes aSystem.ValueTypereference whose scope is one of the core library references (System.Private.CoreLib,System.Runtime,mscorlibornetstandard). The helper usesFindAssemblyReferenceto find the core library references, preserving the existing handling of case and aliases. It creates no references.The old check compared the base type with the one reference the getter cached. The old check missed an unsealed type extending another core library's
System.ValueType, for example when a later.assembly externchanged the preferred core library. The new check reportsUnsealedValueTypefor those types too. Every type the old check reported is still reported.Tests, in
TypeDefinitionTests:System.ValueTypereference;System.ValueTypeis reported for each core library name, including one with different capitalization and one referenced through an alias;System.ValueTypethrough a.typedefis reported even when a later core library reference becomes preferred;System.ValueTypeis reported when a core library reference is declared after an earlier class or value type.ILAssembler.Tests: 5728 passed, 0 failed. I also checked which tests fail with the old comparison and with deliberately incorrect versions of the new check:.typedeftest cases;I assembled three
src/testscases with a previously built baseline managed ilasm and with this change. With this change,Conv_I4anddev10_710121no longer contain theValueTypestring.cpobj(unaligned/1) declares a value type and keeps the string. All three return 100 on the shared framework with either build.Note
This change was prepared with AI assistance (Anthropic Claude and OpenAI Codex) under my direction. AI agents ran the builds and tests on my machine. I reviewed the change and this description before posting.