Skip to content

Remove unsafe code from Guid.TryFormat - #121652

Closed
EgorBo wants to merge 4 commits into
dotnet:mainfrom
EgorBo:remove-unsafe-guid
Closed

EgorBo wants to merge 4 commits into
dotnet:mainfrom
EgorBo:remove-unsafe-guid

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 15, 2025

Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 15, 2025
@EgorBo EgorBo added area-System.Runtime reduce-unsafe and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 15, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

internal bool TryFormatCore<TChar>(Span<TChar> destination, out int charsWritten, int flags)
where TChar : unmanaged, IUtfChar<TChar>
{
Span<TChar> dest = destination;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a tracking issue for the need to cache this in a local?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I didn't want to advertise it as a hack, it should be fixed by removing the old struct promotion eventually

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as "hacks" go, this one is probably one of the safest/simplest ones. Certainly better than using Unsafe.Add and friends.

I think it's better to explicitly track this so we know when we can remove it, so users can use it to avoid unsafe code themselves, and so users can know when they can remove their own workarounds.

@tannergooding

Copy link
Copy Markdown
Member

@EgorBo were you planning on finishing this? I think it was mostly good to go, right?

@EgorBo

EgorBo commented Jan 5, 2026 •

Copy link
Copy Markdown
Member Author

@EgorBo were you planning on finishing this? I think it was mostly good to go, right?

Right, it's just that I wanted to land a few bounds-check related JIT opt first to assist it (work-in-progress)

@EgorBo

EgorBo commented Feb 4, 2026

Copy link
Copy Markdown
Member Author

Will get back to it later

@EgorBo EgorBo closed this Feb 4, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 6, 2026
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