Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Keep ref struct interfaces behind preview flag #73923

Closed
jaredpar opened this issue Jun 10, 2024 · 5 comments · Fixed by #74551
Closed

Keep ref struct interfaces behind preview flag #73923

jaredpar opened this issue Jun 10, 2024 · 5 comments · Fixed by #74551
Assignees
Labels
Area-Compilers Bug Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Milestone

Comments

@jaredpar
Copy link
Member

jaredpar commented Jun 10, 2024

Language design is leaning towards keeping ref struct interfaces for .NET 9. There aren't a lot of real world cases and that is leading to concerns on whether we've battle tested the design enough. Leaving in preview would give us more time to evaluate against real world cases and ensure the design is correct.

This issue is a place holder to ensure we don't attach it to the new language version when it's defined in the 17.12 milestone.

@jaredpar jaredpar added this to the 17.12 milestone Jun 10, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 10, 2024
@hamarb123
Copy link

I have some code like this in some scenarios that require very low overhead to be useful:

interface IAction
{
    void Run(/*extra parameters here for some variants of it*/);
}

And I was hoping to update it to allow ref struct IActions so that I didn't have to do the pointer trick in these cases. (Note that I pass the generic TAction by reference to allow state changes to it when it runs)

I will post more use cases when I have a chance to go through more of the code where I ran into similar issues as I find or think of them.

@AlekseyTs
Copy link
Contributor

@hamarb123 Note, the plan is to keep ability for ref structs to implement interface behind a preview flag, the allows ref struct constraint on type parameters is not affected and will be fully supported.

@tannergooding
Copy link
Member

While ref structs implementing interfaces isn't something terribly important to me for .NET 9/C# 13, there is the slightly related feature of being able to mark interface members with [UnscopedRef] that is important and makes a difference in how the .NET Libraries team will ship ITensor<T>

We want to expose ROSpan<nint> Lengths { get; } which for structs (regular -or- ref struct) requires it be annotated as [UnscopedRef] so that you can return an InlineArray or equivalent to allow allocation free tracking of the multidimensional lengths buffer.

@AlekseyTs
Copy link
Contributor

LDM confirmed that we want to ship this aspect of the feature in NET 9/C# 13. See https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-07-22.md#ref-structs-implementing-interfaces for more information

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area-Compilers Bug Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants