Remove checks and settings for Internal.Runtime.CompilerServices.Unsafe since that...
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Thu, 24 Feb 2022 03:17:58 +0000 (19:17 -0800)
committerGitHub <noreply@github.com>
Thu, 24 Feb 2022 03:17:58 +0000 (19:17 -0800)
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGeneratorOptions.cs
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs

index 4e7f296..bcee9c8 100644 (file)
@@ -5,10 +5,10 @@ using Microsoft.CodeAnalysis.Diagnostics;
 
 namespace Microsoft.Interop
 {
-    internal record DllImportGeneratorOptions(bool GenerateForwarders, bool UseMarshalType, bool UseInternalUnsafeType)
+    internal record DllImportGeneratorOptions(bool GenerateForwarders, bool UseMarshalType)
     {
         public DllImportGeneratorOptions(AnalyzerConfigOptions options)
-            : this(options.GenerateForwarders(), options.UseMarshalType(), options.UseInternalUnsafeType())
+            : this(options.GenerateForwarders(), options.UseMarshalType())
         {
         }
     }
@@ -17,8 +17,6 @@ namespace Microsoft.Interop
     {
         public const string UseMarshalTypeOption = "build_property.DllImportGenerator_UseMarshalType";
         public const string GenerateForwardersOption = "build_property.DllImportGenerator_GenerateForwarders";
-        public const string UseInternalUnsafeTypeOption = "build_property.DllImportGenerator_UseInternalUnsafeType";
-
         private static bool GetBoolOption(this AnalyzerConfigOptions options, string key)
         {
             return options.TryGetValue(key, out string? value)
@@ -29,7 +27,5 @@ namespace Microsoft.Interop
         internal static bool UseMarshalType(this AnalyzerConfigOptions options) => options.GetBoolOption(UseMarshalTypeOption);
 
         internal static bool GenerateForwarders(this AnalyzerConfigOptions options) => options.GetBoolOption(GenerateForwardersOption);
-
-        internal static bool UseInternalUnsafeType(this AnalyzerConfigOptions options) => options.GetBoolOption(UseInternalUnsafeTypeOption);
     }
 }
index 49f920c..3bbcbbc 100644 (file)
@@ -190,7 +190,7 @@ namespace Microsoft.Interop
                 NativeIndex = TypePositionInfo.ReturnIndex
             };
 
-            InteropGenerationOptions options = new(env.Options.UseMarshalType, env.Options.UseInternalUnsafeType);
+            InteropGenerationOptions options = new(env.Options.UseMarshalType);
             IMarshallingGeneratorFactory generatorFactory;
 
             if (env.Options.GenerateForwarders)
@@ -213,13 +213,14 @@ namespace Microsoft.Interop
                 generatorFactory = new MarshalAsMarshallingGeneratorFactory(options, generatorFactory);
 
                 IAssemblySymbol coreLibraryAssembly = env.Compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly;
-                ITypeSymbol disabledRuntimeMarshallingAttributeType = coreLibraryAssembly.GetTypeByMetadataName(TypeNames.System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute);
-                bool runtimeMarshallingDisabled = env.Compilation.Assembly.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, disabledRuntimeMarshallingAttributeType));
+                ITypeSymbol? disabledRuntimeMarshallingAttributeType = coreLibraryAssembly.GetTypeByMetadataName(TypeNames.System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute);
+                bool runtimeMarshallingDisabled = disabledRuntimeMarshallingAttributeType is not null
+                    && env.Compilation.Assembly.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, disabledRuntimeMarshallingAttributeType));
 
-                IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, new AttributedMarshallingModelOptions(options, runtimeMarshallingDisabled));
+                IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, new AttributedMarshallingModelOptions(runtimeMarshallingDisabled));
                 // We don't need to include the later generator factories for collection elements
                 // as the later generator factories only apply to parameters.
-                generatorFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, elementFactory, new AttributedMarshallingModelOptions(options, runtimeMarshallingDisabled));
+                generatorFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, elementFactory, new AttributedMarshallingModelOptions(runtimeMarshallingDisabled));
 
                 generatorFactory = new ByValueContentsMarshalKindValidator(generatorFactory);
             }
