Skip to content

Preserve explicit value-type signatures in managed ILAsm - #137095

Merged
jkoritzinsky merged 3 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-intptr-signature-compatibility
Nov 7, 2026
Merged

jkoritzinsky merged 3 commits into
dotnet:mainfrom
jkoritzinsky:dev/jkoritzinsky/ilasm-intptr-signature-compatibility

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Preserve explicit valuetype references in managed ILAsm signatures instead of replacing well-known primitive value types with short-form type codes. This matches native ILAsm and allows compiler tests to assemble deliberately malformed long-form signatures. Primitive keywords such as native int retain their short-form encodings; existing class System.String and class System.Object handling is unchanged.

The AddressOf<T> fixture returning valuetype [mscorlib]System.IntPtr previously emitted 10010118101E00. It now emits 1001011109101E00, identical to native ILAsm, restoring C# diagnostic CS0570 (ERR_BindToBogus) in a standalone consumer. Regression coverage checks all well-known primitive value-type fields and explicit versus shorthand native-integer generic returns.

Validation on Windows x64 at commit 2c5fb98c916:

  • .\build.cmd tools.ilasm -c Release -test — passed, 0 build warnings/errors; 5,801 tests total, 0 failures, 3 platform skips.
  • .\.dotnet\dotnet.exe test src\tools\ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj -c Release --no-build --filter 'FullyQualifiedName~WellKnownValueType_PreservesExplicitTypeReference|FullyQualifiedName~NativeIntegerGenericMethod_PreservesReturnTypeEncoding' — passed, 20 tests, 0 skips. Before the fix, 17 of these cases failed.
  • Assembled the fixture with native ILAsm and managed ILAsm before/after the fix and compiled standalone C# consumers: native and fixed managed output produce CS0570; unfixed managed output compiles without that diagnostic.

The original Roslyn test suite was not run, and its checkout was not modified.

Note

This pull request description and code changes were generated with GitHub Copilot.

Match native ILAsm by retaining explicit valuetype references, including intentionally malformed long-form primitive signatures. Cover native-integer generic returns and all well-known primitive value-type fields.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-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.

🟢 Approval recommended

No active review issues are reported for the change preserving explicit value-type signatures in managed ILAsm.

No open issues 🎉

What changed in this PR

This PR aligns managed ILAsm with native ILAsm by preserving explicit valuetype references, allowing compiler tests to assemble deliberately malformed long-form primitive signatures.

Changes:

  • Prevents explicit value-type references from being replaced with primitive type codes, while preserving shorthand and existing String/Object handling.
  • Expands field-signature coverage and adds generic-method tests distinguishing explicit native-integer returns from shorthand encodings.
  • Documents the signature-preservation behavior.
File Description
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeSignatureTests.cs Adds explicit versus shorthand native-integer return tests.
src/​tools/​ilasm/​tests/​ILAssembler.Tests/​TypeDefinitionTests.cs Verifies explicit type references for 16 well-known value types.
src/​tools/​ilasm/​src/​ILAssembler/​Actions/​GrammarActions.Signatures.Types.cs Bypasses primitive-code substitution for explicit value types.
src/​tools/​ilasm/​MANAGED-ILASM-FIXES.md Documents native ILAsm compatibility and shorthand usage.

Review effort: Balanced

Comment thread src/tools/ilasm/MANAGED-ILASM-FIXES.md Resolved
Rename the normalization helper and explain the Object/String compatibility rule. Remove the documentation entry describing behavior shared with native ILAsm.

Co-authored-by: Copilot App <[email protected]>
@jkoritzinsky
jkoritzinsky requested a review from jkotas November 6, 2026 21:52
@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) November 6, 2026 22:18
@jkoritzinsky
jkoritzinsky merged commit cc9272b into dotnet:main Nov 7, 2026
58 of 60 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Nov 7, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants