Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 15, 2025

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
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
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
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
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.

Comment on lines 1369 to 1371
vecX.CopyTo(byteDest.Slice(0, Vector128<byte>.Count));
vecX.CopyTo(byteDest.Slice(20, Vector128<byte>.Count));
vecX.CopyTo(byteDest.Slice(8, Vector128<byte>.Count));
Copy link
Member

Choose a reason for hiding this comment

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

What's the codegen for this currently? We've known to have issues for CopyTo in particular

Is one of the prior PRs where we tried to improve it going to be more applicable now?

Span<TChar> dest = destination;

// For better range check elimination, split the dash and no-dash cases.
if (hasDashes)
Copy link
Member

Choose a reason for hiding this comment

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

There's a large amount of calls and casts in here.

I wonder if it's worth it compared to just having the 4 branch checks for hasDashes and manually avoiding the repeated operations

Copy link
Member Author

Choose a reason for hiding this comment

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

the unified version is too complex for JIT to remove bounds checks for

Copy link
Member

Choose a reason for hiding this comment

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

That's unfortunate. It would be nice to have a tracking issue for that, so we can know what patterns might be encouraging users (including ourselves) to write unsafe or less idiomatic code

(Vector128<byte> vecX, Vector128<byte> vecY, Vector128<byte> vecZ) = FormatGuidVector128Utf8(this, flags < 0 /* dash */);
// Vectorized implementation for D, N, P and B formats:
// [{|(]dddddddd[-]dddd[-]dddd[-]dddd[-]dddddddddddd[}|)]
(Vector128<byte> vecX, Vector128<byte> vecY, Vector128<byte> vecZ) = FormatGuidVector128Utf8(this, hasDashes);
Copy link
Member

Choose a reason for hiding this comment

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

It's probably possible to make this fully xplat now and then we could remove the CompExactlyDependsOn

Copy link
Member Author

Choose a reason for hiding this comment

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

probably, although, it relies on some helpers without fallbacks so will fail on e.g. wasm simd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants