Skip to content

Commit

Permalink
Do not say the wrong default behavior for blittable arrays in ComInte…
Browse files Browse the repository at this point in the history
…rfaceGenerator warning (#88212)

The warning used to say the default is [In] for blittable arrays, when the default is [In, Out].

Reworks how Unnecessary / Not supported / supported [In, Out] diagnostic reporting is implemented. Each marshaller will decide which details are provided with the diagnostic and which attributes are unnecessary.

Shares a single Strings.resx with all projects. "Com" or "LibraryImport" suffixes were added to string names that conflicted.

Co-authored-by: Jeremy Koritzinsky <[email protected]>
  • Loading branch information
jtschuster and jkoritzinsky authored Jul 13, 2023
1 parent 620bd3e commit d361507
Show file tree
Hide file tree
Showing 87 changed files with 17,787 additions and 17,877 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2597,11 +2597,11 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PortableThreadPool.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphore.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Unix.cs" Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\PreAllocatedOverlapped.Portable.cs" Condition="('$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true') or '$(FeatureWasmThreads)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Windows.cs" Condition="'$(TargetsWindows)' == 'true'"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Unix.cs" Condition="'$(TargetsWindows)' != 'true'"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Unix.cs" Condition="'$(TargetsWindows)' != 'true'" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\RegisteredWaitHandle.Portable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\LowLevelLifoSemaphoreBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Threading\ThreadPoolBoundHandle.Portable.cs" />
Expand Down Expand Up @@ -2671,4 +2671,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnaryPlusOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Numerics\IUnsignedNumber.cs" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices.JavaScript;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
using System.Runtime.InteropServices.JavaScript;

namespace Microsoft.Interop.JavaScript
{
Expand All @@ -26,7 +26,8 @@ protected BaseJSGenerator(MarshalerType marshalerType, IMarshallingGenerator inn
public virtual bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => _inner.UsesNativeIdentifier(info, context);
public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => _inner.GetNativeSignatureBehavior(info);
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => _inner.GetValueBoundaryBehavior(info, context);
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => _inner.SupportsByValueMarshalKind(marshalKind, context);
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
=> _inner.SupportsByValueMarshalKind(marshalKind, info, context, out diagnostic);

public virtual IEnumerable<ExpressionSyntax> GenerateBind(TypePositionInfo info, StubCodeContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ internal sealed class EmptyJSGenerator : IJSMarshallingGenerator
public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => SignatureBehavior.ManagedTypeAndAttributes;
public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => ValueBoundaryBehavior.ManagedIdentifier;
public bool IsSupported(TargetFramework target, Version version) => false;
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => ByValueMarshalKindSupport.NotSupported;
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
=> ByValueMarshalKindSupportDescriptor.Default.GetSupport(marshalKind, info, context, out diagnostic);
public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<NoWarn>RS2008;RS1038;$(NoWarn)</NoWarn>
<AnalyzerLanguage>cs</AnalyzerLanguage>
<DefineConstants>$(DefineConstants);MICROSOFT_INTEROP_COMINTERFACEGENERATOR</DefineConstants>
<StringResourcesPath>../Common/Resources/Strings.resx</StringResourcesPath>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,38 @@ public class Ids

private const string Category = "ComInterfaceGenerator";

/// <inheritdoc cref="SR.RequiresAllowUnsafeBlocksMessage"/>
/// <inheritdoc cref="SR.RequiresAllowUnsafeBlocksMessageCom"/>
public static readonly DiagnosticDescriptor RequiresAllowUnsafeBlocks =
new DiagnosticDescriptor(
Ids.RequiresAllowUnsafeBlocks,
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksTitle)),
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksMessage)),
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksTitleCom)),
GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksMessageCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksDescription)));
description: GetResourceString(nameof(SR.RequiresAllowUnsafeBlocksDescriptionCom)));

/// <inheritdoc cref="SR.InvalidAttributedMethodSignatureMessage"/>
/// <inheritdoc cref="SR.InvalidAttributedMethodSignatureMessageCom"/>
public static readonly DiagnosticDescriptor InvalidAttributedMethodSignature =
new DiagnosticDescriptor(
Ids.InvalidLibraryImportAttributeUsage,
GetResourceString(nameof(SR.InvalidVirtualMethodIndexAttributeUsage)),
GetResourceString(nameof(SR.InvalidAttributedMethodSignatureMessage)),
GetResourceString(nameof(SR.InvalidAttributedMethodSignatureMessageCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));

/// <inheritdoc cref="SR.InvalidAttributedMethodContainingTypeMissingModifiersMessage"/>
/// <inheritdoc cref="SR.InvalidAttributedMethodContainingTypeMissingModifiersMessageCom"/>
public static readonly DiagnosticDescriptor InvalidAttributedMethodContainingTypeMissingModifiers =
new DiagnosticDescriptor(
Ids.InvalidLibraryImportAttributeUsage,
GetResourceString(nameof(SR.InvalidVirtualMethodIndexAttributeUsage)),
GetResourceString(nameof(SR.InvalidAttributedMethodContainingTypeMissingModifiersMessage)),
GetResourceString(nameof(SR.InvalidAttributedMethodContainingTypeMissingModifiersMessageCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));

/// <inheritdoc cref="SR.InvalidGeneratedComInterfaceUsageMissingPartialModifier"/>
public static readonly DiagnosticDescriptor InvalidAttributedInterfaceMissingPartialModifiers =
Expand All @@ -83,7 +83,7 @@ public class Ids
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription)));
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescriptionCom)));