index 5d64f7d..bf6b2d4 100644 (file)
         of generating a stub that handles all of the marshalling.
       -->
       <CompilerVisibleProperty Include="DllImportGenerator_GenerateForwarders" />
-      <!--
-        Use the Internal.Runtime.ComplierServices.Unsafe type instead of
-        the System.Runtime.CompilerServices.Unsafe type when emitting code.
-      -->
-    <CompilerVisibleProperty Include="DllImportGenerator_UseInternalUnsafeType" />
   </ItemGroup>
 </Project>
index f0cd91a..a3814ad 100644 (file)
@@ -7,5 +7,5 @@ using System.Text;
 
 namespace Microsoft.Interop
 {
-    public readonly record struct InteropGenerationOptions(bool UseMarshalType, bool UseInternalUnsafeType);
+    public readonly record struct InteropGenerationOptions(bool UseMarshalType);
 }
index 569db79..450ba62 100644 (file)
@@ -14,14 +14,12 @@ namespace Microsoft.Interop
         private readonly IMarshallingGenerator _manualMarshallingGenerator;
         private readonly TypeSyntax _elementType;
         private readonly bool _enablePinning;
-        private readonly InteropGenerationOptions _options;
 
-        public ArrayMarshaller(IMarshallingGenerator manualMarshallingGenerator, TypeSyntax elementType, bool enablePinning, InteropGenerationOptions options)
+        public ArrayMarshaller(IMarshallingGenerator manualMarshallingGenerator, TypeSyntax elementType, bool enablePinning)
         {
             _manualMarshallingGenerator = manualMarshallingGenerator;
             _elementType = elementType;
             _enablePinning = enablePinning;
-            _options = options;
         }
 
         public bool IsSupported(TargetFramework target, Version version)
@@ -138,7 +136,7 @@ namespace Microsoft.Interop
                                 PrefixUnaryExpression(SyntaxKind.AddressOfExpression,
                                 InvocationExpression(
                                     MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
-                                        ParseTypeName(TypeNames.Unsafe(_options)),
+                                        ParseTypeName(TypeNames.System_Runtime_CompilerServices_Unsafe),
                                         GenericName("As").AddTypeArgumentListArguments(
                                             arrayElementType,
                                             PredefinedType(Token(SyntaxKind.ByteKeyword)))))
index 3484e42..7b28fa1 100644 (file)
@@ -9,7 +9,7 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
 
 namespace Microsoft.Interop
 {
-    public readonly record struct AttributedMarshallingModelOptions(InteropGenerationOptions InteropOptions, bool RuntimeMarshallingDisabled);
+    public readonly record struct AttributedMarshallingModelOptions(bool RuntimeMarshallingDisabled);
 
     public class AttributedMarshallingModelGeneratorFactory : IMarshallingGeneratorFactory
     {
@@ -294,8 +294,7 @@ namespace Microsoft.Interop
                 return new ArrayMarshaller(
                     new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: true),
                     elementType,
-                    isBlittable,
-                    Options.InteropOptions);
+                    isBlittable);
             }
 
             IMarshallingGenerator marshallingGenerator = new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: false);
index 75a7967..2b7fa36 100644 (file)
@@ -60,16 +60,12 @@ namespace Microsoft.Interop
 
         public const string System_Runtime_CompilerServices_SkipLocalsInitAttribute = "System.Runtime.CompilerServices.SkipLocalsInitAttribute";
 
-        private const string System_Runtime_CompilerServices_Unsafe = "System.Runtime.CompilerServices.Unsafe";
-
-
-        public static string Unsafe(InteropGenerationOptions options)
-        {
-            return System_Runtime_CompilerServices_Unsafe;
-        }
+        public const string System_Runtime_CompilerServices_Unsafe = "System.Runtime.CompilerServices.Unsafe";
 
         public const string System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute = "System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute";
+
         public const string DefaultDllImportSearchPathsAttribute = "System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute";
+
         public const string DllImportSearchPath = "System.Runtime.InteropServices.DllImportSearchPath";
     }
 }