Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ComInterfaceGenerator] Warn on visibility of interface and StringMarshallingCustomType #87065

Merged
merged 23 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6cbc44c
wip - build crashes on refs
jtschuster May 26, 2023
5cb008f
wip
jtschuster May 26, 2023
355fe17
wip
jtschuster May 26, 2023
cab2abf
wip
jtschuster May 26, 2023
7319660
Use Location and revert csprojs
jtschuster May 26, 2023
094a593
Re-add the old Diagnostic APIs to Microsoft.Interop.SourceGeneration
jtschuster May 30, 2023
68dac3b
Don't qualify Location
jtschuster May 31, 2023
c3041a2
wip
jtschuster May 31, 2023
97cdba2
Merge branch 'DiagnosticTemplate' into WarnOnStringMarshallingVisibility
jtschuster May 31, 2023
3d005bf
wip
jtschuster Jun 1, 2023
21698f5
Warn if StringMarshallingCustomType or Com interface is less than int…
jtschuster Jun 1, 2023
cbcbae8
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 2, 2023
0bd13f6
Add comment, fix typo
jtschuster Jun 8, 2023
9d57731
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 9, 2023
131f353
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 12, 2023
b16c34f
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 12, 2023
6fe867e
Use shared IsAccessibleFromGeneratedCode method
jtschuster Jun 12, 2023
7ccc1ec
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 13, 2023
3b7c3ad
Report warning on identifier and add expected diagnostic arguments
jtschuster Jun 13, 2023
5072766
Merge branch 'main' of https://github.com/dotnet/runtime into WarnOnS…
jtschuster Jun 13, 2023
bbfde84
Cleanup after merge
jtschuster Jun 13, 2023
913e8e9
Revert solution to main
jtschuster Jun 13, 2023
9724971
Revert solution to upstream/main
jtschuster Jun 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ internal static class Comparers
/// <summary>
/// Comparer for an individual generated stub source as a syntax tree and the generated diagnostics for the stub.
/// </summary>
public static readonly IEqualityComparer<(MemberDeclarationSyntax Syntax, ImmutableArray<Diagnostic> Diagnostics)> GeneratedSyntax = new CustomValueTupleElementComparer<MemberDeclarationSyntax, ImmutableArray<Diagnostic>>(SyntaxEquivalentComparer.Instance, new ImmutableArraySequenceEqualComparer<Diagnostic>(EqualityComparer<Diagnostic>.Default));
public static readonly IEqualityComparer<(MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<Diagnostic>)> GeneratedSyntax4 =
new CustomValueTupleElementComparer<MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<Diagnostic>>(
public static readonly IEqualityComparer<(MemberDeclarationSyntax Syntax, ImmutableArray<DiagnosticInfo> Diagnostics)> GeneratedSyntax = new CustomValueTupleElementComparer<MemberDeclarationSyntax, ImmutableArray<DiagnosticInfo>>(SyntaxEquivalentComparer.Instance, new ImmutableArraySequenceEqualComparer<DiagnosticInfo>(EqualityComparer<DiagnosticInfo>.Default));
public static readonly IEqualityComparer<(MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<DiagnosticInfo>)> GeneratedSyntax4 =
new CustomValueTupleElementComparer<MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<DiagnosticInfo>>(
SyntaxEquivalentComparer.Instance, SyntaxEquivalentComparer.Instance, SyntaxEquivalentComparer.Instance,
new ImmutableArraySequenceEqualComparer<Diagnostic>(EqualityComparer<Diagnostic>.Default));
new ImmutableArraySequenceEqualComparer<DiagnosticInfo>(EqualityComparer<DiagnosticInfo>.Default));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public class Ids
}

private const string Category = "JSImportGenerator";
private readonly List<Diagnostic> _diagnostics = new List<Diagnostic>();
private readonly List<DiagnosticInfo> _diagnostics = new List<DiagnosticInfo>();

public IEnumerable<Diagnostic> Diagnostics => _diagnostics;
public IEnumerable<DiagnosticInfo> Diagnostics => _diagnostics;

