Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d1be1f8
Initial plan
Copilot Jan 26, 2026
bdf2369
Add link to dotnet/roslyn#64811 in Ref Fields documentation
Copilot Jan 26, 2026
11fd35d
Clarify Span<TypedReference> and Span<Span<char>> as future additions
Copilot Jan 26, 2026
79ff114
Add link to sunset restricted types proposal
Copilot Jan 26, 2026
18cc436
Update link to use main branch instead of specific commit
Copilot Jan 26, 2026
2f485d4
Add motivating examples and links to ByRefLike types in generics
Copilot Jan 26, 2026
10c6563
Swap order of links in Ref Fields section
Copilot Jan 26, 2026
ee15123
Swap order of links in ByRefLike types in generics section for consis…
Copilot Jan 26, 2026
6fec24d
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
c70cbe8
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
6b40b6d
Update docs/design/features/byreflike-generics.md
jkotas Jan 26, 2026
8d907b6
Update docs/design/features/byreflike-generics.md
jkotas Jan 26, 2026
04bbe29
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
53e41b4
Combine Action/Func examples and add string.Create example
Copilot Jan 26, 2026
3212345
Update docs/design/features/byreflike-generics.md
jkotas Jan 26, 2026
9b2b4da
Update docs/design/features/byreflike-generics.md
jkotas Jan 26, 2026
76b86ce
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
23c5d23
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
1581b94
Update docs/design/specs/Ecma-335-Augments.md
jkotas Jan 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/design/features/byreflike-generics.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Generics parameters of ByRefLike types

Using ByRefLike types in Generic parameters is possible by building upon support added for `ref` fields. Scenarios that would benefit most from this are those involving `Span<T>`. For example, consider the following examples:
Using ByRefLike types in Generic parameters is possible by building upon support added for `ref` fields. Scenarios that would benefit most from this are those involving `Span<T>`. For example, consider the following:

- `Action<Span<char>>`, `Func<int, Span<byte>>` &ndash; Enables passing and returning `Span<T>` in delegate-based APIs without requiring custom delegate types.
- `string.Create<TState>(int length, TState state, SpanAction<char, TState> action)` &ndash; Provides a safe and efficient way to create strings from span-based state.

The following are potential future additions (see [Span&lt;Span&lt;T&gt;&gt;](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/ref-struct-interfaces.md#spanspant) for additional context):

- `Span<TypedReference>` &ndash; Represents the general case where a ByRefLike type is used as a Generic parameter. This specific case would be desirable for a more efficient Reflection API.
- `Span<Span<char>>` &ndash; Nested `Span<T>` types would be of benefit in the parsing result of strings.
Expand Down
6 changes: 4 additions & 2 deletions docs/design/specs/Ecma-335-Augments.md
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,9 @@ Note that integer values of less than 4 bytes are extended to int32 (not native
evaluation stack.

## Ref Fields
To improve the usefulness of ref structs, support for fields which are defined as ByRefs is needed. Currently their functionality can be approximated by Span<T> fields, but not all types can be converted into Span<T> types simply. In order to support these scenarios, support for generalizing ByRef fields, and converting TypedReference, ArgIterator and RuntimeArgumentHandle into following the normal rules of C# ref structs is desired. With this set of changes, it becomes possible to have ByRef fields of T, but support for pointers to ByRef fields or ByRefs to ByRefs is not added to the ECMA specification.
To improve the usefulness of ref structs, support for fields which are defined as ByRefs is needed. See [ref fields](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/low-level-struct-improvements.md#provide-ref-fields-and-scoped) for C# language counterpart. With this set of changes, it becomes possible to have ByRef fields of T, but support for pointers to ByRef fields or ByRefs to ByRefs is not added to the ECMA specification.

ByRef fields can enable converting TypedReference, ArgIterator, and RuntimeArgumentHandle to follow the normal rules of C# ref structs in the future. See [sunset restricted types](https://github.com/dotnet/csharplang/blob/main/proposals/expand-ref.md#sunset-restricted-types) and [dotnet/roslyn#64811](https://github.com/dotnet/roslyn/issues/64811).

Changes to the spec. These changes are relative to the 6th edition (June 2012) of the ECMA-335 specification published by ECMA available at:

Expand Down Expand Up @@ -1032,7 +1034,7 @@ Changes to signatures:

## <a name="byreflike-generics"></a> ByRefLike types in generics

ByRefLike types, defined in C# with the `ref struct` syntax, represent types that cannot escape to the managed heap and must remain on the stack. It is possible for these types to be used as generic parameters, but in order to improve utility certain affordances are required.
ByRefLike types, defined in C# with the `ref struct` syntax, represent types that cannot escape to the managed heap and must remain on the stack. It is possible for these types to be used as generic parameters, but in order to improve utility certain affordances are required. See [ref struct Generic Parameters](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-13.0/ref-struct-interfaces.md#ref-struct-generic-parameters) for C# language counterpart.

### II.10.1.7
An additional IL keyword, `byreflike`, is introduced to indicate use of ByRefLike types is permitted. This expands the set of permissible types used by this parameters, but limits the potential instructions that can be used on instances of this generic parameter type.
Expand Down