Skip to content

Clarify struct-to-enum breaking changes and R2R cast folding - #137100

Merged
AaronRobinsonMSFT merged 6 commits into
mainfrom
copilot/clarify-breaking-change-rules
Nov 7, 2026
Merged

AaronRobinsonMSFT merged 6 commits into
mainfrom
copilot/clarify-breaking-change-rules

Conversation

Copilot AI commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

The breaking-change rules did not explicitly prohibit converting between a struct and an enum, though R2R relies on that distinction remaining stable across version bubbles.

  • Rules: Marked conversions between struct and enum as disallowed.
  • R2R: Removed the enum exception from negative-cast resilience:
    if (fromType.IsValueType && !toType.IsInterface)
  • Coverage: Added an R2R cast-folding regression case for a struct cast to System.Enum.

@azure-pipelines

azure-pipelines Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 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: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
Copilot AI changed the title [WIP] Clarify breaking change for struct to enum conversion Clarify struct-to-enum breaking changes and R2R cast folding Nov 6, 2026
@AaronRobinsonMSFT

Copy link
Copy Markdown
Member

@copilot Please examine the failures on this PR.

Copilot AI commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please examine the failures on this PR.

I examined the failed checks. Eight jobs across runtime build 1668155 and runtime-dev-innerloop build 1668156 fail with CS1929 at src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs (lines 6789, 6843, 7084): ReadOnlySpan<byte> has no AsSpan method. Those lines are already present in the PR’s base commit, and this file is outside the PR diff, so this does not appear to be caused by this change. The failures need follow-up in the CDAC area; I don’t see a change warranted in this PR. The Linux and Windows x64 R2R test jobs passed, and the Helix monitor reported zero failed work items.

@jkotas

jkotas commented Nov 6, 2026

Copy link
Copy Markdown
Member

the failures on this PR.

Build break is fixed in main.

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 identified for the ReadyToRun cast-folding compatibility update.

No open issues 🎉

What changed in this PR

This PR aligns ReadyToRun cast folding with the clarified compatibility rule that structs and enums cannot be converted into one another across versions, addressing #137055.

Changes:

  • Explicitly disallows changing a struct to an enum or vice versa.
  • Removes the System.Enum exception from negative-cast version-resilience checks.
  • Adds a struct-to-System.Enum regression case and checks that folding avoids importing System.Enum.
File Description
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun/​JitInterface/​CorInfoImpl.ReadyToRun.cs Simplifies value-type negative-cast resilience logic and updates its comment.
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun.Tests/​TestCases/​R2RTestSuites.cs Asserts that System.Enum is absent from imported types.
src/​coreclr/​tools/​aot/​ILCompiler.ReadyToRun.Tests/​TestCases/​CastFolding/​CastFolding.cs Adds the struct-to-enum cast-folding test case.
docs/​coding-guidelines/​breaking-change-rules.md Explicitly prohibits conversions between structs and enums.

Review effort: Balanced

Added changing a struct to an enum or vice versa as a breaking change.
@AaronRobinsonMSFT
AaronRobinsonMSFT marked this pull request as ready for review November 7, 2026 03:40
Co-authored-by: AaronRobinsonMSFT <30635565+AaronRobinsonMSFT@users.noreply.github.com>
@AaronRobinsonMSFT
AaronRobinsonMSFT enabled auto-merge (squash) November 7, 2026 04:26
@jkotas

jkotas commented Nov 7, 2026

Copy link
Copy Markdown
Member

/ba-g build analysis stuck

@AaronRobinsonMSFT
AaronRobinsonMSFT merged commit 2d457a6 into main Nov 7, 2026
103 checks passed
@AaronRobinsonMSFT
AaronRobinsonMSFT deleted the copilot/clarify-breaking-change-rules branch November 7, 2026 19:18
@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
Status: Done

Development

Successfully merging this pull request may close these issues.

Clarify in breaking-change rules and R2R that converting a struct to an enum is a breaking change

5 participants