meetings/2024/LDM-2024-07-22-ref-struct-interface-examples.md
ITensor<T>The tensor team wants to ship the following interface that is meant
interface ITensor<T>
{
[UnscopedRef]
ReadOnlySpan<nint> Lengths { get; }
}
This is now used by the runtime in the comparer interfaces.
public static int BinarySearch<T, TComparer>(this System.ReadOnlySpan<T> span, T value, TComparer comparer)
where TComparer : System.Collections.Generic.IComparer<T>, allows ref struct;
public static int BinarySearch<T, TComparable>(this System.ReadOnlySpan<T> span, TComparable comparable)
where TComparable : System.IComparable<T>, allows ref struct;
Runtime wants to have existing ref struct based enumerators inherit IEnumerator<T>
Runtime is considering them for the math related interfaces:
IAdditionOperatorsIParsableISpanParsableIUtf8SpanParsableThe runtime doesn't, and never will, support calling a default implemented member (DIM) when the receiver type is a ref struct. The compiler will require that a ref struct implement all members. Could also choose to warn at the point the code invites this problem if we wanted to.
interface I1
{
// Virtual method with default implementation
void M() { }
}
// Invocation of a virtual instance method with default implementation in a generic method that has the `allows ref struct`
// anti-constraint
void M<T>(T p)
where T : allows ref struct, I1
{
p.M(); // Warn?
}
The language allows for us to do this today
void M<T>(T t) where T : IDisposable, allows ref struct { }
That is strange if there is no way T can be ref struct but not also implement interfaces