Based on the following discussion: https://github.com/dotnet/standard/pull/1500#discussion_r321741920
We should do a sanity check to find out if we're missing any dummy field from any significant structs in our ref assemblies.
cc: @stephentoub @ahsonkhan @ericstj
Ok, so I wrote a console app to do this validation and the result is that some other types are indeed missing a dummy primitive for definite assignment validation to work correctly by the compiler:
The list of types is as follows:
System.Collections.Generic.SortedDictionary2+KeyCollection+Enumerator
System.Collections.Generic.SortedDictionary2+ValueCollection+Enumerator
System.Collections.Immutable.ImmutableArray1
System.Collections.Immutable.ImmutableQueue1+Enumerator
System.Collections.Immutable.ImmutableStack1+Enumerator
System.ComponentModel.Design.Serialization.MemberRelationship
System.Data.SqlTypes.SqlBinary
System.Data.SqlTypes.SqlGuid
System.Diagnostics.ActivitySpanId
System.Diagnostics.ActivityTraceId
System.Net.Security.SslApplicationProtocol
System.Net.Sockets.UdpReceiveResult
System.Reflection.PortableExecutable.PdbChecksumDebugDirectoryData
System.Reflection.Metadata.AssemblyDefinition
System.Reflection.Metadata.AssemblyReferenceHandleCollection
System.Reflection.Metadata.CustomAttributeValue1
System.Reflection.Metadata.MetadataStringComparer
System.Reflection.Metadata.ModuleDefinition
System.Reflection.Metadata.NamespaceDefinition
System.Reflection.Metadata.Ecma335.ArrayShapeEncoder
System.Reflection.Metadata.Ecma335.BlobEncoder
System.Reflection.Metadata.Ecma335.CustomAttributeArrayTypeEncoder
System.Reflection.Metadata.Ecma335.CustomAttributeElementTypeEncoder
System.Reflection.Metadata.Ecma335.CustomAttributeNamedArgumentsEncoder
System.Reflection.Metadata.Ecma335.CustomModifiersEncoder
System.Reflection.Metadata.Ecma335.FixedArgumentsEncoder
System.Reflection.Metadata.Ecma335.GenericTypeArgumentsEncoder
System.Reflection.Metadata.Ecma335.InstructionEncoder
System.Reflection.Metadata.Ecma335.LiteralEncoder
System.Reflection.Metadata.Ecma335.LiteralsEncoder
System.Reflection.Metadata.Ecma335.LocalVariablesEncoder
System.Reflection.Metadata.Ecma335.LocalVariableTypeEncoder
System.Reflection.Metadata.Ecma335.MethodBodyStreamEncoder
System.Reflection.Metadata.Ecma335.NamedArgumentsEncoder
System.Reflection.Metadata.Ecma335.NamedArgumentTypeEncoder
System.Reflection.Metadata.Ecma335.NameEncoder
System.Reflection.Metadata.Ecma335.ParameterTypeEncoder
System.Reflection.Metadata.Ecma335.PermissionSetEncoder
System.Reflection.Metadata.Ecma335.ReturnTypeEncoder
System.Reflection.Metadata.Ecma335.ScalarEncoder
System.Reflection.Metadata.Ecma335.SignatureTypeEncoder
System.Reflection.Metadata.Ecma335.VectorEncoder
System.Reflection.Metadata.BlobBuilder+Blobs
System.ModuleHandle
System.RuntimeTypeHandle
System.Threading.CancellationToken
System.Runtime.Serialization.SerializationEntry
System.Runtime.CompilerServices.ConfiguredTaskAwaitable
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1
System.Runtime.CompilerServices.TaskAwaiter
System.Runtime.CompilerServices.TaskAwaiter1
System.Runtime.CompilerServices.ValueTaskAwaiter
System.Runtime.CompilerServices.ValueTaskAwaiter1
System.Reflection.CustomAttributeNamedArgument
System.Reflection.CustomAttributeTypedArgument
System.Reflection.ParameterModifier
System.Collections.DictionaryEntry
System.Text.StringBuilder+ChunkEnumerator
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable+ConfiguredValueTaskAwaiter
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1+ConfiguredValueTaskAwaiter
System.Runtime.InteropServices.OSPlatform
System.Security.Cryptography.ECCurve
System.Security.Cryptography.Xml.X509IssuerSerial
System.Security.Cryptography.HashAlgorithmName
System.ServiceModel.Syndication.XmlDateTimeData
System.Text.Json.JsonArrayEnumerator
System.Text.Json.JsonEncodedText
System.Text.Json.JsonObjectEnumerator
System.Text.Json.JsonProperty
System.Threading.AsyncFlowControl
System.Runtime.CompilerServices.AsyncIteratorMethodBuilder
System.Runtime.CompilerServices.AsyncTaskMethodBuilder
System.Runtime.CompilerServices.AsyncTaskMethodBuilder1
System.Runtime.CompilerServices.AsyncVoidMethodBuilder
System.Xml.Serialization.XmlDeserializationEvents
I will submit a PR to fix this and of course verifying the output that I got is 100% accurate.
Also, there are no types missing a generic field nor a reference type field, which is good.
I missed a special case on my tool to validate this and found 1 type that is missing a reference type field, which is unfortunate because there could be a GC hole if someone creates a pointer of that type, however I don't think the type is too critical, the type missing it is:
System.Text.SpanRuneEnumerator
The reason why it needs it, is because it has a private field of Span<char> type and Span has a ByReference<T> private field which holds a managed ref of T.
@stephentoub @jkotas @danmosemsft would that case meet the bar in order to fix it in 3.1?
GC hole if someone creates a pointer of that type
That is not accurate description of the impact.
The impact is that somebody writing unsafe code without knowing what they are doing will not get a error from the C# compiler. Somebody writing unsafe code without knowing what they are doing can do a ton more damage - without any errors from the C# compiler.
meet the bar in order to fix it in 3.1?
I do not think so.
Most helpful comment
Ok, so I wrote a console app to do this validation and the result is that some other types are indeed missing a dummy primitive for definite assignment validation to work correctly by the compiler:
The list of types is as follows:
I will submit a PR to fix this and of course verifying the output that I got is 100% accurate.
Also, there are no types missing a generic field nor a reference type field, which is good.