From 7e964ef0ca8620eb4e7129396e867059d6c26be4 Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:26:45 -0800 Subject: [PATCH 1/6] Better conversion from expression: prefer ReadOnlySpan over Span --- proposals/first-class-span-types.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index 3b17e7e8e0..8b6af86098 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -193,19 +193,24 @@ This is based on [collection expressions overload resolution changes][ce-or]. > Given an implicit conversion `C₁` that converts from an expression `E` to a type `T₁`, and an implicit conversion `C₂` that converts from an expression `E` to a type `T₂`, `C₁` is a *better conversion* than `C₂` if one of the following holds: > -> - `E` is a *collection expression* and one of the following holds: -> - `T₁` is `System.ReadOnlySpan`, and `T₂` is `System.Span`, and an implicit conversion exists from `E₁` to `E₂`. -> - `T₁` is `System.ReadOnlySpan` or `System.Span`, and `T₂` is an *array_or_array_interface* with *element type* `E₂`, and an implicit conversion exists from `E₁` to `E₂`. -> - `T₁` is not a *span_type*, and `T₂` is not a *span_type*, and an implicit conversion exists from `T₁` to `T₂`. +> - `E` is a *collection expression*, and `C₁` is a [*better collection conversion from expression*][better-collection-conversion-from-expression] than `C₂` > - `E` is not a *collection expression* and one of the following holds: > - `E` exactly matches `T₁` and `E` does not exactly match `T₂` > - **`E` exactly matches neither of `T₁` and `T₂`, > and `C₁` is an implicit span conversion and `C₂` is not an implicit span conversion** > - `E` exactly matches both or neither of `T₁` and `T₂`, > **both or neither of `C₁` and `C₂` are an implicit span conversion**, -> and `T₁` is a better conversion target than `T₂` +> and `T₁` is a *better conversion target* than `T₂` > - `E` is a method group, `T₁` is compatible with the single best method from the method group for conversion `C₁`, and `T₂` is not compatible with the single best method from the method group for conversion `C₂` +*Better conversion target* ([§12.6.4.7][better-conversion-target]) is updated to prefer `ReadOnlySpan` over `Span`. + +> Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: +> +> - **`T₁` is `System.ReadOnlySpan`, `T₂` is `System.Span`, and an identity conversion from `E₁` to `E₂` exists** +> - An implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists +> - ... + This rule should ensure that whenever an overload becomes applicable due to the new span conversions, any potential ambiguity with another overload is avoided because the newly-applicable overload is preferred. @@ -623,3 +628,4 @@ Keep things as they are. [ce-or]: https://github.com/dotnet/csharplang/blob/566a4812682ccece4ae4483d640a489287fa9c76/proposals/csharp-12.0/collection-expressions.md#overload-resolution [overload-resolution-priority]: https://github.com/dotnet/csharplang/blob/566a4812682ccece4ae4483d640a489287fa9c76/proposals/overload-resolution-priority.md +[better-collection-conversion-from-expression]: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/collection-expressions-better-conversion.md#detailed-design From 4c89a7f0d344d8aae52957e58f232b137ee11b8c Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:06:42 -0800 Subject: [PATCH 2/6] Add heading --- proposals/first-class-span-types.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index 8b6af86098..40ffb5d845 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -203,6 +203,9 @@ This is based on [collection expressions overload resolution changes][ce-or]. > and `T₁` is a *better conversion target* than `T₂` > - `E` is a method group, `T₁` is compatible with the single best method from the method group for conversion `C₁`, and `T₂` is not compatible with the single best method from the method group for conversion `C₂` +#### Better conversion target +[better-conversion-target]: #better-conversion-target + *Better conversion target* ([§12.6.4.7][better-conversion-target]) is updated to prefer `ReadOnlySpan` over `Span`. > Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: From 7b628600a2f270dd133f61a69d6770db394dea70 Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:13:49 -0800 Subject: [PATCH 3/6] Address feedback --- proposals/first-class-span-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index 40ffb5d845..f7e397405c 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -204,7 +204,7 @@ This is based on [collection expressions overload resolution changes][ce-or]. > - `E` is a method group, `T₁` is compatible with the single best method from the method group for conversion `C₁`, and `T₂` is not compatible with the single best method from the method group for conversion `C₂` #### Better conversion target -[better-conversion-target]: #better-conversion-target +[betterness-target]: #better-conversion-target *Better conversion target* ([§12.6.4.7][better-conversion-target]) is updated to prefer `ReadOnlySpan` over `Span`. @@ -214,7 +214,7 @@ This is based on [collection expressions overload resolution changes][ce-or]. > - An implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists > - ... -This rule should ensure that whenever an overload becomes applicable due to the new span conversions, +The *better conversion from expression* rule should ensure that whenever an overload becomes applicable due to the new span conversions, any potential ambiguity with another overload is avoided because the newly-applicable overload is preferred. Without this rule, the following code that successfully compiled in C# 13 would result in an ambiguity error in C# 14 From c7917daa69fbc79892321f2197739cff8299c1d8 Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:19:20 -0800 Subject: [PATCH 4/6] Avoid using existing rule with span types --- proposals/first-class-span-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index f7e397405c..2e2777332d 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -211,7 +211,7 @@ This is based on [collection expressions overload resolution changes][ce-or]. > Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: > > - **`T₁` is `System.ReadOnlySpan`, `T₂` is `System.Span`, and an identity conversion from `E₁` to `E₂` exists** -> - An implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists +> - **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 > - ... The *better conversion from expression* rule should ensure that whenever an overload becomes applicable due to the new span conversions, From 8c4ce54b67e3ebd4a75b6662f0e9619b7fb7c7d8 Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:53:49 -0800 Subject: [PATCH 5/6] Allow conversion from ReadOnlySpan to ReadOnlySpan --- proposals/first-class-span-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index 2e2777332d..aa874f0a9e 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -211,7 +211,7 @@ This is based on [collection expressions overload resolution changes][ce-or]. > Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: > > - **`T₁` is `System.ReadOnlySpan`, `T₂` is `System.Span`, and an identity conversion from `E₁` to `E₂` exists** -> - **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 `System.ReadOnlySpan` and `T₂` is `System.ReadOnlySpan`, 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 > - ... The *better conversion from expression* rule should ensure that whenever an overload becomes applicable due to the new span conversions, From bf2042cb885adc3d90c57f5e1e6665e8a1005cb1 Mon Sep 17 00:00:00 2001 From: Charles Stoner <10732005+cston@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:15:32 -0800 Subject: [PATCH 6/6] Clarify span type --- proposals/first-class-span-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/first-class-span-types.md b/proposals/first-class-span-types.md index aa874f0a9e..fe3312c919 100644 --- a/proposals/first-class-span-types.md +++ b/proposals/first-class-span-types.md @@ -211,7 +211,7 @@ This is based on [collection expressions overload resolution changes][ce-or]. > Given two types `T₁` and `T₂`, `T₁` is a ***better conversion target*** than `T₂` if one of the following holds: > > - **`T₁` is `System.ReadOnlySpan`, `T₂` is `System.Span`, and an identity conversion from `E₁` to `E₂` exists** -> - **`T₁` is `System.ReadOnlySpan` and `T₂` is `System.ReadOnlySpan`, 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 `System.ReadOnlySpan` and `T₂` is `System.ReadOnlySpan`, or at least one of `T₁` or `T₂` is not `System.ReadOnlySpan` or `System.Span`, and** an implicit conversion from `T₁` to `T₂` exists and no implicit conversion from `T₂` to `T₁` exists > - ... The *better conversion from expression* rule should ensure that whenever an overload becomes applicable due to the new span conversions,