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

Add diagnostic suppressor for the MarkMethodsAsStatic diagnostics on custom marshallers #72129

Merged
merged 5 commits into from
Jul 15, 2022

Conversation

jkoritzinsky
Copy link
Member

Today, we have to suppress the diagnostic to make a method static for methods on the stateful marshallers shapes that are required to exist but are sometimes empty, such as Free. In particular, dotnet/runtime and dotnet/aspnetcore bump the severity of this rule from info to warning, which is then converted into an error, so we can't just ignore it. Additionally, leaving the diagnostics as-is provides a bad user experience where we guide them to write code that doesn't work with the source generator.

This PR introduces a diagnostic suppressor that disables the "mark methods as static" diagnostic on methods that must be instance methods for our various different marshalling shapes.

It also removes the manual suppression of the diagnostic from the various marshallers we had to add the suppression to.

I decided to add a suppressor instead of updating the analyzer as this suppression works significantly differently than the existing built-in "suppressions" in the analyzer. This suppression is based on attributes on containing types, whereas the built-in "suppressions" are based on attributes applied to the methods or well-known method bodies (like throw NotImplementedException();). Additionally, we may extend this suppressor to cover other diagnostics in the future that interfere with our shape designs.

Fixes #71793

…ppressor for suppressing any diagnostics that guide users to not follow the marshaller shapes.
…methods that are part of the stateful shape.

Improve the test suite for the suppressor
@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels Jul 13, 2022
@ghost ghost assigned jkoritzinsky Jul 13, 2022
@ghost
Copy link

ghost commented Jul 13, 2022

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Today, we have to suppress the diagnostic to make a method static for methods on the stateful marshallers shapes that are required to exist but are sometimes empty, such as Free. In particular, dotnet/runtime and dotnet/aspnetcore bump the severity of this rule from info to warning, which is then converted into an error, so we can't just ignore it. Additionally, leaving the diagnostics as-is provides a bad user experience where we guide them to write code that doesn't work with the source generator.

This PR introduces a diagnostic suppressor that disables the "mark methods as static" diagnostic on methods that must be instance methods for our various different marshalling shapes.

It also removes the manual suppression of the diagnostic from the various marshallers we had to add the suppression to.

I decided to add a suppressor instead of updating the analyzer as this suppression works significantly differently than the existing built-in "suppressions" in the analyzer. This suppression is based on attributes on containing types, whereas the built-in "suppressions" are based on attributes applied to the methods or well-known method bodies (like throw NotImplementedException();). Additionally, we may extend this suppressor to cover other diagnostics in the future that interfere with our shape designs.

Fixes #71793

Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices, source-generator

Milestone: -

…the test suite on Mono against an active issue
…rics and reuse this logic from the suppressor.

Add a linear collection test.

PR feedback.
@jkoritzinsky jkoritzinsky force-pushed the no-static-shape-methods branch from eff93e0 to 2ceab41 Compare July 14, 2022 22:31
/// <param name="entryPointType">The entry point type</param>
/// <param name="attributeMarshallerType">The marshaller type from the CustomMarshallerAttribute</param>
/// <returns>A fully constructed marshaller type</returns>
public static bool TryResolveMarshallerType(INamedTypeSymbol entryPointType, ITypeSymbol? attributeMarshallerType, Action<Diagnostic> reportDiagnostic, [NotNullWhen(true)] out ITypeSymbol? marshallerType)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function came from the start of my work on the new CustomMarshallerAttribute analyzer. The reportDiagnostic parameter currently isn't used to actually report diagnostics, but will be used in that PR.

@jkoritzinsky
Copy link
Member Author

MSquic timeout is unrelated.

@jkoritzinsky jkoritzinsky merged commit 8e4fe9a into dotnet:main Jul 15, 2022
@jkoritzinsky jkoritzinsky deleted the no-static-shape-methods branch July 15, 2022 17:00
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a DiagnosticSuppressor for diagnostics that guide users to not follow the Custom Marshaller shapes
3 participants