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 compiler support for UnconditionalSuppressMessage #51792

Merged
merged 5 commits into from
Mar 19, 2021

Conversation

agocke
Copy link
Member

@agocke agocke commented Mar 11, 2021

Fixes #48885

@agocke agocke marked this pull request as ready for review March 11, 2021 19:22
@agocke agocke requested review from a team as code owners March 11, 2021 19:22
@AlekseyTs AlekseyTs added Community The pull request was submitted by a contributor who is not a Microsoft employee. and removed Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Mar 15, 2021
public string Justification { get; set; }
}
}";
var mscorlibRef = new[] { TestBase.MscorlibRef };
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 16, 2021

Choose a reason for hiding this comment

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

TestBase.MscorlibRef [](start = 38, length = 20)

How do we know this is the right version to use? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be OK regardless: all 4.x+ corlibs should be unified, and I'm only using AttributeUsage, Attribute, and string. Those should always be present.

I looked at trying to find the references used by the workspaces layer, but the TestWorkspace was confusing and I couldn't figure out a good way to keep them in-sync.

@AlekseyTs AlekseyTs requested a review from a team March 16, 2021 16:32
@RikkiGibson RikkiGibson self-assigned this Mar 16, 2021
{
if (!_lazyUnconditionalSuppressMessageAttribute.HasValue)
{
_lazyUnconditionalSuppressMessageAttribute = new(_compilation.GetTypeByMetadataName("System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute"));
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 18, 2021

Choose a reason for hiding this comment

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

_lazyUnconditionalSuppressMessageAttribute [](start = 20, length = 42)

Is this assignment thread-safe? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, in the specific way I was using it -- but rather than guess I just changed it to something I'm certain is safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so, in the specific way I was using it

It looks like Optional is a struct with several fields, the assignment is not guaranteed to be atomic. What am I missing?


In reply to: 597090036 [](ancestors = 597090036)

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I the previous version wasn't thread safe. The path would be:

Thread 1:
_field.HasValue is false
retrieve Type
_field.HasValue <- true
--- interrupted here

Thread 2 (continuing at interruption):
_field.HasValue is true
return value is null (not correct)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Mar 18, 2021

Done with review pass (commit 4) #Closed

@AlekseyTs
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 5), assuming CI is passing

@agocke
Copy link
Member Author

agocke commented Mar 18, 2021

Looks like there was an infra break -- I don't think these were caused by my changes.

Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Looks good, just had a few small questions.

Is @dotnet/roslyn-ide sign-off needed for the EditorFeatures test changes?

private ISymbol? UnconditionalSuppressMessageAttribute
{
get
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking my understanding: is the purpose of this StrongBox just to allow us to distinguish these cases:

  1. _lazySuppressMessageAttribute is not initialized
  2. _lazySuppressMessageAttribute is initialized, and its value is null
  3. _lazySuppressMessageAttribute is initialized, and its value is non-null

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, although we don't really need to care whether the value is null or non null, just whether or not it's initialized.

var attributes = symbol.GetAttributes().Where(a => a.AttributeClass == this.SuppressMessageAttribute);
var attributes = symbol.GetAttributes().Where(a =>
a.AttributeClass == this.SuppressMessageAttribute
|| a.AttributeClass == this.UnconditionalSuppressMessageAttribute);
DecodeGlobalSuppressMessageAttributes(compilation, symbol, globalSuppressions, attributes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be called with an argument with a null AttributeClass? I'm wondering if this API could give strange answers in the event that either SuppressMessageAttribute or UnconditionalSuppressMessageAttribute is null, and a.AttributeClass is null.

Copy link
Member Author

Choose a reason for hiding this comment

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

Heh, yeah I suppose that's possible. I think that's an existing bug. I'd rather not hold up the PR for it if you don't mind, but I can file a bug about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

(I don't think it semantically matters because the diagnostic is only suppressed if the ID's match, but if the attribute doesn't exist, we won't be able to fetch the ID and they will never match).

Copy link
Member Author

Choose a reason for hiding this comment

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

Filed #51972

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

@agocke
Copy link
Member Author

agocke commented Mar 19, 2021

@sharwell Anything else? I'd like to get this in for Preview 3 (snaps tomorrow)

@sharwell
Copy link
Member

Send me a message tomorrow on teams so I don't miss it

Copy link
Member

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Looks fine with the understanding that this will break for cases where a dependency declares a second copy of the attribute as internal (even if there is no IVT access to it).

@RikkiGibson
Copy link
Contributor

Are we good to merge this? @agocke do you have a preference for squash merge or merge commit?

@agocke agocke merged commit 8cdc029 into dotnet:main Mar 19, 2021
@ghost ghost added this to the Next milestone Mar 19, 2021
@agocke agocke deleted the unconditional-suppress branch March 19, 2021 19:34
@agocke
Copy link
Member Author

agocke commented Mar 19, 2021

Squashed, thanks for the quick review everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Treat UnconditionalSuppressMessageAttribute like SuppressMessageAttribute
5 participants