public void ReportInvalidMarshallingAttributeInfo(
AttributeData attributeData,
string reasonResourceName,
params string[] reasonArgs)
{
_diagnostics.Add(
attributeData.CreateDiagnostic(
attributeData.CreateDiagnosticInfo(
GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported,
new LocalizableResourceString(reasonResourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.JavaScript.JSImportGenerator.SR), reasonArgs)));
}
Expand All @@ -57,14 +57,14 @@ public void ReportConfigurationNotSupported(
if (unsupportedValue == null)
{
_diagnostics.Add(
attributeData.CreateDiagnostic(
attributeData.CreateDiagnosticInfo(
GeneratorDiagnostics.ConfigurationNotSupported,
configurationName));
}
else
{
_diagnostics.Add(
attributeData.CreateDiagnostic(
attributeData.CreateDiagnosticInfo(
GeneratorDiagnostics.ConfigurationValueNotSupported,
unsupportedValue,
configurationName));
Expand Down Expand Up @@ -104,7 +104,7 @@ public void ReportMarshallingNotSupported(
if (info.IsManagedReturnPosition)
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails,
diagnosticProperties,
notSupportedDetails!,
Expand All @@ -113,7 +113,7 @@ public void ReportMarshallingNotSupported(
else
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails,
diagnosticProperties,
notSupportedDetails!,
Expand All @@ -128,7 +128,7 @@ public void ReportMarshallingNotSupported(
if (info.IsManagedReturnPosition)
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ReturnConfigurationNotSupported,
diagnosticProperties,
nameof(System.Runtime.InteropServices.MarshalAsAttribute),
Expand All @@ -137,7 +137,7 @@ public void ReportMarshallingNotSupported(
else
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ParameterConfigurationNotSupported,
diagnosticProperties,
nameof(System.Runtime.InteropServices.MarshalAsAttribute),
Expand All @@ -150,7 +150,7 @@ public void ReportMarshallingNotSupported(
if (info.IsManagedReturnPosition)
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ReturnTypeNotSupported,
diagnosticProperties,
info.ManagedType.DiagnosticFormattedName,
Expand All @@ -159,7 +159,7 @@ public void ReportMarshallingNotSupported(
else
{
_diagnostics.Add(
diagnosticLocation.CreateDiagnostic(
diagnosticLocation.CreateDiagnosticInfo(
GeneratorDiagnostics.ParameterTypeNotSupported,
diagnosticProperties,
info.ManagedType.DiagnosticFormattedName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed record IncrementalStubGenerationContext(
MethodSignatureDiagnosticLocations DiagnosticLocation,
JSExportData JSExportData,
MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion, JSGeneratorOptions)> GeneratorFactoryKey,
SequenceEqualImmutableArray<Diagnostic> Diagnostics);
SequenceEqualImmutableArray<DiagnosticInfo> Diagnostics);

public static class StepNames
{
Expand Down Expand Up @@ -69,13 +69,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
if (data.Right.IsEmpty // no attributed methods
|| data.Left.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true }) // Unsafe code enabled
{
return ImmutableArray<Diagnostic>.Empty;
return ImmutableArray<DiagnosticInfo>.Empty;
}

return ImmutableArray.Create(Diagnostic.Create(GeneratorDiagnostics.JSExportRequiresAllowUnsafeBlocks, null));
return ImmutableArray.Create(DiagnosticInfo.Create(GeneratorDiagnostics.JSExportRequiresAllowUnsafeBlocks, null));
}));

IncrementalValuesProvider<(MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<Diagnostic>)> generateSingleStub = methodsToGenerate
IncrementalValuesProvider<(MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<DiagnosticInfo>)> generateSingleStub = methodsToGenerate
.Combine(stubEnvironment)
.Combine(stubOptions)
.Select(static (data, ct) => new
Expand Down Expand Up @@ -214,7 +214,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(
new MethodSignatureDiagnosticLocations(originalSyntax),
jsExportData,
CreateGeneratorFactory(environment, options),
new SequenceEqualImmutableArray<Diagnostic>(generatorDiagnostics.Diagnostics.ToImmutableArray()));
new SequenceEqualImmutableArray<DiagnosticInfo>(generatorDiagnostics.Diagnostics.ToImmutableArray()));
}

private static MarshallingGeneratorFactoryKey<(TargetFramework, Version, JSGeneratorOptions)> CreateGeneratorFactory(StubEnvironment env, JSGeneratorOptions options)
Expand Down Expand Up @@ -286,7 +286,7 @@ private static NamespaceDeclarationSyntax GenerateRegSource(
return ns;
}

private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<Diagnostic>) GenerateSource(
private static (MemberDeclarationSyntax, StatementSyntax, AttributeListSyntax, ImmutableArray<DiagnosticInfo>) GenerateSource(
IncrementalStubGenerationContext incrementalContext)
{
var diagnostics = new GeneratorDiagnostics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed record IncrementalStubGenerationContext(
MethodSignatureDiagnosticLocations DiagnosticLocation,
JSImportData JSImportData,
MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion, JSGeneratorOptions)> GeneratorFactoryKey,
SequenceEqualImmutableArray<Diagnostic> Diagnostics);
SequenceEqualImmutableArray<DiagnosticInfo> Diagnostics);

public static class StepNames
{
Expand Down Expand Up @@ -69,13 +69,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
if (data.Right.IsEmpty // no attributed methods
|| data.Left.Compilation.Options is CSharpCompilationOptions { AllowUnsafe: true }) // Unsafe code enabled
{
return ImmutableArray<Diagnostic>.Empty;
return ImmutableArray<DiagnosticInfo>.Empty;
}

return ImmutableArray.Create(Diagnostic.Create(GeneratorDiagnostics.JSImportRequiresAllowUnsafeBlocks, null));
return ImmutableArray.Create(DiagnosticInfo.Create(GeneratorDiagnostics.JSImportRequiresAllowUnsafeBlocks, null));
}));

IncrementalValuesProvider<(MemberDeclarationSyntax, ImmutableArray<Diagnostic>)> generateSingleStub = methodsToGenerate
IncrementalValuesProvider<(MemberDeclarationSyntax, ImmutableArray<DiagnosticInfo>)> generateSingleStub = methodsToGenerate
.Combine(stubEnvironment)
.Combine(stubOptions)
.Select(static (data, ct) => new
Expand Down Expand Up @@ -201,7 +201,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(
new MethodSignatureDiagnosticLocations(originalSyntax),
jsImportData,
CreateGeneratorFactory(environment, options),
new SequenceEqualImmutableArray<Diagnostic>(generatorDiagnostics.Diagnostics.ToImmutableArray()));
new SequenceEqualImmutableArray<DiagnosticInfo>(generatorDiagnostics.Diagnostics.ToImmutableArray()));
}

private static MarshallingGeneratorFactoryKey<(TargetFramework, Version, JSGeneratorOptions)> CreateGeneratorFactory(StubEnvironment env, JSGeneratorOptions options)
Expand All @@ -211,7 +211,7 @@ private static IncrementalStubGenerationContext CalculateStubInformation(
return MarshallingGeneratorFactoryKey.Create((env.TargetFramework, env.TargetFrameworkVersion, options), jsGeneratorFactory);
}

private static (MemberDeclarationSyntax, ImmutableArray<Diagnostic>) GenerateSource(
private static (MemberDeclarationSyntax, ImmutableArray<DiagnosticInfo>) GenerateSource(
IncrementalStubGenerationContext incrementalContext)
{
var diagnostics = new GeneratorDiagnostics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Initialize(AnalysisContext context)
&& GetAttribute(typeSymbol, TypeNames.InterfaceTypeAttribute, out AttributeData? comInterfaceAttribute)
&& !InterfaceTypeAttributeIsSupported(comInterfaceAttribute, out string unsupportedValue))
{
context.ReportDiagnostic(comInterfaceAttribute.CreateDiagnostic(AnalyzerDiagnostics.InterfaceTypeNotSupported, unsupportedValue));
context.ReportDiagnostic(comInterfaceAttribute.CreateDiagnosticInfo(AnalyzerDiagnostics.InterfaceTypeNotSupported, unsupportedValue).ToDiagnostic());
}
}, SymbolKind.NamedType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ DiagnosticsOr<ComInterfaceContext> AddContext(ComInterfaceInfo iface)
|| (baseReturnedValue = AddContext(baseInfo)).HasDiagnostic)
{
// The base has failed generation at some point, so this interface cannot be generated
var diagnostic = DiagnosticsOr<ComInterfaceContext>.From(
Diagnostic.Create(
var diagnostic = DiagnosticOr<ComInterfaceContext>.From(
DiagnosticInfo.Create(
GeneratorDiagnostics.BaseInterfaceIsNotGenerated,
iface.DiagnosticLocation.AsLocation(), iface.ThisInterfaceKey, iface.BaseInterfaceKey));
iface.DiagnosticLocation, iface.ThisInterfaceKey, iface.BaseInterfaceKey));
nameToContextCache[iface.ThisInterfaceKey] = diagnostic;
return diagnostic;
}
Expand Down
Loading