Better conversion: prefer ReadOnlySpan<T> over Span<T>#8779
Merged
cston merged 8 commits intodotnet:mainfrom Jan 14, 2025
Merged
Better conversion: prefer ReadOnlySpan<T> over Span<T>#8779cston merged 8 commits intodotnet:mainfrom
cston merged 8 commits intodotnet:mainfrom
Conversation
jjonescz
approved these changes
Dec 6, 2024
Member
jjonescz
left a comment
There was a problem hiding this comment.
just nits that I can follow up on myself;
the rule LGTM
jjonescz
reviewed
Dec 10, 2024
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 |
Member
There was a problem hiding this comment.
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 |
Member
There was a problem hiding this comment.
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.
Suggested change
| > - **`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 |
Contributor
Author
There was a problem hiding this comment.
We'll need to allow the case where one type is Span<E1> and the other is not a span type. See similar comment.
333fred
approved these changes
Dec 31, 2024
jjonescz
approved these changes
Jan 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update better conversion target to prefer
ReadOnlySpan<T>overSpan<T>.Follow-up from LDM-2024-12-04 and LDM-2024-12-09.