Add NFloat as an interop intrinsic for the source generator (#88257)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Fri, 30 Jun 2023 18:30:22 +0000 (11:30 -0700)
committerGitHub <noreply@github.com>
Fri, 30 Jun 2023 18:30:22 +0000 (11:30 -0700)
docs/design/libraries/LibraryImportGenerator/Compatibility.md
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Compiles.cs

index e897a5a..92f0c8e 100644 (file)
@@ -20,9 +20,10 @@ Strict blittability checks have been slightly relaxed. A few select types are no
 
 - `System.Runtime.InteropServices.CLong`
 - `System.Runtime.InteropServices.CULong`
+- `System.Runtime.InteropServices.NFloat`
 - `System.Guid`
 
-The first two types are interop intrinsics that were specifically designed to be used at the unmanaged API layer, so they should be considered blittable by all interop systems. `System.Guid` is extremely commonly used in COM-based APIs, and with the move to supporting COM interop in source-generation, this type shows up in signatures quite a bit. As .NET has always maintained that `Guid` is a blittable representation of `GUID` and it is marked as `NonVersionable` (so we have already committed to maintain the shape between multiple versions of the runtime), we have decided to add it to the list of strictly blittable types.
+The first three types are interop intrinsics that were specifically designed to be used at the unmanaged API layer, so they should be considered blittable by all interop systems. `System.Guid` is extremely commonly used in COM-based APIs, and with the move to supporting COM interop in source-generation, this type shows up in signatures quite a bit. As .NET has always maintained that `Guid` is a blittable representation of `GUID` and it is marked as `NonVersionable` (so we have already committed to maintain the shape between multiple versions of the runtime), we have decided to add it to the list of strictly blittable types.
 
 We strive to keep this list of "exceptions" to our strict blittability rules small, but we will continue to evaluate the list of types in the future as we explore new interop scenarios. We will follow these rules to determine if we will consider encoding the type as strictly blittable in the future:
 
index f22d3b9..dac6c26 100644 (file)
@@ -160,5 +160,7 @@ namespace Microsoft.Interop
         public const string System_Runtime_InteropServices_CLong = "System.Runtime.InteropServices.CLong";
 
         public const string System_Runtime_InteropServices_CULong = "System.Runtime.InteropServices.CULong";
+
+        public const string System_Runtime_InteropServices_NFloat = "System.Runtime.InteropServices.NFloat";
     }
 }
index 74bec77..a2b6983 100644 (file)
@@ -74,7 +74,8 @@ namespace Microsoft.Interop
                     {
                         // We have a few exceptions to this rule. We allow a select number of types that we know are unmanaged and will always be unmanaged.
                         if (t.ToDisplayString() is TypeNames.System_Runtime_InteropServices_CLong // CLong is an interop intrinsic type for the C long type
-                                or TypeNames.System_Runtime_InteropServices_CULong)// CULong is an interop intrinsic type for the C ulong type
+                                or TypeNames.System_Runtime_InteropServices_CULong // CULong is an interop intrinsic type for the C ulong type
+                                or TypeNames.System_Runtime_InteropServices_NFloat) // NFloat is an interop intrinsic type for a pointer-sized floating point type
                         {
                             return true;
                         }
index c141011..988a62f 100644 (file)
@@ -33,34 +33,35 @@ namespace LibraryImportGenerator.UnitTests
 
         public static IEnumerable<object[]> CodeSnippetsToCompile()
         {
-            //yield return new[] { ID(), CodeSnippets.TrivialClassDeclarations };
-            //yield return new[] { ID(), CodeSnippets.TrivialStructDeclarations };
-            //yield return new[] { ID(), CodeSnippets.MultipleAttributes };
-            //yield return new[] { ID(), CodeSnippets.NestedNamespace };
-            //yield return new[] { ID(), CodeSnippets.NestedTypes };
-            //yield return new[] { ID(), CodeSnippets.UnsafeContext };
-            //yield return new[] { ID(), CodeSnippets.UserDefinedEntryPoint };
-            //yield return new[] { ID(), CodeSnippets.AllLibraryImportNamedArguments };
-            //yield return new[] { ID(), CodeSnippets.DefaultParameters };
-            //yield return new[] { ID(), CodeSnippets.UseCSharpFeaturesForConstants };
-
-            //// Parameter / return types
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<byte>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<sbyte>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<short>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ushort>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<int>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<uint>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<long>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ulong>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<float>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<double>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<IntPtr>() };
-            //yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<UIntPtr>() };
+            yield return new[] { ID(), CodeSnippets.TrivialClassDeclarations };
+            yield return new[] { ID(), CodeSnippets.TrivialStructDeclarations };
+            yield return new[] { ID(), CodeSnippets.MultipleAttributes };
+            yield return new[] { ID(), CodeSnippets.NestedNamespace };
+            yield return new[] { ID(), CodeSnippets.NestedTypes };
+            yield return new[] { ID(), CodeSnippets.UnsafeContext };
+            yield return new[] { ID(), CodeSnippets.UserDefinedEntryPoint };
+            yield return new[] { ID(), CodeSnippets.AllLibraryImportNamedArguments };
+            yield return new[] { ID(), CodeSnippets.DefaultParameters };
+            yield return new[] { ID(), CodeSnippets.UseCSharpFeaturesForConstants };
+
+            // Parameter / return types
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<byte>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<sbyte>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<short>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ushort>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<int>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<uint>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<long>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<ulong>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<float>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<double>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<IntPtr>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<UIntPtr>() };
 
             // Parameter / return types for specially considered "strictly blittable" types.
             yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<CLong>() };
             yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<CULong>() };
+            yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<NFloat>() };
             yield return new[] { ID(), CodeSnippets.BasicParametersAndModifiers<Guid>() };
 
             // Arrays