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

Allow ref field of the containing type #62098

Closed
cston opened this issue Jun 23, 2022 · 4 comments
Closed

Allow ref field of the containing type #62098

cston opened this issue Jun 23, 2022 · 4 comments

Comments

@cston
Copy link
Member

cston commented Jun 23, 2022

Allow the following:

ref struct R<T>
{
    public ref R<T> Next;
}

Relates to test plan #59194

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 23, 2022
@cston cston added New Language Feature - Ref Fields Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead and removed Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 23, 2022
@RikkiGibson
Copy link
Contributor

Is this planned for C# 11?

@jcouv jcouv added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 24, 2022
@jcouv jcouv added this to the C# 11.0 milestone Jun 24, 2022
@jaredpar jaredpar modified the milestones: C# 11.0, 17.4 Jun 24, 2022
@jaredpar
Copy link
Member

jaredpar commented Jul 1, 2022

Is this planned for C# 11?

No. This section of the proposal is attempting to keep track of what will make C# 11 vs. later releases

https://github.com/dotnet/csharplang/blob/main/proposals/low-level-struct-improvements.md#what-will-make-c-110

@jaredpar jaredpar modified the milestones: 17.4, C# 12.0 Jul 1, 2022
@John0King
Copy link

any news on here ?
demo link
image

since the ref field is a T& in IL and it size is fixed to 8 byte on x64, this could allow us to wirte a struct TreeNode<T> instead of using class

by the way, Java can optimize class to be allocate on stack , and I think that why it‘s "binary-trees“ benchamark faster than C#
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/csharp.html

@jaredpar
Copy link
Member

Closing as ref fields of ref struct are not permitted by the language spec. It's not specific to containing type.

@jaredpar jaredpar closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants