dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.9k stars 4.63k forks source link

TypeSystem: Support ref structs within generics #65112

Open mangod9 opened 2 years ago

mangod9 commented 2 years ago

This is a top-level issue to track supporting ref structs within generics. For additional details refer to https://github.com/dotnet/csharplang/issues/7608 and the older https://github.com/dotnet/csharplang/issues/1148.

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

mangod9 commented 1 year ago

@AaronRobinsonMSFT , assume this is ok to close or is there more work required here?

mangod9 commented 1 year ago

@AaronRobinsonMSFT ping again. Anything remaining for this in 8?

AaronRobinsonMSFT commented 1 year ago

Only the bare minimum has been done. Moving this to .NET 9.

tkreindler commented 10 months ago

This feature request would be extremely valuable for unit testing. Right now, when using mocking frameworks like NSubstitute it's impossible to mock out a function that takes a ref-struct type like ReadOnlySpan as an argument.

For example doing the following gives a CS0306 error:

interface IMessage
{
    string DoSomething(ReadOnlySpan<byte>);
}

// Test Code
IMessage message = Substitute.For<IMessage>();

message.DoSomething(Arg.Any<ReadOnlySpan<byte>>()).Returns("success");

NSubstitute and its parent library Castle.Core have investigated this issue in the past and any fixes seem to have stalled out due to the difficulty of doing this without this language feature.

I believe this feature would fix this unit-testing gap and be a big improvement to the dotnet ecosystem.

lambdageek commented 7 months ago

cc @steveisok

vitek-karas commented 6 months ago

@AaronRobinsonMSFT - did somebody look if this works with Cecil/Trimmer? It uses different type system and it could get confused on the new pattern.

AaronRobinsonMSFT commented 6 months ago

@AaronRobinsonMSFT - did somebody look if this works with Cecil/Trimmer?

Not that I am aware of. Can I get someone from your side to try this out? What do we need to do to exercise this path? We have several IL based assemblies with the feature enabled we can pass to other tools.

vitek-karas commented 6 months ago

@sbomer - we should be able to add tests for illink - the infra has the setup for IL-based tests. Also round-trip tests of Cecil would be helpful (or through illink, it's kind of the same thing) - to make sure trimmer doesn't corrupt the metadata around this.

jbevain commented 3 months ago

Cecil work is at https://github.com/jbevain/cecil/pull/945

steveisok commented 1 month ago

It looks like everything is done and this issue can be closed. If I'm mistaken, feel free to reopen.

AaronRobinsonMSFT commented 1 month ago

No, sadly this isn't done. After updating the design and ECMA, more work is needed. I moved to 10.