Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

cston
Copy link
Member

@cston cston commented Dec 6, 2024

Update better conversion target to prefer ReadOnlySpan<T> over Span<T>.

Follow-up from LDM-2024-12-04 and LDM-2024-12-09.

@cston cston marked this pull request as ready for review December 6, 2024 19:59
@cston cston requested a review from a team as a code owner December 6, 2024 19:59
Copy link
Member

@jjonescz jjonescz left a 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 Show resolved Hide resolved
proposals/first-class-span-types.md Outdated Show resolved Hide resolved
@cston cston requested review from a team, MadsTorgersen and BillWagner December 10, 2024 01:28
> 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
Copy link
Member

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.

> 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
Copy link
Member

@jjonescz jjonescz Dec 10, 2024

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.

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

Copy link
Member Author

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.

@cston cston requested a review from 333fred December 12, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants