Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Aug 18, 2025

This seems to be the only reason why Hello World on Linux still needs support for boxed enums. CreateSpan is used with an enum type in Unix System.Console, which brings a boxed enum into whole program view and we can't undo the damage this causes to the whole program view during compilation anymore (even though we no longer need the typeof then because RyuJIT always expands CreateSpan).

Project Size before Size after Difference
hello-linux 1221600 1151440 -70160
hello-minimal-linux 1069896 999736 -70160

This seems to be at least one of the reasons why Hello World on Linux still needs support for boxed enums. `CreateSpan` is used with an enum type in Unix System.Console, which brings a boxed enum into whole program view and we can't undo the damage this causes to the whole program view during compilation anymore (even though we no longer need the `typeof` then because RyuJIT always expands `CreateSpan`).
Copilot AI review requested due to automatic review settings August 18, 2025 05:24
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 optimizes NativeAOT compilation by avoiding unnecessary type reflection marking in the CreateSpan<T> method. The change prevents enum types from being marked as reflected-on when CreateSpan is called, which was causing unnecessary bloat in Hello World applications on Linux that required support for boxed enums.

Key Changes:

  • Moves the PlatformNotSupportedException throw earlier in the call chain for NativeAOT to avoid executing typeof(T).TypeHandle
  • Removes the unused GetSpanDataFrom helper method from the NativeAOT-specific implementation
  • Adds conditional compilation to handle the method differently between NativeAOT and other runtimes

Reviewed Changes

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

File Description
RuntimeHelpers.cs Adds NativeAOT-specific conditional compilation to throw exception before type reflection occurs
RuntimeHelpers.NativeAot.cs Removes unused GetSpanDataFrom helper method that was only throwing exceptions

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@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

Project Size before Size after Difference
hello-linux 1221600 1151440 -70160
hello-minimal-linux 1069896 999736 -70160

@jkotas
Copy link
Member

jkotas commented Aug 19, 2025

/ba-g infrastructure timeout (Mono_MiniJIT_LibrariesTests running for 8 hours)

@jkotas jkotas merged commit d53785b into dotnet:main Aug 19, 2025
141 of 145 checks passed
@MichalStrehovsky MichalStrehovsky deleted the createspan branch August 19, 2025 04:14
@MichalStrehovsky
Copy link
Member Author

/backport to release/10.0

@github-actions
Copy link
Contributor

@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2025
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