-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 support for assembly/module-level [Experimental]
and contextual suppression
#69316
Changes from 10 commits
2b800fb
c8a0fa0
6669f0b
d44dae2
6baacd2
b0ed1cd
afba201
fba843c
c9d41c6
7ad505e
9add30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,8 @@ | |
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Security.Cryptography; | ||
using System.Threading; | ||
using Microsoft.CodeAnalysis.CSharp.Emit; | ||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
|
@@ -1382,7 +1380,7 @@ private void LoadAndValidateNetModuleAttributes(ref CustomAttributesBag<CSharpAt | |
// This affects only diagnostics. | ||
for (int i = _modules.Length - 1; i > 0; i--) | ||
{ | ||
var peModuleSymbol = (Metadata.PE.PEModuleSymbol)_modules[i]; | ||
var peModuleSymbol = (PEModuleSymbol)_modules[i]; | ||
|
||
foreach (NamedTypeSymbol forwarded in peModuleSymbol.GetForwardedTypes()) | ||
{ | ||
|
@@ -2553,6 +2551,11 @@ private void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments<Attr | |
|
||
arguments.GetOrCreateData<CommonAssemblyWellKnownAttributeData>().AssemblyAlgorithmIdAttributeSetting = algorithmId; | ||
} | ||
else if (attribute.IsTargetAttribute(this, AttributeDescription.ExperimentalAttribute)) | ||
{ | ||
var obsoleteData = attribute.DecodeExperimentalAttribute(); | ||
arguments.GetOrCreateData<CommonAssemblyWellKnownAttributeData>().ExperimentalAttributeData = obsoleteData; | ||
} | ||
} | ||
|
||
// Checks that the integral arguments for the given well-known attribute are non-negative. | ||
|
@@ -2860,6 +2863,41 @@ private static string DefaultValue(TypeSymbol type) | |
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Returns data decoded from Obsolete attribute or null if there is no Obsolete attribute. | ||
/// This property returns ObsoleteAttributeData.Uninitialized if attribute arguments haven't been decoded yet. | ||
/// </summary> | ||
internal sealed override ObsoleteAttributeData? ObsoleteAttributeData | ||
{ | ||
get | ||
{ | ||
// [assembly: Experimental] may have been specified in the assembly or one of the modules | ||
var lazySourceAttributesBag = _lazySourceAttributesBag; | ||
if (lazySourceAttributesBag != null && lazySourceAttributesBag.IsDecodedWellKnownAttributeDataComputed) | ||
{ | ||
var data = (CommonAssemblyWellKnownAttributeData)lazySourceAttributesBag.DecodedWellKnownAttributeData; | ||
if (data?.ExperimentalAttributeData is { } experimentalAttributeData) | ||
{ | ||
return experimentalAttributeData; | ||
} | ||
} | ||
|
||
var lazyNetModuleAttributesBag = _lazyNetModuleAttributesBag; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (lazyNetModuleAttributesBag != null && lazyNetModuleAttributesBag.IsDecodedWellKnownAttributeDataComputed) | ||
{ | ||
var data = (CommonAssemblyWellKnownAttributeData)lazyNetModuleAttributesBag.DecodedWellKnownAttributeData; | ||
return data?.ExperimentalAttributeData; | ||
} | ||
|
||
if (GetAttributeDeclarations().IsEmpty) | ||
{ | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an optimization. It allows not producing a lazy diagnostic when we know from syntax that there are no attributes. |
||
} | ||
|
||
return ObsoleteAttributeData.Uninitialized; | ||
} | ||
} | ||
|
||
#nullable disable | ||
|
||
internal override IEnumerable<NamedTypeSymbol> GetAllTopLevelForwardedTypes() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this doc comment is duplicate of the base one, hence not needed.
Btw, should the base comment be updated to mention ExperimentalAttribute?
(Same for VB in multiple places.)