/// <inheritdoc cref="SR.InvalidStringMarshallingConfigurationOnInterfaceMessage"/>
public static readonly DiagnosticDescriptor InvalidStringMarshallingMismatchBetweenBaseAndDerived =
Expand Down Expand Up @@ -150,27 +150,27 @@ public class Ids
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.InvalidExceptionMarshallingConfigurationDescription)));

/// <inheritdoc cref="SR.InvalidExceptionMarshallingConfigurationMessage"/>
/// <inheritdoc cref="SR.TypeNotSupportedMessageParameterCom"/>
public static readonly DiagnosticDescriptor ParameterTypeNotSupported =
new DiagnosticDescriptor(
Ids.TypeNotSupported,
GetResourceString(nameof(SR.TypeNotSupportedTitle)),
GetResourceString(nameof(SR.TypeNotSupportedMessageParameter)),
GetResourceString(nameof(SR.TypeNotSupportedMessageParameterCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.TypeNotSupportedMessageReturn"/>
/// <inheritdoc cref="SR.TypeNotSupportedMessageReturnCom"/>
public static readonly DiagnosticDescriptor ReturnTypeNotSupported =
new DiagnosticDescriptor(
Ids.TypeNotSupported,
GetResourceString(nameof(SR.TypeNotSupportedTitle)),
GetResourceString(nameof(SR.TypeNotSupportedMessageReturn)),
GetResourceString(nameof(SR.TypeNotSupportedMessageReturnCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.TypeNotSupportedMessageParameterWithDetails"/>
public static readonly DiagnosticDescriptor ParameterTypeNotSupportedWithDetails =
Expand All @@ -181,7 +181,7 @@ public class Ids
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.TypeNotSupportedMessageReturnWithDetails"/>
public static readonly DiagnosticDescriptor ReturnTypeNotSupportedWithDetails =
Expand All @@ -192,84 +192,84 @@ public class Ids
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.TypeNotSupportedDescription)));
description: GetResourceString(nameof(SR.TypeNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageParameter"/>
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageParameterCom"/>
public static readonly DiagnosticDescriptor ParameterConfigurationNotSupported =
new DiagnosticDescriptor(
Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageParameter)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageParameterCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageReturn"/>
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageReturnCom"/>
public static readonly DiagnosticDescriptor ReturnConfigurationNotSupported =
new DiagnosticDescriptor(
Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageReturn)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageReturnCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageParameter"/>
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageParameterCom"/>
public static readonly DiagnosticDescriptor MarshalAsParameterConfigurationNotSupported =
new DiagnosticDescriptor(
GeneratorDiagnostics.Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameter)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageParameterCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageReturn"/>
/// <inheritdoc cref="SR.MarshalAsConfigurationNotSupportedMessageReturnCom"/>
public static readonly DiagnosticDescriptor MarshalAsReturnConfigurationNotSupported =
new DiagnosticDescriptor(
GeneratorDiagnostics.Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturn)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.MarshalAsConfigurationNotSupportedMessageReturnCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.ConfigurationNotSupportedMessage"/>
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageCom"/>
public static readonly DiagnosticDescriptor ConfigurationNotSupported =
new DiagnosticDescriptor(
Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessage)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageValue"/>
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageValueCom"/>
public static readonly DiagnosticDescriptor ConfigurationValueNotSupported =
new DiagnosticDescriptor(
Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageValue)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageValueCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageMarshallingInfo"/>
/// <inheritdoc cref="SR.ConfigurationNotSupportedMessageMarshallingInfoCom"/>
public static readonly DiagnosticDescriptor MarshallingAttributeConfigurationNotSupported =
new DiagnosticDescriptor(
Ids.ConfigurationNotSupported,
GetResourceString(nameof(SR.ConfigurationNotSupportedTitle)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageMarshallingInfo)),
GetResourceString(nameof(SR.ConfigurationNotSupportedTitleCom)),
GetResourceString(nameof(SR.ConfigurationNotSupportedMessageMarshallingInfoCom)),
Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescriptionCom)));

/// <inheritdoc cref="SR.MethodNotDeclaredInAttributedInterfaceMessage"/>
public static readonly DiagnosticDescriptor MethodNotDeclaredInAttributedInterface =
Expand Down Expand Up @@ -414,6 +414,7 @@ public class Ids
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesDescription)));

/// <inheritdoc cref="SR.UnnecessaryParameterMarshallingInfoMessage"/>
public static readonly DiagnosticDescriptor UnnecessaryParameterMarshallingInfo =
new DiagnosticDescriptor(
Ids.UnnecessaryMarshallingInfo,
Expand All @@ -428,6 +429,7 @@ public class Ids
WellKnownDiagnosticTags.Unnecessary
});

/// <inheritdoc cref="SR.UnnecessaryReturnMarshallingInfoMessage"/>
public static readonly DiagnosticDescriptor UnnecessaryReturnMarshallingInfo =
new DiagnosticDescriptor(
Ids.UnnecessaryMarshallingInfo,
Expand Down
Loading

0 comments on commit d361507

Please sign in to comment.