未验证 提交 3cda26a4 编写于 作者: A AlekseyTs 提交者: GitHub

CheckPresenceOfTypeIdentifierAttribute - avoid requesting syntax trees if we...

CheckPresenceOfTypeIdentifierAttribute - avoid requesting syntax trees if we know that we already decoded all well-known attributes. (#24576)

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems?id=537870.
上级 644cb4f4
......@@ -772,6 +772,12 @@ internal override bool IsExplicitDefinitionOfNoPiaLocalType
private void CheckPresenceOfTypeIdentifierAttribute()
{
// Have we already decoded well-known attributes?
if (_lazyCustomAttributesBag?.IsDecodedWellKnownAttributeDataComputed == true)
{
return;
}
// We want this function to be as cheap as possible, it is called for every top level type
// and we don't want to bind attributes attached to the declaration unless there is a chance
// that one of them is TypeIdentifier attribute.
......
......@@ -1865,6 +1865,12 @@ public interface I1
var i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1");
Assert.True(i1.IsExplicitDefinitionOfNoPiaLocalType);
compilation = CreateStandardCompilation(code);
i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1");
i1.GetAttributes();
Assert.True(i1.IsExplicitDefinitionOfNoPiaLocalType);
}
[Fact]
......@@ -1911,6 +1917,11 @@ public interface I1
// [alias1]
Diagnostic(ErrorCode.ERR_NotAnAttributeClass, "alias1").WithArguments("TypeIdentifier").WithLocation(8, 6)
);
compilation = CreateStandardCompilation(code);
i1 = compilation.SourceAssembly.GetTypeByMetadataName("NS1.I1");
i1.GetAttributes();
Assert.False(i1.IsExplicitDefinitionOfNoPiaLocalType);
}
[Fact]
......
......@@ -2293,6 +2293,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Private Sub CheckPresenceOfTypeIdentifierAttribute()
' Have we already decoded well-known attributes?
If Me.m_lazyCustomAttributesBag?.IsDecodedWellKnownAttributeDataComputed Then
Return
End If
' We want this function to be as cheap as possible, it is called for every top level type
' and we don't want to bind attributes attached to the declaration unless there is a chance
' that one of them is TypeIdentifier attribute.
......
......@@ -3400,7 +3400,7 @@ BC30625: 'Module' statement must end with a matching 'End Module'.
<Fact>
Public Sub IsExplicitDefinitionOfNoPiaLocalType_01()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(
Dim sources =
<compilation>
<file><![CDATA[
Imports System.Runtime.InteropServices
......@@ -3409,11 +3409,17 @@ Imports System.Runtime.InteropServices
Public Interface I1
End Interface
]]></file>
</compilation>)
</compilation>
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(sources)
Dim i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1")
Assert.True(i1.IsExplicitDefinitionOfNoPiaLocalType)
compilation = CompilationUtils.CreateCompilationWithMscorlib(sources)
i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1")
i1.GetAttributes()
Assert.True(i1.IsExplicitDefinitionOfNoPiaLocalType)
End Sub
<Fact>
......@@ -3436,7 +3442,7 @@ End Interface
<Fact>
Public Sub IsExplicitDefinitionOfNoPiaLocalType_03()
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(
Dim sources =
<compilation>
<file><![CDATA[
Imports alias1 = System.Runtime.InteropServices.TypeIdentifier
......@@ -3445,8 +3451,9 @@ Imports alias1 = System.Runtime.InteropServices.TypeIdentifier
Public Interface I1
End Interface
]]></file>
</compilation>)
</compilation>
Dim compilation = CompilationUtils.CreateCompilationWithMscorlib(sources)
Dim i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1")
Assert.False(i1.IsExplicitDefinitionOfNoPiaLocalType)
......@@ -3460,6 +3467,11 @@ BC30182: Type expected.
<alias1>
~~~~~~
]]></expected>)
compilation = CompilationUtils.CreateCompilationWithMscorlib(sources)
i1 = compilation.SourceAssembly.GetTypeByMetadataName("I1")
i1.GetAttributes()
Assert.False(i1.IsExplicitDefinitionOfNoPiaLocalType)
End Sub
<Fact>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册