-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better conversion: prefer ReadOnlySpan<T> over Span<T> #8779
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just nits that I can follow up on myself;
the rule LGTM
proposals/first-class-span-types.md
Outdated
> Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: | ||
> | ||
> - **`T₁` is `System.ReadOnlySpan<E₁>`, `T₂` is `System.Span<E₂>`, and an identity conversion from `E₁` to `E₂` exists** | ||
> - **`T₁` is `System.ReadOnlySpan<E₁>` and `T₂` is `System.ReadOnlySpan<E₂>`, or at least one of `T₁` or `T₂` is not a *span type*, and** an implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
span type
Should we be explicit this means Span / ReadOnlySpan? I imagine there might be more span types like TensorSpan.
proposals/first-class-span-types.md
Outdated
> Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: | ||
> | ||
> - **`T₁` is `System.ReadOnlySpan<E₁>`, `T₂` is `System.Span<E₂>`, and an identity conversion from `E₁` to `E₂` exists** | ||
> - **`T₁` is `System.ReadOnlySpan<E₁>` and `T₂` is `System.ReadOnlySpan<E₂>`, or at least one of `T₁` or `T₂` is not a *span type*, and** an implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified, i.e., this would have the same effect, right? But maybe it's worse because the intention is less clear.
> - **`T₁` is `System.ReadOnlySpan<E₁>` and `T₂` is `System.ReadOnlySpan<E₂>`, or at least one of `T₁` or `T₂` is not a *span type*, and** an implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists | |
> - **`T₁` is not `System.Span<E₁>` and** an implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to allow the case where one type is Span<E1>
and the other is not a span type. See similar comment.
Update better conversion target to prefer
ReadOnlySpan<T>
overSpan<T>
.Follow-up from LDM-2024-12-04 and LDM-2024-12-09.