Keep ref struct interfaces behind preview flag
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.
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.
@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.
Related .NET issues
- https://github.com/dotnet/runtime/issues/103270
- https://github.com/dotnet/runtime/issues/103605
- https://github.com/dotnet/runtime/pull/103604
Related Customer Issues
- Need UnscopefRef on interfaces
- csharplang discussion on the topic
- https://github.com/AssetRipper/AssetRipper.Text.Html
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.
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