diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGeneratorOptions.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGeneratorOptions.cs index 4e7f296e4d8d2e..bcee9c816bbea0 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGeneratorOptions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGeneratorOptions.cs @@ -5,10 +5,10 @@ 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 @@ public static class OptionsHelper { 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 @@ private static bool GetBoolOption(this AnalyzerConfigOptions options, string key 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); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs index 1f6e7f16e09a9f..9cec9bfcccfb0d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs @@ -190,7 +190,7 @@ private static (ImmutableArray, IMarshallingGeneratorFactory) 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 @@ private static (ImmutableArray, IMarshallingGeneratorFactory) 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); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props index 5d64f7df4a8326..bf6b2d4a0d0ca8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props @@ -15,10 +15,5 @@ of generating a stub that handles all of the marshalling. --> - - diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs index f0cd91ae0a01ce..a3814ada6619da 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs @@ -7,5 +7,5 @@ namespace Microsoft.Interop { - public readonly record struct InteropGenerationOptions(bool UseMarshalType, bool UseInternalUnsafeType); + public readonly record struct InteropGenerationOptions(bool UseMarshalType); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs index 569db790ffe701..450ba62c1aaa1c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs @@ -14,14 +14,12 @@ public sealed class ArrayMarshaller : IMarshallingGenerator 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 @@ private IEnumerable GeneratePinningPath(TypePositionInfo info, 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))))) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs index 3484e427130155..7b28fa14f2a9a1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs @@ -9,7 +9,7 @@ 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 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller( return new ArrayMarshaller( new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: true), elementType, - isBlittable, - Options.InteropOptions); + isBlittable); } IMarshallingGenerator marshallingGenerator = new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: false); diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs index d8b816e1a855bf..4d67dbefdac01e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs @@ -65,16 +65,12 @@ public static string MarshalEx(InteropGenerationOptions options) 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"; } }