Skip to content

Add documentation links for ByRef fields and byref-like generics#123626

Merged
jkotas merged 19 commits intomainfrom
copilot/add-support-for-byref-fields
Jan 27, 2026
Merged

Add documentation links for ByRef fields and byref-like generics#123626
jkotas merged 19 commits intomainfrom
copilot/add-support-for-byref-fields

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Description

Adds reference links to improve documentation clarity for ByRef fields and byref-like generics features.

The changes document the C# language support requirements, add concrete motivating examples of implemented features, and clarify the current state of certain constructs.

Changes

  • docs/design/specs/Ecma-335-Augments.md:

    • Added inline links to the sunset restricted types proposal and Sunset restricted types roslyn#64811 in the "Ref Fields" section describing the desired support for generalizing ByRef fields and converting TypedReference, ArgIterator, and RuntimeArgumentHandle to follow normal ref struct rules.
    • Added the same links to the "ByRefLike types in generics" section for consistency and completeness.
    • Added a link to the ref struct Generic Parameters C# language counterpart in the "ByRefLike types in generics" section.
    • Link order: sunset restricted types proposal is listed first, followed by the dotnet/roslyn issue in both sections.
  • docs/design/features/byreflike-generics.md:

    • Added motivating examples of features that were actually built:
      • Combined Action<Span<char>> and Func<int, Span<byte>> into a single bullet demonstrating delegate-based APIs with Span<T> parameters and return types.
      • Added string.Create<TState>(int length, TState state, SpanAction<char, TState> action) example showing efficient string creation using stack-allocated buffers with ByRefLike types in generic parameters.
    • Clarified that Span<TypedReference> and Span<Span<char>> are potential future additions rather than currently enabled features.
    • Added link to the C# language specification explaining why these constructs were not enabled by this feature.
Original prompt

Create PR that links to dotnet/roslyn#64811 from "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"


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for generalizing ByRef fields and related types Add Roslyn issue reference to ByRef fields documentation Jan 26, 2026
Copilot AI requested a review from jkotas January 26, 2026 15:48
@GeeLaw
Copy link

GeeLaw commented Jan 26, 2026

The link should also be added in "ByRefLike types in generics" (section after "Ref Fields").

@jkotas
Copy link
Member

jkotas commented Jan 26, 2026

@copilot Please change mention of Span<TypedReference> and Span<Span<char>> in https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md to potential future addition since these constructs were not enabled by this feature. Link to https://github.com/dotnet/csharplang/blob/e8dbda9ab73cbba592206084553a08a6791a272d/proposals/csharp-13.0/ref-struct-interfaces.md#spanspant for additional context.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot Please change mention of Span<TypedReference> and Span<Span<char>> in https://github.com/dotnet/runtime/blob/main/docs/design/features/byreflike-generics.md to potential future addition s...

Done in commit 11fd35d. Updated the text to clarify these are "potential future additions" and added a link to the C# language specification section explaining why these constructs were not enabled.

Copilot AI changed the title Add Roslyn issue reference to ByRef fields documentation Add documentation links for ByRef fields and byref-like generics Jan 26, 2026
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
@jkotas
Copy link
Member

jkotas commented Jan 26, 2026

The link should also be added in "ByRefLike types in generics" (section after "Ref Fields").

@copilot Address this feedback

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
jkotas and others added 2 commits January 26, 2026 14:46
Copilot AI requested a review from jkotas January 26, 2026 22:49
@jkotas jkotas marked this pull request as ready for review January 26, 2026 23:03
Copilot AI review requested due to automatic review settings January 26, 2026 23:03
@jkotas
Copy link
Member

jkotas commented Jan 26, 2026

@GeeLaw @huoyaoyuan Does this look good?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances documentation for ByRef fields and byref-like generics by adding reference links to C# language proposals and related issues, along with concrete examples of implemented features.

Changes:

  • Added documentation links connecting runtime specifications to C# language proposals for ref fields and byref-like generics
  • Clarified which features are currently implemented versus potential future additions
  • Added concrete motivating examples showing real-world usage of byref-like types in generic parameters

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
docs/design/specs/Ecma-335-Augments.md Added links to C# language proposals for ref fields and byref-like generics, and split the ref fields section into two paragraphs for better clarity
docs/design/features/byreflike-generics.md Added concrete examples of implemented features (Action/Func with Span, string.Create) and clarified that Span and Span<Span> are potential future additions

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@huoyaoyuan
Copy link
Member

It looks a bit clear now.

@GeeLaw
Copy link

GeeLaw commented Jan 27, 2026

Under "ByRefLike types in generics", it's not pointed out that the runtime currently doesn't support substituting TypedReference to allows ref struct --- this is not just a C# restriction.

type as generic argument C# runtime
TypedReference does not compile exception upon MakeGenericXyz
ArgIterator does not compile MakeGenericXyz succeeds
RuntimeArgumentHandle does not compile MakeGenericXyz succeeds

Given the status of TypedReference, I'm not sure if the support for the two is accidental or intended in the current release of the runtime.

@jkotas
Copy link
Member

jkotas commented Jan 27, 2026

I'm not sure if the support for the two is accidental or intended in the current release of the runtime.

It is unfinished feature. I would not recommend depending on it.

@jkotas
Copy link
Member

jkotas commented Jan 27, 2026

In general, MakeGeneric API is less strict than C#.

@jkotas
Copy link
Member

jkotas commented Jan 27, 2026

/ba-g markdown change only

@jkotas jkotas merged commit e83b37c into main Jan 27, 2026
15 of 16 checks passed
@jkotas jkotas deleted the copilot/add-support-for-byref-fields branch January 27, 2026 18:47
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.

5 participants