\n \n MSB3883: Unexpected exception: \n MSB3883: 意外的异常: \n {StrBegin=\"MSB3883: \"}\n \n \n MSB3053: The assembly alias \"{1}\" on reference \"{0}\" contains illegal characters.\n MSB3053: 引用“{0}”上的程序集别名“{1}”包含非法字符。\n {StrBegin=\"MSB3053: \"}\n \n \n MSB3051: The parameter to the compiler is invalid. {0}\n MSB3051: 编译器的参数无效。 {0}\n {StrBegin=\"MSB3051: \"}\n \n \n MSB3052: The parameter to the compiler is invalid, '{0}{1}' will be ignored.\n MSB3052: 编译器的参数无效,“{0}{1}”将被忽略。\n {StrBegin=\"MSB3052: \"}\n \n \n The string \"{0}\" cannot be converted to a boolean (true/false) value.\n 无法将字符串“{0}”转换为布尔值(true/false)。\n \n \n \n MSB3081: A problem occurred while trying to set the \"{0}\" parameter for the IDE's in-process compiler. {1}\n MSB3081: 尝试设置 IDE 的进程内编译器的“{0}”参数时出现问题。{1}\n {StrBegin=\"MSB3081: \"}\n \n \n MSB3105: The item \"{0}\" was specified more than once in the \"{1}\" parameter. Duplicate items are not supported by the \"{1}\" parameter.\n MSB3105: 在“{1}”参数中指定了项“{0}”多次。“{1}”参数不支持重复项。\n {StrBegin=\"MSB3105: \"}\n \n \n MSB3083: The item \"{0}\" was specified more than once in the \"{1}\" parameter and both items had the same value \"{2}\" for the \"{3}\" metadata. Duplicate items are not supported by the \"{1}\" parameter unless they have different values for the \"{3}\" metadata.\n MSB3083: 在参数“{1}”中指定了项“{0}”多次,并且这两个项对于元数据“{3}”具有相同的值“{2}”。参数“{1}”不支持重复项,除非这些项具有不同的“{3}”元数据值。\n {StrBegin=\"MSB3083: \"}\n \n \n Expected file \"{0}\" does not exist.\n 所需文件“{0}”不存在。\n \n \n \n Reference assembly \"{0}\" already has latest information. Leaving it untouched.\n 引用程序集“{0}”已具有最新信息。请不要改动。\n \n \n \n Could not extract the MVID from \"{0}\". Are you sure it is a reference assembly?\n 无法从“{0}”提取 MVID。是否确定它是引用程序集?\n \n \n \n Failed to check the content hash of the source ref assembly '{0}': {1}\n{2}\n 未能查看源引用程序集“{0}”的内容哈希: {1}\n{2}\n \n \n \n Failed to check the content hash of the destination ref assembly '{0}'. It will be overwritten.\n 未能检查目标引用程序集“{0}”的内容哈希。将对其进行覆盖。\n \n \n \n MSB3082: Task failed because \"{0}\" was not found.\n MSB3082: 由于找不到“{0}”,任务失败。\n {StrBegin=\"MSB3082: \"}\n \n \n MSB3087: An incompatible host object was passed into the \"{0}\" task. The host object for this task must implement the \"{1}\" interface.\n MSB3087: 向任务“{0}”传入了不兼容的宿主对象。此任务的宿主对象必须实现“{1}”接口。\n {StrBegin=\"MSB3087: \"}\n \n \n Item \"{0}\" has attribute \"{1}\" with value \"{2}\" that could not be converted to \"{3}\".\n 项“{0}”具有值为“{2}”的特性“{1}”,该值未能转换为“{3}”。\n \n \n \n The IDE's in-process compiler does not support the specified values for the \"{0}\" parameter. Therefore, this task will fallback to using the command-line compiler.\n IDE 的进程内编译器不支持为“{0}”参数指定的值。因此,此任务将退而使用命令行编译器。\n \n \n \n MSB3104: The referenced assembly \"{0}\" was not found. If this assembly is produced by another one of your projects, please make sure to build that project before building this one.\n MSB3104: 未找到引用的程序集“{0}”。如果此程序集是由你的另一个项目生成的,请确保在生成该项目之后再生成此程序集。\n {StrBegin=\"MSB3104: \"}\n \n \n File \"{0}\" could not be read: {1}\n 无法读取文件 \"{0}\": {1}\n \n \n \n Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.\n 跳过分析器以加快生成速度。可以执行“生成”或“重新生成”命令来运行分析器。\n \n \n \n Shared compilation failed; falling back to tool: {0}\n 共享编译失败; 回到工具: {0}\n \n \n \n Using shared compilation with compiler from directory: {0}\n 对来自后列目录的编译器使用共享编译: {0}\n \n \n \n MSB3401: \"{1}\" is an invalid value for the \"{0}\" parameter. The valid values are: {2}\n MSB3401: “{1}”是无效的“{0}”参数值。有效值为: {2}\n {StrBegin=\"MSB3401: \"}\n \n \n \"{1}\" is an invalid value for the \"{0}\" parameter.\n “{1}”是无效的“{0}”参数值。\n \n \n \n MSB3402: There was an error creating the pdb file \"{0}\". {1}\n MSB3402: 创建 pdb 文件“{0}”时出现错误。{1}\n {StrBegin=\"MSB3402: \"}\n \n \n {0} contains duplicate items '{1}' with conflicting metadata '{2}': '{3}' and '{4}'\n {0} 包含重复项“{1}”和冲突元数据“{2}”:“{3}”和“{4}”\n \n \n \n {0} paths are required to end with a slash or backslash: '{1}'\n 要求“{0}”路径以斜杠或反斜杠结尾:“{1}”\n \n \n \n {0} items must include at least one top-level (not nested) item when {1} is true\n 当 {1} 为 true,{0} 项必须包括至少一个顶级(未嵌套)项\n \n \n \n The value of {0} not found in {1} items, or the corresponding item is not a top-level source root: '{2}'\n 未在 {1} 项中找到值 {0},或者对应项不是顶级源根目录:“{2}”\n \n \n
\n \n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":963,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56416,"string":"56,416"},"pr_title":{"kind":"string","value":"Do not include function type conversions in user-defined conversions"},"pr_description":{"kind":"string","value":"Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-15T18:16:38Z","string":"2021-09-15T18:16:38Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T23:24:46Z","string":"2021-09-24T23:24:46Z"},"previous_commit":{"kind":"string","value":"bb99d0bc89bde01650d2a694d720d600dd952dcb"},"pr_commit":{"kind":"string","value":"3913f352cf066fa485869d866e4753fa721cbe93"},"query":{"kind":"string","value":"Do not include function type conversions in user-defined conversions. Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/EditorFeatures/Test2/IntelliSense/IntellisenseQuickInfoBuilderTests_Lists.vb"},"before_content":{"kind":"string","value":"' Licensed to the .NET Foundation under one or more agreements.\n' The .NET Foundation licenses this file to you under the MIT license.\n' See the LICENSE file in the project root for more information.\n\nImports Microsoft.CodeAnalysis.Classification\nImports Microsoft.CodeAnalysis.Test.Utilities.QuickInfo\nImports Microsoft.VisualStudio.Core.Imaging\nImports Microsoft.VisualStudio.Imaging\nImports Microsoft.VisualStudio.Text.Adornments\n\nNamespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense\n Public Class IntellisenseQuickInfoBuilderTests_Lists\n Inherits AbstractIntellisenseQuickInfoBuilderTests\n\n \n \n \n Public Async Function QuickInfoForBulletedList(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"bullet\">\n /// <%= openItemTag %>Item 1<%= closeItemTag %>\n /// <%= openItemTag %>Item 2<%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n \n \n Public Async Function QuickInfoForNumberedList(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <%= openItemTag %>Item 1<%= closeItemTag %>\n /// <%= openItemTag %>Item 2<%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n Public Async Function QuickInfoForBulletedTermList() As Task\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"bullet\">\n /// <item><term>word1</term><description>Item 1</description></item>\n /// <item><term>word2</term><description>Item 2</description></item>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word1\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word2\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n Public Async Function QuickInfoForNumberedTermList() As Task\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <item><term>word1</term><description>Item 1</description></item>\n /// <item><term>word2</term><description>Item 2</description></item>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word1\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word2\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n \n \n Public Async Function QuickInfoForNestedLists(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <%= openItemTag %>\n /// <list type=\"bullet\">\n /// <%= openItemTag %><para>Line1</para><para>Line2</para><%= closeItemTag %>\n /// <%= openItemTag %>Item 1.2<%= closeItemTag %>\n /// </list>\n /// <%= closeItemTag %>\n /// <%= openItemTag %>\n /// <list type=\"number\">\n /// <%= openItemTag %>Item 2.1<%= closeItemTag %>\n /// <%= openItemTag %><para>Line1</para><para>Line2</para><%= closeItemTag %>\n /// </list>\n /// <%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line1\")),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line2\"))))),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1.2\")))))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2.1\")))),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line1\")),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line2\")))))))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n End Class\nEnd Namespace\n"},"after_content":{"kind":"string","value":"' Licensed to the .NET Foundation under one or more agreements.\n' The .NET Foundation licenses this file to you under the MIT license.\n' See the LICENSE file in the project root for more information.\n\nImports Microsoft.CodeAnalysis.Classification\nImports Microsoft.CodeAnalysis.Test.Utilities.QuickInfo\nImports Microsoft.VisualStudio.Core.Imaging\nImports Microsoft.VisualStudio.Imaging\nImports Microsoft.VisualStudio.Text.Adornments\n\nNamespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense\n Public Class IntellisenseQuickInfoBuilderTests_Lists\n Inherits AbstractIntellisenseQuickInfoBuilderTests\n\n \n \n \n Public Async Function QuickInfoForBulletedList(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"bullet\">\n /// <%= openItemTag %>Item 1<%= closeItemTag %>\n /// <%= openItemTag %>Item 2<%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n \n \n Public Async Function QuickInfoForNumberedList(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <%= openItemTag %>Item 1<%= closeItemTag %>\n /// <%= openItemTag %>Item 2<%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n Public Async Function QuickInfoForBulletedTermList() As Task\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"bullet\">\n /// <item><term>word1</term><description>Item 1</description></item>\n /// <item><term>word2</term><description>Item 2</description></item>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word1\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word2\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n Public Async Function QuickInfoForNumberedTermList() As Task\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <item><term>word1</term><description>Item 1</description></item>\n /// <item><term>word2</term><description>Item 2</description></item>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word1\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1\"))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"word2\", ClassifiedTextRunStyle.Bold),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"–\"),\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2\")))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n\n \n \n \n Public Async Function QuickInfoForNestedLists(itemTags As String()) As Task\n Dim openItemTag = String.Join(\"\", itemTags.Select(Function(tag) $\"<{tag}>\"))\n Dim closeItemTag = String.Join(\"\", itemTags.Reverse().Select(Function(tag) $\"{tag}>\"))\n Dim workspace =\n \n \n \n using System.Threading;\n class MyClass {\n /// <summary>\n /// <list type=\"number\">\n /// <%= openItemTag %>\n /// <list type=\"bullet\">\n /// <%= openItemTag %><para>Line1</para><para>Line2</para><%= closeItemTag %>\n /// <%= openItemTag %>Item 1.2<%= closeItemTag %>\n /// </list>\n /// <%= closeItemTag %>\n /// <%= openItemTag %>\n /// <list type=\"number\">\n /// <%= openItemTag %>Item 2.1<%= closeItemTag %>\n /// <%= openItemTag %><para>Line1</para><para>Line2</para><%= closeItemTag %>\n /// </list>\n /// <%= closeItemTag %>\n /// </list>\n /// </summary>\n void MyMethod() {\n MyM$$ethod();\n }\n }\n \n \n \n\n Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp)\n\n Dim expected = New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPrivate)),\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Keyword, \"void\"),\n New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, \" \"),\n New ClassifiedTextRun(ClassificationTypeNames.ClassName, \"MyClass\", navigationAction:=Sub() Return, \"MyClass\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \".\"),\n New ClassifiedTextRun(ClassificationTypeNames.MethodName, \"MyMethod\", navigationAction:=Sub() Return, \"void MyClass.MyMethod()\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \"(\"),\n New ClassifiedTextRun(ClassificationTypeNames.Punctuation, \")\"))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line1\")),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line2\"))))),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"• \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 1.2\")))))))),\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"1. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Item 2.1\")))),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ContainerElement(\n ContainerElementStyle.Wrapped,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"2. \")),\n New ContainerElement(\n ContainerElementStyle.Stacked,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line1\")),\n New ContainerElement(\n ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding,\n New ClassifiedTextElement(\n New ClassifiedTextRun(ClassificationTypeNames.Text, \"Line2\")))))))))\n\n ToolTipAssert.EqualContent(expected, intellisenseQuickInfo.Item)\n End Function\n End Class\nEnd Namespace\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":964,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56416,"string":"56,416"},"pr_title":{"kind":"string","value":"Do not include function type conversions in user-defined conversions"},"pr_description":{"kind":"string","value":"Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-15T18:16:38Z","string":"2021-09-15T18:16:38Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T23:24:46Z","string":"2021-09-24T23:24:46Z"},"previous_commit":{"kind":"string","value":"bb99d0bc89bde01650d2a694d720d600dd952dcb"},"pr_commit":{"kind":"string","value":"3913f352cf066fa485869d866e4753fa721cbe93"},"query":{"kind":"string","value":"Do not include function type conversions in user-defined conversions. Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/Features/Core/Portable/IntroduceVariable/AbstractIntroduceVariableService.State_Parameter.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Linq;\nusing System.Threading;\nusing Microsoft.CodeAnalysis;\n\nnamespace Microsoft.CodeAnalysis.IntroduceVariable\n{\n internal partial class AbstractIntroduceVariableService\n {\n private partial class State\n {\n private bool IsInParameterContext(\n CancellationToken cancellationToken)\n {\n if (!_service.IsInParameterInitializer(Expression))\n {\n return false;\n }\n\n // The default value for a parameter is a constant. So we always allow it unless it\n // happens to capture one of the method's type parameters.\n var bindingMap = GetSemanticMap(cancellationToken);\n if (bindingMap.AllReferencedSymbols.OfType()\n .Where(tp => tp.TypeParameterKind == TypeParameterKind.Method)\n .Any())\n {\n return false;\n }\n\n return true;\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Linq;\nusing System.Threading;\nusing Microsoft.CodeAnalysis;\n\nnamespace Microsoft.CodeAnalysis.IntroduceVariable\n{\n internal partial class AbstractIntroduceVariableService\n {\n private partial class State\n {\n private bool IsInParameterContext(\n CancellationToken cancellationToken)\n {\n if (!_service.IsInParameterInitializer(Expression))\n {\n return false;\n }\n\n // The default value for a parameter is a constant. So we always allow it unless it\n // happens to capture one of the method's type parameters.\n var bindingMap = GetSemanticMap(cancellationToken);\n if (bindingMap.AllReferencedSymbols.OfType()\n .Where(tp => tp.TypeParameterKind == TypeParameterKind.Method)\n .Any())\n {\n return false;\n }\n\n return true;\n }\n }\n }\n}\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":965,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56416,"string":"56,416"},"pr_title":{"kind":"string","value":"Do not include function type conversions in user-defined conversions"},"pr_description":{"kind":"string","value":"Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"author":{"kind":"string","value":"cston"},"date_created":{"kind":"timestamp","value":"2021-09-15T18:16:38Z","string":"2021-09-15T18:16:38Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T23:24:46Z","string":"2021-09-24T23:24:46Z"},"previous_commit":{"kind":"string","value":"bb99d0bc89bde01650d2a694d720d600dd952dcb"},"pr_commit":{"kind":"string","value":"3913f352cf066fa485869d866e4753fa721cbe93"},"query":{"kind":"string","value":"Do not include function type conversions in user-defined conversions. Removes \"function type conversions\" from the set of \"standard conversions\" so that function type conversions (from the inferred type of a lambda expression or method group to `Delegate`, `Expression` or a base type) are not considered for user-defined conversions.\r\n\r\nFixes #56407\r\n\r\nRelates to test plan #52192"},"filepath":{"kind":"string","value":"./src/Features/Core/Portable/ExternalAccess/VSTypeScript/Api/IVSTypeScriptDiagnosticAnalyzerImplementation.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Collections.Immutable;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api\n{\n internal interface IVSTypeScriptDiagnosticAnalyzerImplementation\n {\n Task> AnalyzeProjectAsync(Project project, CancellationToken cancellationToken);\n Task> AnalyzeDocumentSyntaxAsync(Document document, CancellationToken cancellationToken);\n Task> AnalyzeDocumentSemanticsAsync(Document document, CancellationToken cancellationToken);\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\nusing System.Collections.Immutable;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api\n{\n internal interface IVSTypeScriptDiagnosticAnalyzerImplementation\n {\n Task> AnalyzeProjectAsync(Project project, CancellationToken cancellationToken);\n Task> AnalyzeDocumentSyntaxAsync(Document document, CancellationToken cancellationToken);\n Task> AnalyzeDocumentSemanticsAsync(Document document, CancellationToken cancellationToken);\n }\n}\n"},"label":{"kind":"number","value":-1,"string":"-1"}}},{"rowIdx":966,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Declarations/DeclarationTreeBuilder.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Linq;\nusing Microsoft.CodeAnalysis.Collections;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Roslyn.Utilities;\nusing CoreInternalSyntax = Microsoft.CodeAnalysis.Syntax.InternalSyntax;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class DeclarationTreeBuilder : CSharpSyntaxVisitor\n {\n private readonly SyntaxTree _syntaxTree;\n private readonly string _scriptClassName;\n private readonly bool _isSubmission;\n\n private DeclarationTreeBuilder(SyntaxTree syntaxTree, string scriptClassName, bool isSubmission)\n {\n _syntaxTree = syntaxTree;\n _scriptClassName = scriptClassName;\n _isSubmission = isSubmission;\n }\n\n public static RootSingleNamespaceDeclaration ForTree(\n SyntaxTree syntaxTree,\n string scriptClassName,\n bool isSubmission)\n {\n var builder = new DeclarationTreeBuilder(syntaxTree, scriptClassName, isSubmission);\n return (RootSingleNamespaceDeclaration)builder.Visit(syntaxTree.GetRoot());\n }\n\n private ImmutableArray VisitNamespaceChildren(\n CSharpSyntaxNode node,\n SyntaxList members,\n CoreInternalSyntax.SyntaxList internalMembers)\n {\n Debug.Assert(\n node.Kind() is SyntaxKind.NamespaceDeclaration or SyntaxKind.FileScopedNamespaceDeclaration ||\n (node.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind == SourceCodeKind.Regular));\n\n if (members.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n // We look for members that are not allowed in a namespace. \n // If there are any we create an implicit class to wrap them.\n bool hasGlobalMembers = false;\n bool acceptSimpleProgram = node.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind == SourceCodeKind.Regular;\n bool hasAwaitExpressions = false;\n bool isIterator = false;\n bool hasReturnWithExpression = false;\n GlobalStatementSyntax firstGlobalStatement = null;\n bool hasNonEmptyGlobalStatement = false;\n\n var childrenBuilder = ArrayBuilder.GetInstance();\n foreach (var member in members)\n {\n SingleNamespaceOrTypeDeclaration namespaceOrType = Visit(member);\n if (namespaceOrType != null)\n {\n childrenBuilder.Add(namespaceOrType);\n }\n else if (acceptSimpleProgram && member.IsKind(SyntaxKind.GlobalStatement))\n {\n var global = (GlobalStatementSyntax)member;\n firstGlobalStatement ??= global;\n var topLevelStatement = global.Statement;\n\n if (!topLevelStatement.IsKind(SyntaxKind.EmptyStatement))\n {\n hasNonEmptyGlobalStatement = true;\n }\n\n if (!hasAwaitExpressions)\n {\n hasAwaitExpressions = SyntaxFacts.HasAwaitOperations(topLevelStatement);\n }\n\n if (!isIterator)\n {\n isIterator = SyntaxFacts.HasYieldOperations(topLevelStatement);\n }\n\n if (!hasReturnWithExpression)\n {\n hasReturnWithExpression = SyntaxFacts.HasReturnWithExpression(topLevelStatement);\n }\n }\n else if (!hasGlobalMembers && member.Kind() != SyntaxKind.IncompleteMember)\n {\n hasGlobalMembers = true;\n }\n }\n\n // wrap all global statements in a compilation unit into a simple program type:\n if (firstGlobalStatement is object)\n {\n var diagnostics = ImmutableArray.Empty;\n\n if (!hasNonEmptyGlobalStatement)\n {\n var bag = DiagnosticBag.GetInstance();\n bag.Add(ErrorCode.ERR_SimpleProgramIsEmpty, ((EmptyStatementSyntax)firstGlobalStatement.Statement).SemicolonToken.GetLocation());\n diagnostics = bag.ToReadOnlyAndFree();\n }\n\n childrenBuilder.Add(CreateSimpleProgram(firstGlobalStatement, hasAwaitExpressions, isIterator, hasReturnWithExpression, diagnostics));\n }\n\n // wrap all members that are defined in a namespace or compilation unit into an implicit type:\n if (hasGlobalMembers)\n {\n //The implicit class is not static and has no extensions\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = SingleTypeDeclaration.TypeDeclarationFlags.None;\n var memberNames = GetNonTypeMemberNames(internalMembers, ref declFlags, skipGlobalStatements: acceptSimpleProgram);\n var container = _syntaxTree.GetReference(node);\n\n childrenBuilder.Add(CreateImplicitClass(memberNames, container, declFlags));\n }\n\n return childrenBuilder.ToImmutableAndFree();\n }\n\n private static SingleNamespaceOrTypeDeclaration CreateImplicitClass(ImmutableSegmentedDictionary memberNames, SyntaxReference container, SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n return new SingleTypeDeclaration(\n kind: DeclarationKind.ImplicitClass,\n name: TypeSymbol.ImplicitTypeName,\n arity: 0,\n modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Sealed,\n declFlags: declFlags,\n syntaxReference: container,\n nameLocation: new SourceLocation(container),\n memberNames: memberNames,\n children: ImmutableArray.Empty,\n diagnostics: ImmutableArray.Empty);\n }\n\n private static SingleNamespaceOrTypeDeclaration CreateSimpleProgram(GlobalStatementSyntax firstGlobalStatement, bool hasAwaitExpressions, bool isIterator, bool hasReturnWithExpression, ImmutableArray diagnostics)\n {\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Class,\n name: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName,\n arity: 0,\n modifiers: DeclarationModifiers.Partial,\n declFlags: (hasAwaitExpressions ? SingleTypeDeclaration.TypeDeclarationFlags.HasAwaitExpressions : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n (isIterator ? SingleTypeDeclaration.TypeDeclarationFlags.IsIterator : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n (hasReturnWithExpression ? SingleTypeDeclaration.TypeDeclarationFlags.HasReturnWithExpression : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n SingleTypeDeclaration.TypeDeclarationFlags.IsSimpleProgram,\n syntaxReference: firstGlobalStatement.SyntaxTree.GetReference(firstGlobalStatement.Parent),\n nameLocation: new SourceLocation(firstGlobalStatement.GetFirstToken()),\n memberNames: ImmutableSegmentedDictionary.Empty,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics);\n }\n\n /// \n /// Creates a root declaration that contains a Script class declaration (possibly in a namespace) and namespace declarations.\n /// Top-level declarations in script code are nested in Script class.\n /// \n private RootSingleNamespaceDeclaration CreateScriptRootDeclaration(CompilationUnitSyntax compilationUnit)\n {\n Debug.Assert(_syntaxTree.Options.Kind != SourceCodeKind.Regular);\n\n var members = compilationUnit.Members;\n var rootChildren = ArrayBuilder.GetInstance();\n var scriptChildren = ArrayBuilder.GetInstance();\n\n foreach (var member in members)\n {\n var decl = Visit(member);\n if (decl != null)\n {\n // Although namespaces are not allowed in script code process them \n // here as if they were to improve error reporting.\n if (decl.Kind == DeclarationKind.Namespace)\n {\n rootChildren.Add(decl);\n }\n else\n {\n scriptChildren.Add((SingleTypeDeclaration)decl);\n }\n }\n }\n\n //Script class is not static and contains no extensions.\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = SingleTypeDeclaration.TypeDeclarationFlags.None;\n var membernames = GetNonTypeMemberNames(((Syntax.InternalSyntax.CompilationUnitSyntax)(compilationUnit.Green)).Members, ref declFlags);\n rootChildren.Add(\n CreateScriptClass(\n compilationUnit,\n scriptChildren.ToImmutableAndFree(),\n membernames,\n declFlags));\n\n return CreateRootSingleNamespaceDeclaration(compilationUnit, rootChildren.ToImmutableAndFree(), isForScript: true);\n }\n\n private static ImmutableArray GetReferenceDirectives(CompilationUnitSyntax compilationUnit)\n {\n IList directiveNodes = compilationUnit.GetReferenceDirectives(\n d => !d.File.ContainsDiagnostics && !string.IsNullOrEmpty(d.File.ValueText));\n if (directiveNodes.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n var directives = ArrayBuilder.GetInstance(directiveNodes.Count);\n foreach (var directiveNode in directiveNodes)\n {\n directives.Add(new ReferenceDirective(directiveNode.File.ValueText, new SourceLocation(directiveNode)));\n }\n return directives.ToImmutableAndFree();\n }\n\n private SingleNamespaceOrTypeDeclaration CreateScriptClass(\n CompilationUnitSyntax parent,\n ImmutableArray children,\n ImmutableSegmentedDictionary memberNames,\n SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n Debug.Assert(parent.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind != SourceCodeKind.Regular);\n\n // script type is represented by the parent node:\n var parentReference = _syntaxTree.GetReference(parent);\n var fullName = _scriptClassName.Split('.');\n\n // Note: The symbol representing the merged declarations uses parentReference to enumerate non-type members.\n SingleNamespaceOrTypeDeclaration decl = new SingleTypeDeclaration(\n kind: _isSubmission ? DeclarationKind.Submission : DeclarationKind.Script,\n name: fullName.Last(),\n arity: 0,\n modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Sealed,\n declFlags: declFlags,\n syntaxReference: parentReference,\n nameLocation: new SourceLocation(parentReference),\n memberNames: memberNames,\n children: children,\n diagnostics: ImmutableArray.Empty);\n\n for (int i = fullName.Length - 2; i >= 0; i--)\n {\n decl = SingleNamespaceDeclaration.Create(\n name: fullName[i],\n hasUsings: false,\n hasExternAliases: false,\n syntaxReference: parentReference,\n nameLocation: new SourceLocation(parentReference),\n children: ImmutableArray.Create(decl),\n diagnostics: ImmutableArray.Empty);\n }\n\n return decl;\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitCompilationUnit(CompilationUnitSyntax compilationUnit)\n {\n if (_syntaxTree.Options.Kind != SourceCodeKind.Regular)\n {\n return CreateScriptRootDeclaration(compilationUnit);\n }\n\n var children = VisitNamespaceChildren(compilationUnit, compilationUnit.Members, ((Syntax.InternalSyntax.CompilationUnitSyntax)(compilationUnit.Green)).Members);\n\n return CreateRootSingleNamespaceDeclaration(compilationUnit, children, isForScript: false);\n }\n\n private RootSingleNamespaceDeclaration CreateRootSingleNamespaceDeclaration(CompilationUnitSyntax compilationUnit, ImmutableArray children, bool isForScript)\n {\n bool hasUsings = false;\n bool hasGlobalUsings = false;\n bool reportedGlobalUsingOutOfOrder = false;\n var diagnostics = DiagnosticBag.GetInstance();\n\n foreach (var directive in compilationUnit.Usings)\n {\n if (directive.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))\n {\n hasGlobalUsings = true;\n\n if (hasUsings && !reportedGlobalUsingOutOfOrder)\n {\n reportedGlobalUsingOutOfOrder = true;\n diagnostics.Add(ErrorCode.ERR_GlobalUsingOutOfOrder, directive.GlobalKeyword.GetLocation());\n }\n }\n else\n {\n hasUsings = true;\n }\n }\n\n return new RootSingleNamespaceDeclaration(\n hasGlobalUsings: hasGlobalUsings,\n hasUsings: hasUsings,\n hasExternAliases: compilationUnit.Externs.Any(),\n treeNode: _syntaxTree.GetReference(compilationUnit),\n children: children,\n referenceDirectives: isForScript ? GetReferenceDirectives(compilationUnit) : ImmutableArray.Empty,\n hasAssemblyAttributes: compilationUnit.AttributeLists.Any(),\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclarationSyntax node)\n => this.VisitBaseNamespaceDeclaration(node);\n\n public override SingleNamespaceOrTypeDeclaration VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)\n => this.VisitBaseNamespaceDeclaration(node);\n\n private SingleNamespaceDeclaration VisitBaseNamespaceDeclaration(BaseNamespaceDeclarationSyntax node)\n {\n var children = VisitNamespaceChildren(node, node.Members, ((Syntax.InternalSyntax.BaseNamespaceDeclarationSyntax)node.Green).Members);\n\n bool hasUsings = node.Usings.Any();\n bool hasExterns = node.Externs.Any();\n NameSyntax name = node.Name;\n CSharpSyntaxNode currentNode = node;\n QualifiedNameSyntax dotted;\n while ((dotted = name as QualifiedNameSyntax) != null)\n {\n var ns = SingleNamespaceDeclaration.Create(\n name: dotted.Right.Identifier.ValueText,\n hasUsings: hasUsings,\n hasExternAliases: hasExterns,\n syntaxReference: _syntaxTree.GetReference(currentNode),\n nameLocation: new SourceLocation(dotted.Right),\n children: children,\n diagnostics: ImmutableArray.Empty);\n\n var nsDeclaration = new[] { ns };\n children = nsDeclaration.AsImmutableOrNull();\n currentNode = name = dotted.Left;\n hasUsings = false;\n hasExterns = false;\n }\n\n var diagnostics = DiagnosticBag.GetInstance();\n\n if (node is FileScopedNamespaceDeclarationSyntax)\n {\n if (node.Parent is FileScopedNamespaceDeclarationSyntax)\n {\n // Happens when user writes:\n // namespace A.B;\n // namespace X.Y;\n diagnostics.Add(ErrorCode.ERR_MultipleFileScopedNamespace, node.Name.GetLocation());\n }\n else if (node.Parent is NamespaceDeclarationSyntax)\n {\n // Happens with:\n //\n // namespace A.B\n // {\n // namespace X.Y;\n diagnostics.Add(ErrorCode.ERR_FileScopedAndNormalNamespace, node.Name.GetLocation());\n }\n else\n {\n // Happens with cases like:\n //\n // namespace A.B { }\n // namespace X.Y;\n //\n // or even\n //\n // class C { }\n // namespace X.Y;\n\n Debug.Assert(node.Parent is CompilationUnitSyntax);\n var compilationUnit = (CompilationUnitSyntax)node.Parent;\n if (node != compilationUnit.Members[0])\n {\n diagnostics.Add(ErrorCode.ERR_FileScopedNamespaceNotBeforeAllMembers, node.Name.GetLocation());\n }\n }\n }\n else\n {\n Debug.Assert(node is NamespaceDeclarationSyntax);\n\n // namespace X.Y;\n // namespace A.B { }\n if (node.Parent is FileScopedNamespaceDeclarationSyntax)\n {\n diagnostics.Add(ErrorCode.ERR_FileScopedAndNormalNamespace, node.Name.GetLocation());\n }\n }\n\n if (ContainsGeneric(node.Name))\n {\n // We're not allowed to have generics.\n diagnostics.Add(ErrorCode.ERR_UnexpectedGenericName, node.Name.GetLocation());\n }\n\n if (ContainsAlias(node.Name))\n {\n diagnostics.Add(ErrorCode.ERR_UnexpectedAliasedName, node.Name.GetLocation());\n }\n\n if (node.AttributeLists.Count > 0)\n {\n diagnostics.Add(ErrorCode.ERR_BadModifiersOnNamespace, node.AttributeLists[0].GetLocation());\n }\n\n if (node.Modifiers.Count > 0)\n {\n diagnostics.Add(ErrorCode.ERR_BadModifiersOnNamespace, node.Modifiers[0].GetLocation());\n }\n\n foreach (var directive in node.Usings)\n {\n if (directive.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))\n {\n diagnostics.Add(ErrorCode.ERR_GlobalUsingInNamespace, directive.GlobalKeyword.GetLocation());\n break;\n }\n }\n\n // NOTE: *Something* has to happen for alias-qualified names. It turns out that we\n // just grab the part after the colons (via GetUnqualifiedName, below). This logic\n // must be kept in sync with NamespaceSymbol.GetNestedNamespace.\n return SingleNamespaceDeclaration.Create(\n name: name.GetUnqualifiedName().Identifier.ValueText,\n hasUsings: hasUsings,\n hasExternAliases: hasExterns,\n syntaxReference: _syntaxTree.GetReference(currentNode),\n nameLocation: new SourceLocation(name),\n children: children,\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n private static bool ContainsAlias(NameSyntax name)\n {\n switch (name.Kind())\n {\n case SyntaxKind.GenericName:\n return false;\n case SyntaxKind.AliasQualifiedName:\n return true;\n case SyntaxKind.QualifiedName:\n var qualifiedName = (QualifiedNameSyntax)name;\n return ContainsAlias(qualifiedName.Left);\n }\n\n return false;\n }\n\n private static bool ContainsGeneric(NameSyntax name)\n {\n switch (name.Kind())\n {\n case SyntaxKind.GenericName:\n return true;\n case SyntaxKind.AliasQualifiedName:\n return ContainsGeneric(((AliasQualifiedNameSyntax)name).Name);\n case SyntaxKind.QualifiedName:\n var qualifiedName = (QualifiedNameSyntax)name;\n return ContainsGeneric(qualifiedName.Left) || ContainsGeneric(qualifiedName.Right);\n }\n\n return false;\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitClassDeclaration(ClassDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Class);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitStructDeclaration(StructDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Struct);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Interface);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitRecordDeclaration(RecordDeclarationSyntax node)\n {\n var declarationKind = node.Kind() switch\n {\n SyntaxKind.RecordDeclaration => DeclarationKind.Record,\n SyntaxKind.RecordStructDeclaration => DeclarationKind.RecordStruct,\n _ => throw ExceptionUtilities.UnexpectedValue(node.Kind())\n };\n\n return VisitTypeDeclaration(node, declarationKind);\n }\n\n private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyntax node, DeclarationKind kind)\n {\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ?\n SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes :\n SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n if (node.BaseList != null)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;\n }\n\n var diagnostics = DiagnosticBag.GetInstance();\n if (node.Arity == 0)\n {\n Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);\n }\n\n var memberNames = GetNonTypeMemberNames(((Syntax.InternalSyntax.TypeDeclarationSyntax)(node.Green)).Members,\n ref declFlags);\n\n // A record with parameters at least has a primary constructor\n if (((declFlags & SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers) == 0) &&\n node is RecordDeclarationSyntax { ParameterList: { } })\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n\n return new SingleTypeDeclaration(\n kind: kind,\n name: node.Identifier.ValueText,\n modifiers: modifiers,\n arity: node.Arity,\n declFlags: declFlags,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: memberNames,\n children: VisitTypeChildren(node),\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n private ImmutableArray VisitTypeChildren(TypeDeclarationSyntax node)\n {\n if (node.Members.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n var children = ArrayBuilder.GetInstance();\n foreach (var member in node.Members)\n {\n var typeDecl = Visit(member) as SingleTypeDeclaration;\n if (typeDecl != null)\n {\n children.Add(typeDecl);\n }\n }\n\n return children.ToImmutableAndFree();\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitDelegateDeclaration(DelegateDeclarationSyntax node)\n {\n var declFlags = node.AttributeLists.Any()\n ? SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes\n : SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n var diagnostics = DiagnosticBag.GetInstance();\n if (node.Arity == 0)\n {\n Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);\n }\n\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Delegate,\n name: node.Identifier.ValueText,\n modifiers: modifiers,\n declFlags: declFlags,\n arity: node.Arity,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: ImmutableSegmentedDictionary.Empty,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitEnumDeclaration(EnumDeclarationSyntax node)\n {\n var members = node.Members;\n\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ?\n SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes :\n SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n if (node.BaseList != null)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;\n }\n\n ImmutableSegmentedDictionary memberNames = GetEnumMemberNames(members, ref declFlags);\n\n var diagnostics = DiagnosticBag.GetInstance();\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Enum,\n name: node.Identifier.ValueText,\n arity: 0,\n modifiers: modifiers,\n declFlags: declFlags,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: memberNames,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n private static readonly ObjectPool.Builder> s_memberNameBuilderPool =\n new ObjectPool.Builder>(() => ImmutableSegmentedDictionary.CreateBuilder());\n\n private static ImmutableSegmentedDictionary ToImmutableAndFree(ImmutableSegmentedDictionary.Builder builder)\n {\n var result = builder.ToImmutable();\n builder.Clear();\n s_memberNameBuilderPool.Free(builder);\n return result;\n }\n\n private static ImmutableSegmentedDictionary GetEnumMemberNames(SeparatedSyntaxList members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n var cnt = members.Count;\n\n var memberNamesBuilder = s_memberNameBuilderPool.Allocate();\n if (cnt != 0)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n bool anyMemberHasAttributes = false;\n foreach (var member in members)\n {\n memberNamesBuilder.TryAdd(member.Identifier.ValueText);\n if (!anyMemberHasAttributes && member.AttributeLists.Any())\n {\n anyMemberHasAttributes = true;\n }\n }\n\n if (anyMemberHasAttributes)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasAttributes;\n }\n\n return ToImmutableAndFree(memberNamesBuilder);\n }\n\n private static ImmutableSegmentedDictionary GetNonTypeMemberNames(\n CoreInternalSyntax.SyntaxList members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags, bool skipGlobalStatements = false)\n {\n bool anyMethodHadExtensionSyntax = false;\n bool anyMemberHasAttributes = false;\n bool anyNonTypeMembers = false;\n\n var memberNameBuilder = s_memberNameBuilderPool.Allocate();\n\n foreach (var member in members)\n {\n AddNonTypeMemberNames(member, memberNameBuilder, ref anyNonTypeMembers, skipGlobalStatements);\n\n // Check to see if any method contains a 'this' modifier on its first parameter.\n // This data is used to determine if a type needs to have its members materialized\n // as part of extension method lookup.\n if (!anyMethodHadExtensionSyntax && CheckMethodMemberForExtensionSyntax(member))\n {\n anyMethodHadExtensionSyntax = true;\n }\n\n if (!anyMemberHasAttributes && CheckMemberForAttributes(member))\n {\n anyMemberHasAttributes = true;\n }\n }\n\n if (anyMethodHadExtensionSyntax)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasExtensionMethodSyntax;\n }\n\n if (anyMemberHasAttributes)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasAttributes;\n }\n\n if (anyNonTypeMembers)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n return ToImmutableAndFree(memberNameBuilder);\n }\n\n private static bool CheckMethodMemberForExtensionSyntax(Syntax.InternalSyntax.CSharpSyntaxNode member)\n {\n if (member.Kind == SyntaxKind.MethodDeclaration)\n {\n var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;\n\n var paramList = methodDecl.parameterList;\n if (paramList != null)\n {\n var parameters = paramList.Parameters;\n\n if (parameters.Count != 0)\n {\n var firstParameter = parameters[0];\n foreach (var modifier in firstParameter.Modifiers)\n {\n if (modifier.Kind == SyntaxKind.ThisKeyword)\n {\n return true;\n }\n }\n }\n }\n }\n return false;\n }\n\n private static bool CheckMemberForAttributes(Syntax.InternalSyntax.CSharpSyntaxNode member)\n {\n switch (member.Kind)\n {\n case SyntaxKind.CompilationUnit:\n return (((Syntax.InternalSyntax.CompilationUnitSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.EnumDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n return (((Syntax.InternalSyntax.BaseTypeDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.DelegateDeclaration:\n return (((Syntax.InternalSyntax.DelegateDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.FieldDeclaration:\n case SyntaxKind.EventFieldDeclaration:\n return (((Syntax.InternalSyntax.BaseFieldDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.MethodDeclaration:\n case SyntaxKind.OperatorDeclaration:\n case SyntaxKind.ConversionOperatorDeclaration:\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n return (((Syntax.InternalSyntax.BaseMethodDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.PropertyDeclaration:\n case SyntaxKind.EventDeclaration:\n case SyntaxKind.IndexerDeclaration:\n var baseProp = (Syntax.InternalSyntax.BasePropertyDeclarationSyntax)member;\n bool hasAttributes = baseProp.AttributeLists.Any();\n\n if (!hasAttributes && baseProp.AccessorList != null)\n {\n foreach (var accessor in baseProp.AccessorList.Accessors)\n {\n hasAttributes |= accessor.AttributeLists.Any();\n }\n }\n\n return hasAttributes;\n }\n\n return false;\n }\n\n private static void AddNonTypeMemberNames(\n Syntax.InternalSyntax.CSharpSyntaxNode member, ImmutableSegmentedDictionary.Builder set, ref bool anyNonTypeMembers, bool skipGlobalStatements)\n {\n switch (member.Kind)\n {\n case SyntaxKind.FieldDeclaration:\n anyNonTypeMembers = true;\n CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList fieldDeclarators =\n ((Syntax.InternalSyntax.FieldDeclarationSyntax)member).Declaration.Variables;\n int numFieldDeclarators = fieldDeclarators.Count;\n for (int i = 0; i < numFieldDeclarators; i++)\n {\n set.TryAdd(fieldDeclarators[i].Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.EventFieldDeclaration:\n anyNonTypeMembers = true;\n CoreInternalSyntax.SeparatedSyntaxList eventDeclarators =\n ((Syntax.InternalSyntax.EventFieldDeclarationSyntax)member).Declaration.Variables;\n int numEventDeclarators = eventDeclarators.Count;\n for (int i = 0; i < numEventDeclarators; i++)\n {\n set.TryAdd(eventDeclarators[i].Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.MethodDeclaration:\n anyNonTypeMembers = true;\n // Member names are exposed via NamedTypeSymbol.MemberNames and are used primarily\n // as an acid test to determine whether a more in-depth search of a type is worthwhile.\n // We decided that it was reasonable to exclude explicit interface implementations\n // from the list of member names.\n var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;\n if (methodDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(methodDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.PropertyDeclaration:\n anyNonTypeMembers = true;\n // Handle in the same way as explicit method implementations\n var propertyDecl = (Syntax.InternalSyntax.PropertyDeclarationSyntax)member;\n if (propertyDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(propertyDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.EventDeclaration:\n anyNonTypeMembers = true;\n // Handle in the same way as explicit method implementations\n var eventDecl = (Syntax.InternalSyntax.EventDeclarationSyntax)member;\n if (eventDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(eventDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.ConstructorDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(((Syntax.InternalSyntax.ConstructorDeclarationSyntax)member).Modifiers.Any((int)SyntaxKind.StaticKeyword)\n ? WellKnownMemberNames.StaticConstructorName\n : WellKnownMemberNames.InstanceConstructorName);\n break;\n\n case SyntaxKind.DestructorDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(WellKnownMemberNames.DestructorName);\n break;\n\n case SyntaxKind.IndexerDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(WellKnownMemberNames.Indexer);\n break;\n\n case SyntaxKind.OperatorDeclaration:\n {\n anyNonTypeMembers = true;\n\n // Handle in the same way as explicit method implementations\n var opDecl = (Syntax.InternalSyntax.OperatorDeclarationSyntax)member;\n\n if (opDecl.ExplicitInterfaceSpecifier == null)\n {\n var name = OperatorFacts.OperatorNameFromDeclaration(opDecl);\n set.TryAdd(name);\n }\n }\n break;\n\n case SyntaxKind.ConversionOperatorDeclaration:\n {\n anyNonTypeMembers = true;\n\n // Handle in the same way as explicit method implementations\n var opDecl = (Syntax.InternalSyntax.ConversionOperatorDeclarationSyntax)member;\n\n if (opDecl.ExplicitInterfaceSpecifier == null)\n {\n var name = OperatorFacts.OperatorNameFromDeclaration(opDecl);\n set.TryAdd(name);\n }\n }\n break;\n\n case SyntaxKind.GlobalStatement:\n if (!skipGlobalStatements)\n {\n anyNonTypeMembers = true;\n }\n break;\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Linq;\nusing Microsoft.CodeAnalysis.Collections;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Roslyn.Utilities;\nusing CoreInternalSyntax = Microsoft.CodeAnalysis.Syntax.InternalSyntax;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class DeclarationTreeBuilder : CSharpSyntaxVisitor\n {\n private readonly SyntaxTree _syntaxTree;\n private readonly string _scriptClassName;\n private readonly bool _isSubmission;\n\n /// \n /// Any special attributes we may be referencing through a using alias in the file.\n /// For example using X = System.Runtime.CompilerServices.TypeForwardedToAttribute.\n /// \n private QuickAttributes _nonGlobalAliasedQuickAttributes;\n\n private DeclarationTreeBuilder(SyntaxTree syntaxTree, string scriptClassName, bool isSubmission)\n {\n _syntaxTree = syntaxTree;\n _scriptClassName = scriptClassName;\n _isSubmission = isSubmission;\n }\n\n public static RootSingleNamespaceDeclaration ForTree(\n SyntaxTree syntaxTree,\n string scriptClassName,\n bool isSubmission)\n {\n var builder = new DeclarationTreeBuilder(syntaxTree, scriptClassName, isSubmission);\n return (RootSingleNamespaceDeclaration)builder.Visit(syntaxTree.GetRoot());\n }\n\n private ImmutableArray VisitNamespaceChildren(\n CSharpSyntaxNode node,\n SyntaxList members,\n CoreInternalSyntax.SyntaxList internalMembers)\n {\n Debug.Assert(\n node.Kind() is SyntaxKind.NamespaceDeclaration or SyntaxKind.FileScopedNamespaceDeclaration ||\n (node.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind == SourceCodeKind.Regular));\n\n if (members.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n // We look for members that are not allowed in a namespace. \n // If there are any we create an implicit class to wrap them.\n bool hasGlobalMembers = false;\n bool acceptSimpleProgram = node.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind == SourceCodeKind.Regular;\n bool hasAwaitExpressions = false;\n bool isIterator = false;\n bool hasReturnWithExpression = false;\n GlobalStatementSyntax firstGlobalStatement = null;\n bool hasNonEmptyGlobalStatement = false;\n\n var childrenBuilder = ArrayBuilder.GetInstance();\n foreach (var member in members)\n {\n SingleNamespaceOrTypeDeclaration namespaceOrType = Visit(member);\n if (namespaceOrType != null)\n {\n childrenBuilder.Add(namespaceOrType);\n }\n else if (acceptSimpleProgram && member.IsKind(SyntaxKind.GlobalStatement))\n {\n var global = (GlobalStatementSyntax)member;\n firstGlobalStatement ??= global;\n var topLevelStatement = global.Statement;\n\n if (!topLevelStatement.IsKind(SyntaxKind.EmptyStatement))\n {\n hasNonEmptyGlobalStatement = true;\n }\n\n if (!hasAwaitExpressions)\n {\n hasAwaitExpressions = SyntaxFacts.HasAwaitOperations(topLevelStatement);\n }\n\n if (!isIterator)\n {\n isIterator = SyntaxFacts.HasYieldOperations(topLevelStatement);\n }\n\n if (!hasReturnWithExpression)\n {\n hasReturnWithExpression = SyntaxFacts.HasReturnWithExpression(topLevelStatement);\n }\n }\n else if (!hasGlobalMembers && member.Kind() != SyntaxKind.IncompleteMember)\n {\n hasGlobalMembers = true;\n }\n }\n\n // wrap all global statements in a compilation unit into a simple program type:\n if (firstGlobalStatement is object)\n {\n var diagnostics = ImmutableArray.Empty;\n\n if (!hasNonEmptyGlobalStatement)\n {\n var bag = DiagnosticBag.GetInstance();\n bag.Add(ErrorCode.ERR_SimpleProgramIsEmpty, ((EmptyStatementSyntax)firstGlobalStatement.Statement).SemicolonToken.GetLocation());\n diagnostics = bag.ToReadOnlyAndFree();\n }\n\n childrenBuilder.Add(CreateSimpleProgram(firstGlobalStatement, hasAwaitExpressions, isIterator, hasReturnWithExpression, diagnostics));\n }\n\n // wrap all members that are defined in a namespace or compilation unit into an implicit type:\n if (hasGlobalMembers)\n {\n //The implicit class is not static and has no extensions\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = SingleTypeDeclaration.TypeDeclarationFlags.None;\n var memberNames = GetNonTypeMemberNames(internalMembers, ref declFlags, skipGlobalStatements: acceptSimpleProgram);\n var container = _syntaxTree.GetReference(node);\n\n childrenBuilder.Add(CreateImplicitClass(memberNames, container, declFlags));\n }\n\n return childrenBuilder.ToImmutableAndFree();\n }\n\n private static SingleNamespaceOrTypeDeclaration CreateImplicitClass(ImmutableSegmentedDictionary memberNames, SyntaxReference container, SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n return new SingleTypeDeclaration(\n kind: DeclarationKind.ImplicitClass,\n name: TypeSymbol.ImplicitTypeName,\n arity: 0,\n modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Sealed,\n declFlags: declFlags,\n syntaxReference: container,\n nameLocation: new SourceLocation(container),\n memberNames: memberNames,\n children: ImmutableArray.Empty,\n diagnostics: ImmutableArray.Empty,\n quickAttributes: QuickAttributes.None);\n }\n\n private static SingleNamespaceOrTypeDeclaration CreateSimpleProgram(GlobalStatementSyntax firstGlobalStatement, bool hasAwaitExpressions, bool isIterator, bool hasReturnWithExpression, ImmutableArray diagnostics)\n {\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Class,\n name: WellKnownMemberNames.TopLevelStatementsEntryPointTypeName,\n arity: 0,\n modifiers: DeclarationModifiers.Partial,\n declFlags: (hasAwaitExpressions ? SingleTypeDeclaration.TypeDeclarationFlags.HasAwaitExpressions : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n (isIterator ? SingleTypeDeclaration.TypeDeclarationFlags.IsIterator : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n (hasReturnWithExpression ? SingleTypeDeclaration.TypeDeclarationFlags.HasReturnWithExpression : SingleTypeDeclaration.TypeDeclarationFlags.None) |\n SingleTypeDeclaration.TypeDeclarationFlags.IsSimpleProgram,\n syntaxReference: firstGlobalStatement.SyntaxTree.GetReference(firstGlobalStatement.Parent),\n nameLocation: new SourceLocation(firstGlobalStatement.GetFirstToken()),\n memberNames: ImmutableSegmentedDictionary.Empty,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics,\n quickAttributes: QuickAttributes.None);\n }\n\n /// \n /// Creates a root declaration that contains a Script class declaration (possibly in a namespace) and namespace declarations.\n /// Top-level declarations in script code are nested in Script class.\n /// \n private RootSingleNamespaceDeclaration CreateScriptRootDeclaration(CompilationUnitSyntax compilationUnit)\n {\n Debug.Assert(_syntaxTree.Options.Kind != SourceCodeKind.Regular);\n\n var members = compilationUnit.Members;\n var rootChildren = ArrayBuilder.GetInstance();\n var scriptChildren = ArrayBuilder.GetInstance();\n\n foreach (var member in members)\n {\n var decl = Visit(member);\n if (decl != null)\n {\n // Although namespaces are not allowed in script code process them \n // here as if they were to improve error reporting.\n if (decl.Kind == DeclarationKind.Namespace)\n {\n rootChildren.Add(decl);\n }\n else\n {\n scriptChildren.Add((SingleTypeDeclaration)decl);\n }\n }\n }\n\n //Script class is not static and contains no extensions.\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = SingleTypeDeclaration.TypeDeclarationFlags.None;\n var membernames = GetNonTypeMemberNames(((Syntax.InternalSyntax.CompilationUnitSyntax)(compilationUnit.Green)).Members, ref declFlags);\n rootChildren.Add(\n CreateScriptClass(\n compilationUnit,\n scriptChildren.ToImmutableAndFree(),\n membernames,\n declFlags));\n\n return CreateRootSingleNamespaceDeclaration(compilationUnit, rootChildren.ToImmutableAndFree(), isForScript: true);\n }\n\n private static ImmutableArray GetReferenceDirectives(CompilationUnitSyntax compilationUnit)\n {\n IList directiveNodes = compilationUnit.GetReferenceDirectives(\n d => !d.File.ContainsDiagnostics && !string.IsNullOrEmpty(d.File.ValueText));\n if (directiveNodes.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n var directives = ArrayBuilder.GetInstance(directiveNodes.Count);\n foreach (var directiveNode in directiveNodes)\n {\n directives.Add(new ReferenceDirective(directiveNode.File.ValueText, new SourceLocation(directiveNode)));\n }\n return directives.ToImmutableAndFree();\n }\n\n private SingleNamespaceOrTypeDeclaration CreateScriptClass(\n CompilationUnitSyntax parent,\n ImmutableArray children,\n ImmutableSegmentedDictionary memberNames,\n SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n Debug.Assert(parent.Kind() == SyntaxKind.CompilationUnit && _syntaxTree.Options.Kind != SourceCodeKind.Regular);\n\n // script type is represented by the parent node:\n var parentReference = _syntaxTree.GetReference(parent);\n var fullName = _scriptClassName.Split('.');\n\n // Note: The symbol representing the merged declarations uses parentReference to enumerate non-type members.\n SingleNamespaceOrTypeDeclaration decl = new SingleTypeDeclaration(\n kind: _isSubmission ? DeclarationKind.Submission : DeclarationKind.Script,\n name: fullName.Last(),\n arity: 0,\n modifiers: DeclarationModifiers.Internal | DeclarationModifiers.Partial | DeclarationModifiers.Sealed,\n declFlags: declFlags,\n syntaxReference: parentReference,\n nameLocation: new SourceLocation(parentReference),\n memberNames: memberNames,\n children: children,\n diagnostics: ImmutableArray.Empty,\n quickAttributes: QuickAttributes.None);\n\n for (int i = fullName.Length - 2; i >= 0; i--)\n {\n decl = SingleNamespaceDeclaration.Create(\n name: fullName[i],\n hasUsings: false,\n hasExternAliases: false,\n syntaxReference: parentReference,\n nameLocation: new SourceLocation(parentReference),\n children: ImmutableArray.Create(decl),\n diagnostics: ImmutableArray.Empty);\n }\n\n return decl;\n }\n\n private static QuickAttributes GetQuickAttributes(\n SyntaxList usings, bool global)\n {\n var result = QuickAttributes.None;\n\n foreach (var directive in usings)\n {\n if (directive.Alias == null)\n {\n continue;\n }\n\n var isGlobal = directive.GlobalKeyword.Kind() != SyntaxKind.None;\n if (isGlobal != global)\n {\n continue;\n }\n\n result |= QuickAttributeHelpers.GetQuickAttributes(directive.Name.GetUnqualifiedName().Identifier.ValueText, inAttribute: false);\n }\n\n return result;\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitCompilationUnit(CompilationUnitSyntax compilationUnit)\n {\n if (_syntaxTree.Options.Kind != SourceCodeKind.Regular)\n {\n return CreateScriptRootDeclaration(compilationUnit);\n }\n\n _nonGlobalAliasedQuickAttributes = GetNonGlobalAliasedQuickAttributes(compilationUnit);\n\n var children = VisitNamespaceChildren(compilationUnit, compilationUnit.Members, ((Syntax.InternalSyntax.CompilationUnitSyntax)(compilationUnit.Green)).Members);\n\n return CreateRootSingleNamespaceDeclaration(compilationUnit, children, isForScript: false);\n }\n\n private static QuickAttributes GetNonGlobalAliasedQuickAttributes(CompilationUnitSyntax compilationUnit)\n {\n var result = GetQuickAttributes(compilationUnit.Usings, global: false);\n foreach (var member in compilationUnit.Members)\n {\n if (member is BaseNamespaceDeclarationSyntax @namespace)\n {\n result |= GetNonGlobalAliasedQuickAttributes(@namespace);\n }\n }\n\n return result;\n }\n\n private static QuickAttributes GetNonGlobalAliasedQuickAttributes(BaseNamespaceDeclarationSyntax @namespace)\n {\n var result = GetQuickAttributes(@namespace.Usings, global: false);\n foreach (var member in @namespace.Members)\n {\n if (member is BaseNamespaceDeclarationSyntax child)\n {\n result |= GetNonGlobalAliasedQuickAttributes(child);\n }\n }\n\n return result;\n }\n\n private RootSingleNamespaceDeclaration CreateRootSingleNamespaceDeclaration(CompilationUnitSyntax compilationUnit, ImmutableArray children, bool isForScript)\n {\n bool hasUsings = false;\n bool hasGlobalUsings = false;\n bool reportedGlobalUsingOutOfOrder = false;\n var diagnostics = DiagnosticBag.GetInstance();\n\n foreach (var directive in compilationUnit.Usings)\n {\n if (directive.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))\n {\n hasGlobalUsings = true;\n\n if (hasUsings && !reportedGlobalUsingOutOfOrder)\n {\n reportedGlobalUsingOutOfOrder = true;\n diagnostics.Add(ErrorCode.ERR_GlobalUsingOutOfOrder, directive.GlobalKeyword.GetLocation());\n }\n }\n else\n {\n hasUsings = true;\n }\n }\n\n var globalAliasedQuickAttributes = GetQuickAttributes(compilationUnit.Usings, global: true);\n\n return new RootSingleNamespaceDeclaration(\n hasGlobalUsings: hasGlobalUsings,\n hasUsings: hasUsings,\n hasExternAliases: compilationUnit.Externs.Any(),\n treeNode: _syntaxTree.GetReference(compilationUnit),\n children: children,\n referenceDirectives: isForScript ? GetReferenceDirectives(compilationUnit) : ImmutableArray.Empty,\n hasAssemblyAttributes: compilationUnit.AttributeLists.Any(),\n diagnostics: diagnostics.ToReadOnlyAndFree(),\n globalAliasedQuickAttributes);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitFileScopedNamespaceDeclaration(FileScopedNamespaceDeclarationSyntax node)\n => this.VisitBaseNamespaceDeclaration(node);\n\n public override SingleNamespaceOrTypeDeclaration VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)\n => this.VisitBaseNamespaceDeclaration(node);\n\n private SingleNamespaceDeclaration VisitBaseNamespaceDeclaration(BaseNamespaceDeclarationSyntax node)\n {\n var children = VisitNamespaceChildren(node, node.Members, ((Syntax.InternalSyntax.BaseNamespaceDeclarationSyntax)node.Green).Members);\n\n bool hasUsings = node.Usings.Any();\n bool hasExterns = node.Externs.Any();\n NameSyntax name = node.Name;\n CSharpSyntaxNode currentNode = node;\n QualifiedNameSyntax dotted;\n while ((dotted = name as QualifiedNameSyntax) != null)\n {\n var ns = SingleNamespaceDeclaration.Create(\n name: dotted.Right.Identifier.ValueText,\n hasUsings: hasUsings,\n hasExternAliases: hasExterns,\n syntaxReference: _syntaxTree.GetReference(currentNode),\n nameLocation: new SourceLocation(dotted.Right),\n children: children,\n diagnostics: ImmutableArray.Empty);\n\n var nsDeclaration = new[] { ns };\n children = nsDeclaration.AsImmutableOrNull();\n currentNode = name = dotted.Left;\n hasUsings = false;\n hasExterns = false;\n }\n\n var diagnostics = DiagnosticBag.GetInstance();\n\n if (node is FileScopedNamespaceDeclarationSyntax)\n {\n if (node.Parent is FileScopedNamespaceDeclarationSyntax)\n {\n // Happens when user writes:\n // namespace A.B;\n // namespace X.Y;\n diagnostics.Add(ErrorCode.ERR_MultipleFileScopedNamespace, node.Name.GetLocation());\n }\n else if (node.Parent is NamespaceDeclarationSyntax)\n {\n // Happens with:\n //\n // namespace A.B\n // {\n // namespace X.Y;\n diagnostics.Add(ErrorCode.ERR_FileScopedAndNormalNamespace, node.Name.GetLocation());\n }\n else\n {\n // Happens with cases like:\n //\n // namespace A.B { }\n // namespace X.Y;\n //\n // or even\n //\n // class C { }\n // namespace X.Y;\n\n Debug.Assert(node.Parent is CompilationUnitSyntax);\n var compilationUnit = (CompilationUnitSyntax)node.Parent;\n if (node != compilationUnit.Members[0])\n {\n diagnostics.Add(ErrorCode.ERR_FileScopedNamespaceNotBeforeAllMembers, node.Name.GetLocation());\n }\n }\n }\n else\n {\n Debug.Assert(node is NamespaceDeclarationSyntax);\n\n // namespace X.Y;\n // namespace A.B { }\n if (node.Parent is FileScopedNamespaceDeclarationSyntax)\n {\n diagnostics.Add(ErrorCode.ERR_FileScopedAndNormalNamespace, node.Name.GetLocation());\n }\n }\n\n if (ContainsGeneric(node.Name))\n {\n // We're not allowed to have generics.\n diagnostics.Add(ErrorCode.ERR_UnexpectedGenericName, node.Name.GetLocation());\n }\n\n if (ContainsAlias(node.Name))\n {\n diagnostics.Add(ErrorCode.ERR_UnexpectedAliasedName, node.Name.GetLocation());\n }\n\n if (node.AttributeLists.Count > 0)\n {\n diagnostics.Add(ErrorCode.ERR_BadModifiersOnNamespace, node.AttributeLists[0].GetLocation());\n }\n\n if (node.Modifiers.Count > 0)\n {\n diagnostics.Add(ErrorCode.ERR_BadModifiersOnNamespace, node.Modifiers[0].GetLocation());\n }\n\n foreach (var directive in node.Usings)\n {\n if (directive.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword))\n {\n diagnostics.Add(ErrorCode.ERR_GlobalUsingInNamespace, directive.GlobalKeyword.GetLocation());\n break;\n }\n }\n\n // NOTE: *Something* has to happen for alias-qualified names. It turns out that we\n // just grab the part after the colons (via GetUnqualifiedName, below). This logic\n // must be kept in sync with NamespaceSymbol.GetNestedNamespace.\n return SingleNamespaceDeclaration.Create(\n name: name.GetUnqualifiedName().Identifier.ValueText,\n hasUsings: hasUsings,\n hasExternAliases: hasExterns,\n syntaxReference: _syntaxTree.GetReference(currentNode),\n nameLocation: new SourceLocation(name),\n children: children,\n diagnostics: diagnostics.ToReadOnlyAndFree());\n }\n\n private static bool ContainsAlias(NameSyntax name)\n {\n switch (name.Kind())\n {\n case SyntaxKind.GenericName:\n return false;\n case SyntaxKind.AliasQualifiedName:\n return true;\n case SyntaxKind.QualifiedName:\n var qualifiedName = (QualifiedNameSyntax)name;\n return ContainsAlias(qualifiedName.Left);\n }\n\n return false;\n }\n\n private static bool ContainsGeneric(NameSyntax name)\n {\n switch (name.Kind())\n {\n case SyntaxKind.GenericName:\n return true;\n case SyntaxKind.AliasQualifiedName:\n return ContainsGeneric(((AliasQualifiedNameSyntax)name).Name);\n case SyntaxKind.QualifiedName:\n var qualifiedName = (QualifiedNameSyntax)name;\n return ContainsGeneric(qualifiedName.Left) || ContainsGeneric(qualifiedName.Right);\n }\n\n return false;\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitClassDeclaration(ClassDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Class);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitStructDeclaration(StructDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Struct);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)\n {\n return VisitTypeDeclaration(node, DeclarationKind.Interface);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitRecordDeclaration(RecordDeclarationSyntax node)\n {\n var declarationKind = node.Kind() switch\n {\n SyntaxKind.RecordDeclaration => DeclarationKind.Record,\n SyntaxKind.RecordStructDeclaration => DeclarationKind.RecordStruct,\n _ => throw ExceptionUtilities.UnexpectedValue(node.Kind())\n };\n\n return VisitTypeDeclaration(node, declarationKind);\n }\n\n private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyntax node, DeclarationKind kind)\n {\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ?\n SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes :\n SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n if (node.BaseList != null)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;\n }\n\n var diagnostics = DiagnosticBag.GetInstance();\n if (node.Arity == 0)\n {\n Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);\n }\n\n var memberNames = GetNonTypeMemberNames(((Syntax.InternalSyntax.TypeDeclarationSyntax)(node.Green)).Members,\n ref declFlags);\n\n // A record with parameters at least has a primary constructor\n if (((declFlags & SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers) == 0) &&\n node is RecordDeclarationSyntax { ParameterList: { } })\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n var quickAttributes = DeclarationTreeBuilder.GetQuickAttributes(node.AttributeLists);\n\n return new SingleTypeDeclaration(\n kind: kind,\n name: node.Identifier.ValueText,\n arity: node.Arity,\n modifiers: modifiers,\n declFlags: declFlags,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: memberNames,\n children: VisitTypeChildren(node),\n diagnostics: diagnostics.ToReadOnlyAndFree(),\n _nonGlobalAliasedQuickAttributes | quickAttributes);\n }\n\n private ImmutableArray VisitTypeChildren(TypeDeclarationSyntax node)\n {\n if (node.Members.Count == 0)\n {\n return ImmutableArray.Empty;\n }\n\n var children = ArrayBuilder.GetInstance();\n foreach (var member in node.Members)\n {\n var typeDecl = Visit(member) as SingleTypeDeclaration;\n children.AddIfNotNull(typeDecl);\n }\n\n return children.ToImmutableAndFree();\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitDelegateDeclaration(DelegateDeclarationSyntax node)\n {\n var declFlags = node.AttributeLists.Any()\n ? SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes\n : SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n var diagnostics = DiagnosticBag.GetInstance();\n if (node.Arity == 0)\n {\n Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);\n }\n\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n var quickAttributes = DeclarationTreeBuilder.GetQuickAttributes(node.AttributeLists);\n\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Delegate,\n name: node.Identifier.ValueText,\n arity: node.Arity,\n modifiers: modifiers,\n declFlags: declFlags,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: ImmutableSegmentedDictionary.Empty,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics.ToReadOnlyAndFree(),\n _nonGlobalAliasedQuickAttributes | quickAttributes);\n }\n\n public override SingleNamespaceOrTypeDeclaration VisitEnumDeclaration(EnumDeclarationSyntax node)\n {\n var members = node.Members;\n\n SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ?\n SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes :\n SingleTypeDeclaration.TypeDeclarationFlags.None;\n\n if (node.BaseList != null)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;\n }\n\n ImmutableSegmentedDictionary memberNames = GetEnumMemberNames(members, ref declFlags);\n\n var diagnostics = DiagnosticBag.GetInstance();\n var modifiers = node.Modifiers.ToDeclarationModifiers(diagnostics: diagnostics);\n var quickAttributes = DeclarationTreeBuilder.GetQuickAttributes(node.AttributeLists);\n\n return new SingleTypeDeclaration(\n kind: DeclarationKind.Enum,\n name: node.Identifier.ValueText,\n arity: 0,\n modifiers: modifiers,\n declFlags: declFlags,\n syntaxReference: _syntaxTree.GetReference(node),\n nameLocation: new SourceLocation(node.Identifier),\n memberNames: memberNames,\n children: ImmutableArray.Empty,\n diagnostics: diagnostics.ToReadOnlyAndFree(),\n _nonGlobalAliasedQuickAttributes | quickAttributes);\n }\n\n private static QuickAttributes GetQuickAttributes(SyntaxList attributeLists)\n {\n var result = QuickAttributes.None;\n foreach (var attributeList in attributeLists)\n {\n foreach (var attribute in attributeList.Attributes)\n {\n result |= QuickAttributeHelpers.GetQuickAttributes(attribute.Name.GetUnqualifiedName().Identifier.ValueText, inAttribute: true);\n }\n }\n\n return result;\n }\n\n private static readonly ObjectPool.Builder> s_memberNameBuilderPool =\n new ObjectPool.Builder>(() => ImmutableSegmentedDictionary.CreateBuilder());\n\n private static ImmutableSegmentedDictionary ToImmutableAndFree(ImmutableSegmentedDictionary.Builder builder)\n {\n var result = builder.ToImmutable();\n builder.Clear();\n s_memberNameBuilderPool.Free(builder);\n return result;\n }\n\n private static ImmutableSegmentedDictionary GetEnumMemberNames(SeparatedSyntaxList members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags)\n {\n var cnt = members.Count;\n\n var memberNamesBuilder = s_memberNameBuilderPool.Allocate();\n if (cnt != 0)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n bool anyMemberHasAttributes = false;\n foreach (var member in members)\n {\n memberNamesBuilder.TryAdd(member.Identifier.ValueText);\n if (!anyMemberHasAttributes && member.AttributeLists.Any())\n {\n anyMemberHasAttributes = true;\n }\n }\n\n if (anyMemberHasAttributes)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasAttributes;\n }\n\n return ToImmutableAndFree(memberNamesBuilder);\n }\n\n private static ImmutableSegmentedDictionary GetNonTypeMemberNames(\n CoreInternalSyntax.SyntaxList members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags, bool skipGlobalStatements = false)\n {\n bool anyMethodHadExtensionSyntax = false;\n bool anyMemberHasAttributes = false;\n bool anyNonTypeMembers = false;\n\n var memberNameBuilder = s_memberNameBuilderPool.Allocate();\n\n foreach (var member in members)\n {\n AddNonTypeMemberNames(member, memberNameBuilder, ref anyNonTypeMembers, skipGlobalStatements);\n\n // Check to see if any method contains a 'this' modifier on its first parameter.\n // This data is used to determine if a type needs to have its members materialized\n // as part of extension method lookup.\n if (!anyMethodHadExtensionSyntax && CheckMethodMemberForExtensionSyntax(member))\n {\n anyMethodHadExtensionSyntax = true;\n }\n\n if (!anyMemberHasAttributes && CheckMemberForAttributes(member))\n {\n anyMemberHasAttributes = true;\n }\n }\n\n if (anyMethodHadExtensionSyntax)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasExtensionMethodSyntax;\n }\n\n if (anyMemberHasAttributes)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.AnyMemberHasAttributes;\n }\n\n if (anyNonTypeMembers)\n {\n declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;\n }\n\n return ToImmutableAndFree(memberNameBuilder);\n }\n\n private static bool CheckMethodMemberForExtensionSyntax(Syntax.InternalSyntax.CSharpSyntaxNode member)\n {\n if (member.Kind == SyntaxKind.MethodDeclaration)\n {\n var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;\n\n var paramList = methodDecl.parameterList;\n if (paramList != null)\n {\n var parameters = paramList.Parameters;\n\n if (parameters.Count != 0)\n {\n var firstParameter = parameters[0];\n foreach (var modifier in firstParameter.Modifiers)\n {\n if (modifier.Kind == SyntaxKind.ThisKeyword)\n {\n return true;\n }\n }\n }\n }\n }\n return false;\n }\n\n private static bool CheckMemberForAttributes(Syntax.InternalSyntax.CSharpSyntaxNode member)\n {\n switch (member.Kind)\n {\n case SyntaxKind.CompilationUnit:\n return (((Syntax.InternalSyntax.CompilationUnitSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.EnumDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n return (((Syntax.InternalSyntax.BaseTypeDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.DelegateDeclaration:\n return (((Syntax.InternalSyntax.DelegateDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.FieldDeclaration:\n case SyntaxKind.EventFieldDeclaration:\n return (((Syntax.InternalSyntax.BaseFieldDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.MethodDeclaration:\n case SyntaxKind.OperatorDeclaration:\n case SyntaxKind.ConversionOperatorDeclaration:\n case SyntaxKind.ConstructorDeclaration:\n case SyntaxKind.DestructorDeclaration:\n return (((Syntax.InternalSyntax.BaseMethodDeclarationSyntax)member).AttributeLists).Any();\n\n case SyntaxKind.PropertyDeclaration:\n case SyntaxKind.EventDeclaration:\n case SyntaxKind.IndexerDeclaration:\n var baseProp = (Syntax.InternalSyntax.BasePropertyDeclarationSyntax)member;\n bool hasAttributes = baseProp.AttributeLists.Any();\n\n if (!hasAttributes && baseProp.AccessorList != null)\n {\n foreach (var accessor in baseProp.AccessorList.Accessors)\n {\n hasAttributes |= accessor.AttributeLists.Any();\n }\n }\n\n return hasAttributes;\n }\n\n return false;\n }\n\n private static void AddNonTypeMemberNames(\n Syntax.InternalSyntax.CSharpSyntaxNode member, ImmutableSegmentedDictionary.Builder set, ref bool anyNonTypeMembers, bool skipGlobalStatements)\n {\n switch (member.Kind)\n {\n case SyntaxKind.FieldDeclaration:\n anyNonTypeMembers = true;\n CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList fieldDeclarators =\n ((Syntax.InternalSyntax.FieldDeclarationSyntax)member).Declaration.Variables;\n int numFieldDeclarators = fieldDeclarators.Count;\n for (int i = 0; i < numFieldDeclarators; i++)\n {\n set.TryAdd(fieldDeclarators[i].Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.EventFieldDeclaration:\n anyNonTypeMembers = true;\n CoreInternalSyntax.SeparatedSyntaxList eventDeclarators =\n ((Syntax.InternalSyntax.EventFieldDeclarationSyntax)member).Declaration.Variables;\n int numEventDeclarators = eventDeclarators.Count;\n for (int i = 0; i < numEventDeclarators; i++)\n {\n set.TryAdd(eventDeclarators[i].Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.MethodDeclaration:\n anyNonTypeMembers = true;\n // Member names are exposed via NamedTypeSymbol.MemberNames and are used primarily\n // as an acid test to determine whether a more in-depth search of a type is worthwhile.\n // We decided that it was reasonable to exclude explicit interface implementations\n // from the list of member names.\n var methodDecl = (Syntax.InternalSyntax.MethodDeclarationSyntax)member;\n if (methodDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(methodDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.PropertyDeclaration:\n anyNonTypeMembers = true;\n // Handle in the same way as explicit method implementations\n var propertyDecl = (Syntax.InternalSyntax.PropertyDeclarationSyntax)member;\n if (propertyDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(propertyDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.EventDeclaration:\n anyNonTypeMembers = true;\n // Handle in the same way as explicit method implementations\n var eventDecl = (Syntax.InternalSyntax.EventDeclarationSyntax)member;\n if (eventDecl.ExplicitInterfaceSpecifier == null)\n {\n set.TryAdd(eventDecl.Identifier.ValueText);\n }\n break;\n\n case SyntaxKind.ConstructorDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(((Syntax.InternalSyntax.ConstructorDeclarationSyntax)member).Modifiers.Any((int)SyntaxKind.StaticKeyword)\n ? WellKnownMemberNames.StaticConstructorName\n : WellKnownMemberNames.InstanceConstructorName);\n break;\n\n case SyntaxKind.DestructorDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(WellKnownMemberNames.DestructorName);\n break;\n\n case SyntaxKind.IndexerDeclaration:\n anyNonTypeMembers = true;\n set.TryAdd(WellKnownMemberNames.Indexer);\n break;\n\n case SyntaxKind.OperatorDeclaration:\n {\n anyNonTypeMembers = true;\n\n // Handle in the same way as explicit method implementations\n var opDecl = (Syntax.InternalSyntax.OperatorDeclarationSyntax)member;\n\n if (opDecl.ExplicitInterfaceSpecifier == null)\n {\n var name = OperatorFacts.OperatorNameFromDeclaration(opDecl);\n set.TryAdd(name);\n }\n }\n break;\n\n case SyntaxKind.ConversionOperatorDeclaration:\n {\n anyNonTypeMembers = true;\n\n // Handle in the same way as explicit method implementations\n var opDecl = (Syntax.InternalSyntax.ConversionOperatorDeclarationSyntax)member;\n\n if (opDecl.ExplicitInterfaceSpecifier == null)\n {\n var name = OperatorFacts.OperatorNameFromDeclaration(opDecl);\n set.TryAdd(name);\n }\n }\n break;\n\n case SyntaxKind.GlobalStatement:\n if (!skipGlobalStatements)\n {\n anyNonTypeMembers = true;\n }\n break;\n }\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":967,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Declarations/MergedTypeDeclaration.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n // An invariant of a merged type declaration is that all of its children are also merged\n // declarations.\n [DebuggerDisplay(\"{GetDebuggerDisplay(), nq}\")]\n internal sealed class MergedTypeDeclaration : MergedNamespaceOrTypeDeclaration\n {\n private readonly ImmutableArray _declarations;\n private ImmutableArray _lazyChildren;\n private ICollection _lazyMemberNames;\n\n internal MergedTypeDeclaration(ImmutableArray declarations)\n : base(declarations[0].Name)\n {\n _declarations = declarations;\n }\n\n public ImmutableArray Declarations\n {\n get\n {\n return _declarations;\n }\n }\n\n public ImmutableArray SyntaxReferences\n {\n get\n {\n return _declarations.SelectAsArray(r => r.SyntaxReference);\n }\n }\n\n public ImmutableArray> GetAttributeDeclarations()\n {\n var attributeSyntaxListBuilder = ArrayBuilder>.GetInstance();\n\n foreach (var decl in _declarations)\n {\n if (!decl.HasAnyAttributes)\n {\n continue;\n }\n\n var syntaxRef = decl.SyntaxReference;\n var typeDecl = syntaxRef.GetSyntax();\n SyntaxList attributesSyntaxList;\n switch (typeDecl.Kind())\n {\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n attributesSyntaxList = ((TypeDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n case SyntaxKind.DelegateDeclaration:\n attributesSyntaxList = ((DelegateDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n case SyntaxKind.EnumDeclaration:\n attributesSyntaxList = ((EnumDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n default:\n throw ExceptionUtilities.UnexpectedValue(typeDecl.Kind());\n }\n\n attributeSyntaxListBuilder.Add(attributesSyntaxList);\n }\n\n return attributeSyntaxListBuilder.ToImmutableAndFree();\n }\n\n public override DeclarationKind Kind\n {\n get\n {\n return this.Declarations[0].Kind;\n }\n }\n\n public int Arity\n {\n get\n {\n return this.Declarations[0].Arity;\n }\n }\n\n public bool ContainsExtensionMethods\n {\n get\n {\n foreach (var decl in this.Declarations)\n {\n if (decl.AnyMemberHasExtensionMethodSyntax)\n return true;\n }\n\n return false;\n }\n }\n\n public bool AnyMemberHasAttributes\n {\n get\n {\n foreach (var decl in this.Declarations)\n {\n if (decl.AnyMemberHasAttributes)\n return true;\n }\n\n return false;\n }\n }\n\n public LexicalSortKey GetLexicalSortKey(CSharpCompilation compilation)\n {\n LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation);\n for (var i = 1; i < Declarations.Length; i++)\n {\n sortKey = LexicalSortKey.First(sortKey, new LexicalSortKey(Declarations[i].NameLocation, compilation));\n }\n\n return sortKey;\n }\n\n public ImmutableArray NameLocations\n {\n get\n {\n if (Declarations.Length == 1)\n {\n return ImmutableArray.Create(Declarations[0].NameLocation);\n }\n else\n {\n var builder = ArrayBuilder.GetInstance();\n foreach (var decl in Declarations)\n {\n SourceLocation loc = decl.NameLocation;\n if (loc != null)\n builder.Add(loc);\n }\n return builder.ToImmutableAndFree();\n }\n }\n }\n\n private ImmutableArray MakeChildren()\n {\n ArrayBuilder nestedTypes = null;\n\n foreach (var decl in this.Declarations)\n {\n foreach (var child in decl.Children)\n {\n var asType = child as SingleTypeDeclaration;\n if (asType != null)\n {\n if (nestedTypes == null)\n {\n nestedTypes = ArrayBuilder.GetInstance();\n }\n nestedTypes.Add(asType);\n }\n }\n }\n\n var children = ArrayBuilder.GetInstance();\n\n if (nestedTypes != null)\n {\n var typesGrouped = nestedTypes.ToDictionary(t => t.Identity);\n nestedTypes.Free();\n\n foreach (var typeGroup in typesGrouped.Values)\n {\n children.Add(new MergedTypeDeclaration(typeGroup));\n }\n }\n\n return children.ToImmutableAndFree();\n }\n\n public new ImmutableArray Children\n {\n get\n {\n if (_lazyChildren.IsDefault)\n {\n ImmutableInterlocked.InterlockedInitialize(ref _lazyChildren, MakeChildren());\n }\n\n return _lazyChildren;\n }\n }\n\n protected override ImmutableArray GetDeclarationChildren()\n {\n return StaticCast.From(this.Children);\n }\n\n public ICollection MemberNames\n {\n get\n {\n if (_lazyMemberNames == null)\n {\n var names = UnionCollection.Create(this.Declarations, d => d.MemberNames.Keys);\n Interlocked.CompareExchange(ref _lazyMemberNames, names, null);\n }\n\n return _lazyMemberNames;\n }\n }\n\n internal string GetDebuggerDisplay()\n {\n return $\"{nameof(MergedTypeDeclaration)} {Name}\";\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n // An invariant of a merged type declaration is that all of its children are also merged\n // declarations.\n [DebuggerDisplay(\"{GetDebuggerDisplay(), nq}\")]\n internal sealed class MergedTypeDeclaration : MergedNamespaceOrTypeDeclaration\n {\n private readonly ImmutableArray _declarations;\n private ImmutableArray _lazyChildren;\n private ICollection _lazyMemberNames;\n\n internal MergedTypeDeclaration(ImmutableArray declarations)\n : base(declarations[0].Name)\n {\n _declarations = declarations;\n }\n\n public ImmutableArray Declarations\n {\n get\n {\n return _declarations;\n }\n }\n\n public ImmutableArray SyntaxReferences\n {\n get\n {\n return _declarations.SelectAsArray(r => r.SyntaxReference);\n }\n }\n\n /// \n /// Returns the original syntax nodes for this type declaration across all its parts. If\n /// is provided, attributes will not be returned if it\n /// is certain there are none that could match the request. This prevents going back to \n /// source unnecessarily.\n /// \n public ImmutableArray> GetAttributeDeclarations(QuickAttributes? quickAttributes)\n {\n var attributeSyntaxListBuilder = ArrayBuilder>.GetInstance();\n\n foreach (var decl in _declarations)\n {\n if (!decl.HasAnyAttributes)\n {\n continue;\n }\n\n if (quickAttributes != null && (decl.QuickAttributes & quickAttributes.Value) == 0)\n {\n continue;\n }\n\n var syntaxRef = decl.SyntaxReference;\n var typeDecl = syntaxRef.GetSyntax();\n SyntaxList attributesSyntaxList;\n switch (typeDecl.Kind())\n {\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n attributesSyntaxList = ((TypeDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n case SyntaxKind.DelegateDeclaration:\n attributesSyntaxList = ((DelegateDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n case SyntaxKind.EnumDeclaration:\n attributesSyntaxList = ((EnumDeclarationSyntax)typeDecl).AttributeLists;\n break;\n\n default:\n throw ExceptionUtilities.UnexpectedValue(typeDecl.Kind());\n }\n\n attributeSyntaxListBuilder.Add(attributesSyntaxList);\n }\n\n return attributeSyntaxListBuilder.ToImmutableAndFree();\n }\n\n public override DeclarationKind Kind\n {\n get\n {\n return this.Declarations[0].Kind;\n }\n }\n\n public int Arity\n {\n get\n {\n return this.Declarations[0].Arity;\n }\n }\n\n public bool ContainsExtensionMethods\n {\n get\n {\n foreach (var decl in this.Declarations)\n {\n if (decl.AnyMemberHasExtensionMethodSyntax)\n return true;\n }\n\n return false;\n }\n }\n\n public bool AnyMemberHasAttributes\n {\n get\n {\n foreach (var decl in this.Declarations)\n {\n if (decl.AnyMemberHasAttributes)\n return true;\n }\n\n return false;\n }\n }\n\n public LexicalSortKey GetLexicalSortKey(CSharpCompilation compilation)\n {\n LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation);\n for (var i = 1; i < Declarations.Length; i++)\n {\n sortKey = LexicalSortKey.First(sortKey, new LexicalSortKey(Declarations[i].NameLocation, compilation));\n }\n\n return sortKey;\n }\n\n public ImmutableArray NameLocations\n {\n get\n {\n if (Declarations.Length == 1)\n {\n return ImmutableArray.Create(Declarations[0].NameLocation);\n }\n else\n {\n var builder = ArrayBuilder.GetInstance();\n foreach (var decl in Declarations)\n {\n SourceLocation loc = decl.NameLocation;\n if (loc != null)\n builder.Add(loc);\n }\n return builder.ToImmutableAndFree();\n }\n }\n }\n\n private ImmutableArray MakeChildren()\n {\n ArrayBuilder nestedTypes = null;\n\n foreach (var decl in this.Declarations)\n {\n foreach (var child in decl.Children)\n {\n var asType = child as SingleTypeDeclaration;\n if (asType != null)\n {\n if (nestedTypes == null)\n {\n nestedTypes = ArrayBuilder.GetInstance();\n }\n nestedTypes.Add(asType);\n }\n }\n }\n\n var children = ArrayBuilder.GetInstance();\n\n if (nestedTypes != null)\n {\n var typesGrouped = nestedTypes.ToDictionary(t => t.Identity);\n nestedTypes.Free();\n\n foreach (var typeGroup in typesGrouped.Values)\n {\n children.Add(new MergedTypeDeclaration(typeGroup));\n }\n }\n\n return children.ToImmutableAndFree();\n }\n\n public new ImmutableArray Children\n {\n get\n {\n if (_lazyChildren.IsDefault)\n {\n ImmutableInterlocked.InterlockedInitialize(ref _lazyChildren, MakeChildren());\n }\n\n return _lazyChildren;\n }\n }\n\n protected override ImmutableArray GetDeclarationChildren()\n {\n return StaticCast.From(this.Children);\n }\n\n public ICollection MemberNames\n {\n get\n {\n if (_lazyMemberNames == null)\n {\n var names = UnionCollection.Create(this.Declarations, d => d.MemberNames.Keys);\n Interlocked.CompareExchange(ref _lazyMemberNames, names, null);\n }\n\n return _lazyMemberNames;\n }\n }\n\n internal string GetDebuggerDisplay()\n {\n return $\"{nameof(MergedTypeDeclaration)} {Name}\";\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":968,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Declarations/RootSingleNamespaceDeclaration.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Immutable;\nusing System.Diagnostics;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class RootSingleNamespaceDeclaration : SingleNamespaceDeclaration\n {\n private readonly ImmutableArray _referenceDirectives;\n private readonly bool _hasAssemblyAttributes;\n private readonly bool _hasGlobalUsings;\n private readonly bool _hasUsings;\n private readonly bool _hasExternAliases;\n\n public RootSingleNamespaceDeclaration(\n bool hasGlobalUsings,\n bool hasUsings,\n bool hasExternAliases,\n SyntaxReference treeNode,\n ImmutableArray children,\n ImmutableArray referenceDirectives,\n bool hasAssemblyAttributes,\n ImmutableArray diagnostics)\n : base(string.Empty,\n treeNode,\n nameLocation: new SourceLocation(treeNode),\n children: children,\n diagnostics: diagnostics)\n {\n Debug.Assert(!referenceDirectives.IsDefault);\n\n _referenceDirectives = referenceDirectives;\n _hasAssemblyAttributes = hasAssemblyAttributes;\n _hasGlobalUsings = hasGlobalUsings;\n _hasUsings = hasUsings;\n _hasExternAliases = hasExternAliases;\n }\n\n public ImmutableArray ReferenceDirectives\n {\n get\n {\n return _referenceDirectives;\n }\n }\n\n public bool HasAssemblyAttributes\n {\n get\n {\n return _hasAssemblyAttributes;\n }\n }\n\n public override bool HasGlobalUsings\n {\n get\n {\n return _hasGlobalUsings;\n }\n }\n\n public override bool HasUsings\n {\n get\n {\n return _hasUsings;\n }\n }\n\n public override bool HasExternAliases\n {\n get\n {\n return _hasExternAliases;\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class RootSingleNamespaceDeclaration : SingleNamespaceDeclaration\n {\n private readonly ImmutableArray _referenceDirectives;\n private readonly bool _hasAssemblyAttributes;\n private readonly bool _hasGlobalUsings;\n private readonly bool _hasUsings;\n private readonly bool _hasExternAliases;\n\n /// \n /// Any special attributes we may be referencing directly through a global using alias in the file.\n /// global using X = System.Runtime.CompilerServices.TypeForwardedToAttribute.\n /// \n public QuickAttributes GlobalAliasedQuickAttributes { get; }\n\n public RootSingleNamespaceDeclaration(\n bool hasGlobalUsings,\n bool hasUsings,\n bool hasExternAliases,\n SyntaxReference treeNode,\n ImmutableArray children,\n ImmutableArray referenceDirectives,\n bool hasAssemblyAttributes,\n ImmutableArray diagnostics,\n QuickAttributes globalAliasedQuickAttributes)\n : base(string.Empty,\n treeNode,\n nameLocation: new SourceLocation(treeNode),\n children: children,\n diagnostics: diagnostics)\n {\n Debug.Assert(!referenceDirectives.IsDefault);\n\n _referenceDirectives = referenceDirectives;\n _hasAssemblyAttributes = hasAssemblyAttributes;\n _hasGlobalUsings = hasGlobalUsings;\n _hasUsings = hasUsings;\n _hasExternAliases = hasExternAliases;\n GlobalAliasedQuickAttributes = globalAliasedQuickAttributes;\n }\n\n public ImmutableArray ReferenceDirectives\n {\n get\n {\n return _referenceDirectives;\n }\n }\n\n public bool HasAssemblyAttributes\n {\n get\n {\n return _hasAssemblyAttributes;\n }\n }\n\n public override bool HasGlobalUsings\n {\n get\n {\n return _hasGlobalUsings;\n }\n }\n\n public override bool HasUsings\n {\n get\n {\n return _hasUsings;\n }\n }\n\n public override bool HasExternAliases\n {\n get\n {\n return _hasExternAliases;\n }\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":969,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Declarations/SingleTypeDeclaration.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing Microsoft.CodeAnalysis.Collections;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class SingleTypeDeclaration : SingleNamespaceOrTypeDeclaration\n {\n private readonly DeclarationKind _kind;\n private readonly TypeDeclarationFlags _flags;\n private readonly ushort _arity;\n private readonly DeclarationModifiers _modifiers;\n private readonly ImmutableArray _children;\n\n [Flags]\n internal enum TypeDeclarationFlags : ushort\n {\n None = 0,\n AnyMemberHasExtensionMethodSyntax = 1 << 1,\n HasAnyAttributes = 1 << 2,\n HasBaseDeclarations = 1 << 3,\n AnyMemberHasAttributes = 1 << 4,\n HasAnyNontypeMembers = 1 << 5,\n\n /// \n /// Simple program uses await expressions. Set only in conjunction with \n /// \n HasAwaitExpressions = 1 << 6,\n\n /// \n /// Set only in conjunction with \n /// \n IsIterator = 1 << 7,\n\n /// \n /// Set only in conjunction with \n /// \n HasReturnWithExpression = 1 << 8,\n\n IsSimpleProgram = 1 << 9,\n }\n\n internal SingleTypeDeclaration(\n DeclarationKind kind,\n string name,\n int arity,\n DeclarationModifiers modifiers,\n TypeDeclarationFlags declFlags,\n SyntaxReference syntaxReference,\n SourceLocation nameLocation,\n ImmutableSegmentedDictionary memberNames,\n ImmutableArray children,\n ImmutableArray diagnostics)\n : base(name, syntaxReference, nameLocation, diagnostics)\n {\n Debug.Assert(kind != DeclarationKind.Namespace);\n\n _kind = kind;\n _arity = (ushort)arity;\n _modifiers = modifiers;\n MemberNames = memberNames;\n _children = children;\n _flags = declFlags;\n }\n\n public override DeclarationKind Kind\n {\n get\n {\n return _kind;\n }\n }\n\n public new ImmutableArray Children\n {\n get\n {\n return _children;\n }\n }\n\n public int Arity\n {\n get\n {\n return _arity;\n }\n }\n\n public DeclarationModifiers Modifiers\n {\n get\n {\n return _modifiers;\n }\n }\n\n public ImmutableSegmentedDictionary MemberNames { get; }\n\n public bool AnyMemberHasExtensionMethodSyntax\n {\n get\n {\n return (_flags & TypeDeclarationFlags.AnyMemberHasExtensionMethodSyntax) != 0;\n }\n }\n\n public bool HasAnyAttributes\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAnyAttributes) != 0;\n }\n }\n\n public bool HasBaseDeclarations\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasBaseDeclarations) != 0;\n }\n }\n\n public bool AnyMemberHasAttributes\n {\n get\n {\n return (_flags & TypeDeclarationFlags.AnyMemberHasAttributes) != 0;\n }\n }\n\n public bool HasAnyNontypeMembers\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAnyNontypeMembers) != 0;\n }\n }\n\n public bool HasAwaitExpressions\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAwaitExpressions) != 0;\n }\n }\n\n public bool HasReturnWithExpression\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasReturnWithExpression) != 0;\n }\n }\n\n public bool IsIterator\n {\n get\n {\n return (_flags & TypeDeclarationFlags.IsIterator) != 0;\n }\n }\n\n public bool IsSimpleProgram\n {\n get\n {\n return (_flags & TypeDeclarationFlags.IsSimpleProgram) != 0;\n }\n }\n\n protected override ImmutableArray GetNamespaceOrTypeDeclarationChildren()\n {\n return StaticCast.From(_children);\n }\n\n internal TypeDeclarationIdentity Identity\n {\n get\n {\n return new TypeDeclarationIdentity(this);\n }\n }\n\n // identity that is used when collecting all declarations \n // of same type across multiple containers\n internal struct TypeDeclarationIdentity : IEquatable\n {\n private readonly SingleTypeDeclaration _decl;\n\n internal TypeDeclarationIdentity(SingleTypeDeclaration decl)\n {\n _decl = decl;\n }\n\n public override bool Equals(object obj)\n {\n return obj is TypeDeclarationIdentity && Equals((TypeDeclarationIdentity)obj);\n }\n\n public bool Equals(TypeDeclarationIdentity other)\n {\n var thisDecl = _decl;\n var otherDecl = other._decl;\n\n // same as itself\n if ((object)thisDecl == otherDecl)\n {\n return true;\n }\n\n // arity, kind, name must match\n if ((thisDecl._arity != otherDecl._arity) ||\n (thisDecl._kind != otherDecl._kind) ||\n (thisDecl.name != otherDecl.name))\n {\n return false;\n }\n\n if (thisDecl._kind == DeclarationKind.Enum || thisDecl._kind == DeclarationKind.Delegate)\n {\n // oh, so close, but enums and delegates cannot be partial\n return false;\n }\n\n return true;\n }\n\n public override int GetHashCode()\n {\n var thisDecl = _decl;\n return Hash.Combine(thisDecl.Name.GetHashCode(),\n Hash.Combine(thisDecl.Arity.GetHashCode(),\n (int)thisDecl.Kind));\n }\n }\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing Microsoft.CodeAnalysis.Collections;\nusing Microsoft.CodeAnalysis.CSharp.Symbols;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp\n{\n internal sealed class SingleTypeDeclaration : SingleNamespaceOrTypeDeclaration\n {\n private readonly DeclarationKind _kind;\n private readonly TypeDeclarationFlags _flags;\n private readonly ushort _arity;\n private readonly DeclarationModifiers _modifiers;\n private readonly ImmutableArray _children;\n\n /// \n /// Any special attributes we may be referencing directly as an attribute on this type or\n /// through a using alias in the file. For example\n /// using X = System.Runtime.CompilerServices.TypeForwardedToAttribute or\n /// [TypeForwardedToAttribute]. Can be used to avoid having to go back to source\n /// to retrieve attributes whtn there is no chance they would bind to attribute of interest.\n /// \n public QuickAttributes QuickAttributes { get; }\n\n [Flags]\n internal enum TypeDeclarationFlags : ushort\n {\n None = 0,\n AnyMemberHasExtensionMethodSyntax = 1 << 1,\n HasAnyAttributes = 1 << 2,\n HasBaseDeclarations = 1 << 3,\n AnyMemberHasAttributes = 1 << 4,\n HasAnyNontypeMembers = 1 << 5,\n\n /// \n /// Simple program uses await expressions. Set only in conjunction with \n /// \n HasAwaitExpressions = 1 << 6,\n\n /// \n /// Set only in conjunction with \n /// \n IsIterator = 1 << 7,\n\n /// \n /// Set only in conjunction with \n /// \n HasReturnWithExpression = 1 << 8,\n\n IsSimpleProgram = 1 << 9,\n }\n\n internal SingleTypeDeclaration(\n DeclarationKind kind,\n string name,\n int arity,\n DeclarationModifiers modifiers,\n TypeDeclarationFlags declFlags,\n SyntaxReference syntaxReference,\n SourceLocation nameLocation,\n ImmutableSegmentedDictionary memberNames,\n ImmutableArray children,\n ImmutableArray diagnostics,\n QuickAttributes quickAttributes)\n : base(name, syntaxReference, nameLocation, diagnostics)\n {\n Debug.Assert(kind != DeclarationKind.Namespace);\n\n _kind = kind;\n _arity = (ushort)arity;\n _modifiers = modifiers;\n MemberNames = memberNames;\n _children = children;\n _flags = declFlags;\n QuickAttributes = quickAttributes;\n }\n\n public override DeclarationKind Kind\n {\n get\n {\n return _kind;\n }\n }\n\n public new ImmutableArray Children\n {\n get\n {\n return _children;\n }\n }\n\n public int Arity\n {\n get\n {\n return _arity;\n }\n }\n\n public DeclarationModifiers Modifiers\n {\n get\n {\n return _modifiers;\n }\n }\n\n public ImmutableSegmentedDictionary MemberNames { get; }\n\n public bool AnyMemberHasExtensionMethodSyntax\n {\n get\n {\n return (_flags & TypeDeclarationFlags.AnyMemberHasExtensionMethodSyntax) != 0;\n }\n }\n\n public bool HasAnyAttributes\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAnyAttributes) != 0;\n }\n }\n\n public bool HasBaseDeclarations\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasBaseDeclarations) != 0;\n }\n }\n\n public bool AnyMemberHasAttributes\n {\n get\n {\n return (_flags & TypeDeclarationFlags.AnyMemberHasAttributes) != 0;\n }\n }\n\n public bool HasAnyNontypeMembers\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAnyNontypeMembers) != 0;\n }\n }\n\n public bool HasAwaitExpressions\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasAwaitExpressions) != 0;\n }\n }\n\n public bool HasReturnWithExpression\n {\n get\n {\n return (_flags & TypeDeclarationFlags.HasReturnWithExpression) != 0;\n }\n }\n\n public bool IsIterator\n {\n get\n {\n return (_flags & TypeDeclarationFlags.IsIterator) != 0;\n }\n }\n\n public bool IsSimpleProgram\n {\n get\n {\n return (_flags & TypeDeclarationFlags.IsSimpleProgram) != 0;\n }\n }\n\n protected override ImmutableArray GetNamespaceOrTypeDeclarationChildren()\n {\n return StaticCast.From(_children);\n }\n\n internal TypeDeclarationIdentity Identity\n {\n get\n {\n return new TypeDeclarationIdentity(this);\n }\n }\n\n // identity that is used when collecting all declarations \n // of same type across multiple containers\n internal struct TypeDeclarationIdentity : IEquatable\n {\n private readonly SingleTypeDeclaration _decl;\n\n internal TypeDeclarationIdentity(SingleTypeDeclaration decl)\n {\n _decl = decl;\n }\n\n public override bool Equals(object obj)\n {\n return obj is TypeDeclarationIdentity && Equals((TypeDeclarationIdentity)obj);\n }\n\n public bool Equals(TypeDeclarationIdentity other)\n {\n var thisDecl = _decl;\n var otherDecl = other._decl;\n\n // same as itself\n if ((object)thisDecl == otherDecl)\n {\n return true;\n }\n\n // arity, kind, name must match\n if ((thisDecl._arity != otherDecl._arity) ||\n (thisDecl._kind != otherDecl._kind) ||\n (thisDecl.name != otherDecl.name))\n {\n return false;\n }\n\n if (thisDecl._kind == DeclarationKind.Enum || thisDecl._kind == DeclarationKind.Delegate)\n {\n // oh, so close, but enums and delegates cannot be partial\n return false;\n }\n\n return true;\n }\n\n public override int GetHashCode()\n {\n var thisDecl = _decl;\n return Hash.Combine(thisDecl.Name.GetHashCode(),\n Hash.Combine(thisDecl.Arity.GetHashCode(),\n (int)thisDecl.Kind));\n }\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":970,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Symbols/Source/QuickAttributeChecker.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Symbols\n{\n /// \n /// The QuickAttributeChecker applies a simple fast heuristic for determining probable\n /// attributes of certain kinds without binding attribute types, just by looking at the final syntax of an\n /// attribute usage.\n /// \n /// \n /// It works by maintaining a dictionary of all possible simple names that might map to the given\n /// attribute.\n /// \n internal sealed class QuickAttributeChecker\n {\n private readonly Dictionary _nameToAttributeMap;\n private static QuickAttributeChecker _lazyPredefinedQuickAttributeChecker;\n\n#if DEBUG\n private bool _sealed;\n#endif\n\n internal static QuickAttributeChecker Predefined\n {\n get\n {\n if (_lazyPredefinedQuickAttributeChecker is null)\n {\n Interlocked.CompareExchange(ref _lazyPredefinedQuickAttributeChecker, CreatePredefinedQuickAttributeChecker(), null);\n }\n\n return _lazyPredefinedQuickAttributeChecker;\n }\n }\n\n private static QuickAttributeChecker CreatePredefinedQuickAttributeChecker()\n {\n var result = new QuickAttributeChecker();\n result.AddName(AttributeDescription.TypeIdentifierAttribute.Name, QuickAttributes.TypeIdentifier);\n result.AddName(AttributeDescription.TypeForwardedToAttribute.Name, QuickAttributes.TypeForwardedTo);\n result.AddName(AttributeDescription.AssemblyKeyNameAttribute.Name, QuickAttributes.AssemblyKeyName);\n result.AddName(AttributeDescription.AssemblyKeyFileAttribute.Name, QuickAttributes.AssemblyKeyFile);\n result.AddName(AttributeDescription.AssemblySignatureKeyAttribute.Name, QuickAttributes.AssemblySignatureKey);\n\n#if DEBUG\n result._sealed = true;\n#endif\n return result;\n }\n\n private QuickAttributeChecker()\n {\n _nameToAttributeMap = new Dictionary(StringComparer.Ordinal);\n // NOTE: caller must seal\n }\n\n private QuickAttributeChecker(QuickAttributeChecker previous)\n {\n _nameToAttributeMap = new Dictionary(previous._nameToAttributeMap, StringComparer.Ordinal);\n // NOTE: caller must seal\n }\n\n private void AddName(string name, QuickAttributes newAttributes)\n {\n#if DEBUG\n Debug.Assert(!_sealed);\n#endif\n var currentValue = QuickAttributes.None;\n _nameToAttributeMap.TryGetValue(name, out currentValue);\n\n QuickAttributes newValue = newAttributes | currentValue;\n _nameToAttributeMap[name] = newValue;\n }\n\n internal QuickAttributeChecker AddAliasesIfAny(SyntaxList usingsSyntax, bool onlyGlobalAliases = false)\n {\n if (usingsSyntax.Count == 0)\n {\n return this;\n }\n\n QuickAttributeChecker newChecker = null;\n\n foreach (var usingDirective in usingsSyntax)\n {\n if (usingDirective.Alias != null && (!onlyGlobalAliases || usingDirective.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword)))\n {\n string name = usingDirective.Alias.Name.Identifier.ValueText;\n string target = usingDirective.Name.GetUnqualifiedName().Identifier.ValueText;\n\n if (_nameToAttributeMap.TryGetValue(target, out var foundAttributes))\n {\n // copy the QuickAttributes from alias target to alias name\n (newChecker ?? (newChecker = new QuickAttributeChecker(this))).AddName(name, foundAttributes);\n }\n }\n }\n\n if (newChecker != null)\n {\n#if DEBUG\n newChecker._sealed = true;\n#endif\n return newChecker;\n }\n\n return this;\n }\n\n public bool IsPossibleMatch(AttributeSyntax attr, QuickAttributes pattern)\n {\n#if DEBUG\n Debug.Assert(_sealed);\n#endif\n string name = attr.Name.GetUnqualifiedName().Identifier.ValueText;\n QuickAttributes foundAttributes;\n\n // We allow \"Name\" to bind to \"NameAttribute\"\n if (_nameToAttributeMap.TryGetValue(name, out foundAttributes) ||\n _nameToAttributeMap.TryGetValue(name + \"Attribute\", out foundAttributes))\n {\n return (foundAttributes & pattern) != 0;\n }\n\n return false;\n }\n }\n\n [Flags]\n internal enum QuickAttributes : byte\n {\n None = 0,\n TypeIdentifier = 1 << 0,\n TypeForwardedTo = 1 << 1,\n AssemblyKeyName = 1 << 2,\n AssemblyKeyFile = 1 << 3,\n AssemblySignatureKey = 1 << 4,\n }\n}\n"},"after_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Symbols\n{\n /// \n /// The QuickAttributeChecker applies a simple fast heuristic for determining probable\n /// attributes of certain kinds without binding attribute types, just by looking at the final syntax of an\n /// attribute usage.\n /// \n /// \n /// It works by maintaining a dictionary of all possible simple names that might map to the given\n /// attribute.\n /// \n internal sealed class QuickAttributeChecker\n {\n private readonly Dictionary _nameToAttributeMap;\n private static QuickAttributeChecker _lazyPredefinedQuickAttributeChecker;\n\n#if DEBUG\n private bool _sealed;\n#endif\n\n internal static QuickAttributeChecker Predefined\n {\n get\n {\n if (_lazyPredefinedQuickAttributeChecker is null)\n {\n Interlocked.CompareExchange(ref _lazyPredefinedQuickAttributeChecker, CreatePredefinedQuickAttributeChecker(), null);\n }\n\n return _lazyPredefinedQuickAttributeChecker;\n }\n }\n\n private static QuickAttributeChecker CreatePredefinedQuickAttributeChecker()\n {\n var result = new QuickAttributeChecker();\n result.AddName(AttributeDescription.TypeIdentifierAttribute.Name, QuickAttributes.TypeIdentifier);\n result.AddName(AttributeDescription.TypeForwardedToAttribute.Name, QuickAttributes.TypeForwardedTo);\n result.AddName(AttributeDescription.AssemblyKeyNameAttribute.Name, QuickAttributes.AssemblyKeyName);\n result.AddName(AttributeDescription.AssemblyKeyFileAttribute.Name, QuickAttributes.AssemblyKeyFile);\n result.AddName(AttributeDescription.AssemblySignatureKeyAttribute.Name, QuickAttributes.AssemblySignatureKey);\n\n#if DEBUG\n result._sealed = true;\n#endif\n return result;\n }\n\n private QuickAttributeChecker()\n {\n _nameToAttributeMap = new Dictionary(StringComparer.Ordinal);\n // NOTE: caller must seal\n }\n\n private QuickAttributeChecker(QuickAttributeChecker previous)\n {\n _nameToAttributeMap = new Dictionary(previous._nameToAttributeMap, StringComparer.Ordinal);\n // NOTE: caller must seal\n }\n\n private void AddName(string name, QuickAttributes newAttributes)\n {\n#if DEBUG\n Debug.Assert(!_sealed);\n#endif\n var currentValue = QuickAttributes.None;\n _nameToAttributeMap.TryGetValue(name, out currentValue);\n\n QuickAttributes newValue = newAttributes | currentValue;\n _nameToAttributeMap[name] = newValue;\n }\n\n internal QuickAttributeChecker AddAliasesIfAny(SyntaxList usingsSyntax, bool onlyGlobalAliases = false)\n {\n if (usingsSyntax.Count == 0)\n {\n return this;\n }\n\n QuickAttributeChecker newChecker = null;\n\n foreach (var usingDirective in usingsSyntax)\n {\n if (usingDirective.Alias != null && (!onlyGlobalAliases || usingDirective.GlobalKeyword.IsKind(SyntaxKind.GlobalKeyword)))\n {\n string name = usingDirective.Alias.Name.Identifier.ValueText;\n string target = usingDirective.Name.GetUnqualifiedName().Identifier.ValueText;\n\n if (_nameToAttributeMap.TryGetValue(target, out var foundAttributes))\n {\n // copy the QuickAttributes from alias target to alias name\n (newChecker ?? (newChecker = new QuickAttributeChecker(this))).AddName(name, foundAttributes);\n }\n }\n }\n\n if (newChecker != null)\n {\n#if DEBUG\n newChecker._sealed = true;\n#endif\n return newChecker;\n }\n\n return this;\n }\n\n public bool IsPossibleMatch(AttributeSyntax attr, QuickAttributes pattern)\n {\n#if DEBUG\n Debug.Assert(_sealed);\n#endif\n string name = attr.Name.GetUnqualifiedName().Identifier.ValueText;\n QuickAttributes foundAttributes;\n\n // We allow \"Name\" to bind to \"NameAttribute\"\n if (_nameToAttributeMap.TryGetValue(name, out foundAttributes) ||\n _nameToAttributeMap.TryGetValue(name + \"Attribute\", out foundAttributes))\n {\n return (foundAttributes & pattern) != 0;\n }\n\n return false;\n }\n }\n\n [Flags]\n internal enum QuickAttributes : byte\n {\n None = 0,\n TypeIdentifier = 1 << 0,\n TypeForwardedTo = 1 << 1,\n AssemblyKeyName = 1 << 2,\n AssemblyKeyFile = 1 << 3,\n AssemblySignatureKey = 1 << 4,\n Last = AssemblySignatureKey,\n }\n\n internal static class QuickAttributeHelpers\n {\n /// \n /// Returns the that corresponds to the particular type \n /// passed in. If is \n /// then the name will be checked both as-is as well as with the 'Attribute' suffix.\n /// \n public static QuickAttributes GetQuickAttributes(string name, bool inAttribute)\n {\n // Update this code if we add new quick attributes.\n Debug.Assert(QuickAttributes.Last == QuickAttributes.AssemblySignatureKey);\n\n var result = QuickAttributes.None;\n if (matches(AttributeDescription.TypeIdentifierAttribute))\n {\n result |= QuickAttributes.TypeIdentifier;\n }\n else if (matches(AttributeDescription.TypeForwardedToAttribute))\n {\n result |= QuickAttributes.TypeForwardedTo;\n }\n else if (matches(AttributeDescription.AssemblyKeyNameAttribute))\n {\n result |= QuickAttributes.AssemblyKeyName;\n }\n else if (matches(AttributeDescription.AssemblyKeyFileAttribute))\n {\n result |= QuickAttributes.AssemblyKeyFile;\n }\n else if (matches(AttributeDescription.AssemblySignatureKeyAttribute))\n {\n result |= QuickAttributes.AssemblySignatureKey;\n }\n\n return result;\n\n bool matches(AttributeDescription attributeDescription)\n {\n Debug.Assert(attributeDescription.Name.EndsWith(nameof(System.Attribute)));\n\n if (name == attributeDescription.Name)\n {\n return true;\n }\n\n // In an attribute context the name might be referenced as the full name (like 'TypeForwardedToAttribute')\n // or the short name (like 'TypeForwardedTo').\n if (inAttribute &&\n (name.Length + nameof(System.Attribute).Length) == attributeDescription.Name.Length &&\n attributeDescription.Name.StartsWith(name))\n {\n return true;\n }\n\n return false;\n }\n }\n }\n}\n"},"label":{"kind":"number","value":1,"string":"1"}}},{"rowIdx":971,"cells":{"repo_name":{"kind":"string","value":"dotnet/roslyn"},"pr_number":{"kind":"number","value":56402,"string":"56,402"},"pr_title":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily."},"pr_description":{"kind":"string","value":"Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"author":{"kind":"string","value":"CyrusNajmabadi"},"date_created":{"kind":"timestamp","value":"2021-09-15T02:38:04Z","string":"2021-09-15T02:38:04Z"},"date_merged":{"kind":"timestamp","value":"2021-09-24T04:17:33Z","string":"2021-09-24T04:17:33Z"},"previous_commit":{"kind":"string","value":"633346af571d640eeacb2e2fc724f5d25ed20faa"},"pr_commit":{"kind":"string","value":"2b7f137ebbfdf33e9eebffe87d036be392815d2b"},"query":{"kind":"string","value":"Store information about special attributes in the decl table to avoid going back to source unnecessarily.. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1393763\r\n\r\nThe compiler sometimes does excess work in an uncancellable fashion, which can impact some IDE scenarios. Specifically, requesting the Assembly symbol for a Compilation will end up parsing all files that have types with attributes on them to determine if any of them have the `System.Runtime.InteropServices.TypeIdentifierAttribute` on them. This can be very costly (as it may require reparsing large files), esp. as it is uncancellable (since Compilation.Assembly has no way to pass a cancellation token through).\r\n\r\nThis PR mitigates the issue here by adding enough information to the compiler's decl tables to allow it to avoid going back to source when it would be entirely unnecessary. Specifically, it effectively encodes in the decl table \"is it possible for this type to have that attribute on it\". It encodes that by both keeping track of the names referenced directly in the attributes on the types, as well as keeping track of aliases in the file (and global aliases) to know if that type could be brought in by an alias.\r\n\r\nTodo:\r\n- [x] Tests\r\n- [x] VB "},"filepath":{"kind":"string","value":"./src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs"},"before_content":{"kind":"string","value":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n#nullable disable\n\nusing System.Collections.Generic;\nusing System.Collections.Immutable;\nusing System.Diagnostics;\nusing System.Globalization;\nusing System.Linq;\nusing System.Runtime.InteropServices;\nusing System.Threading;\nusing Microsoft.CodeAnalysis.CSharp.Emit;\nusing Microsoft.CodeAnalysis.CSharp.Syntax;\nusing Microsoft.CodeAnalysis.PooledObjects;\nusing Roslyn.Utilities;\n\nnamespace Microsoft.CodeAnalysis.CSharp.Symbols\n{\n // This is a type symbol associated with a type definition in source code.\n // That is, for a generic type C this is the instance type C. \n internal sealed partial class SourceNamedTypeSymbol : SourceMemberContainerTypeSymbol, IAttributeTargetSymbol\n {\n private ImmutableArray _lazyTypeParameters;\n\n /// \n /// A collection of type parameter constraint types, populated when\n /// constraint types for the first type parameter are requested.\n /// \n private ImmutableArray> _lazyTypeParameterConstraintTypes;\n\n /// \n /// A collection of type parameter constraint kinds, populated when\n /// constraint kinds for the first type parameter are requested.\n /// \n private ImmutableArray _lazyTypeParameterConstraintKinds;\n\n private CustomAttributesBag _lazyCustomAttributesBag;\n\n private string _lazyDocComment;\n private string _lazyExpandedDocComment;\n\n private ThreeState _lazyIsExplicitDefinitionOfNoPiaLocalType = ThreeState.Unknown;\n\n protected override Location GetCorrespondingBaseListLocation(NamedTypeSymbol @base)\n {\n Location backupLocation = null;\n\n foreach (SyntaxReference part in SyntaxReferences)\n {\n TypeDeclarationSyntax typeBlock = (TypeDeclarationSyntax)part.GetSyntax();\n BaseListSyntax bases = typeBlock.BaseList;\n if (bases == null)\n {\n continue;\n }\n SeparatedSyntaxList inheritedTypeDecls = bases.Types;\n\n var baseBinder = this.DeclaringCompilation.GetBinder(bases);\n baseBinder = baseBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.SuppressConstraintChecks, this);\n\n if ((object)backupLocation == null)\n {\n backupLocation = inheritedTypeDecls[0].Type.GetLocation();\n }\n\n foreach (BaseTypeSyntax baseTypeSyntax in inheritedTypeDecls)\n {\n TypeSyntax t = baseTypeSyntax.Type;\n TypeSymbol bt = baseBinder.BindType(t, BindingDiagnosticBag.Discarded).Type;\n\n if (TypeSymbol.Equals(bt, @base, TypeCompareKind.ConsiderEverything2))\n {\n return t.GetLocation();\n }\n }\n }\n\n return backupLocation;\n }\n\n internal SourceNamedTypeSymbol(NamespaceOrTypeSymbol containingSymbol, MergedTypeDeclaration declaration, BindingDiagnosticBag diagnostics, TupleExtraData tupleData = null)\n : base(containingSymbol, declaration, diagnostics, tupleData)\n {\n switch (declaration.Kind)\n {\n case DeclarationKind.Struct:\n case DeclarationKind.Interface:\n case DeclarationKind.Enum:\n case DeclarationKind.Delegate:\n case DeclarationKind.Class:\n case DeclarationKind.Record:\n case DeclarationKind.RecordStruct:\n break;\n default:\n Debug.Assert(false, \"bad declaration kind\");\n break;\n }\n\n if (containingSymbol.Kind == SymbolKind.NamedType)\n {\n // Nested types are never unified.\n _lazyIsExplicitDefinitionOfNoPiaLocalType = ThreeState.False;\n }\n }\n\n protected override NamedTypeSymbol WithTupleDataCore(TupleExtraData newData)\n {\n return new SourceNamedTypeSymbol(ContainingType, declaration, BindingDiagnosticBag.Discarded, newData);\n }\n\n #region Syntax\n\n private static SyntaxToken GetName(CSharpSyntaxNode node)\n {\n switch (node.Kind())\n {\n case SyntaxKind.EnumDeclaration:\n return ((EnumDeclarationSyntax)node).Identifier;\n case SyntaxKind.DelegateDeclaration:\n return ((DelegateDeclarationSyntax)node).Identifier;\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n return ((BaseTypeDeclarationSyntax)node).Identifier;\n default:\n return default(SyntaxToken);\n }\n }\n\n public override string GetDocumentationCommentXml(CultureInfo preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default(CancellationToken))\n {\n ref var lazyDocComment = ref expandIncludes ? ref _lazyExpandedDocComment : ref _lazyDocComment;\n return SourceDocumentationCommentUtils.GetAndCacheDocumentationComment(this, expandIncludes, ref lazyDocComment);\n }\n\n #endregion\n\n #region Type Parameters\n\n private ImmutableArray MakeTypeParameters(BindingDiagnosticBag diagnostics)\n {\n if (declaration.Arity == 0)\n {\n return ImmutableArray.Empty;\n }\n\n var typeParameterMismatchReported = false;\n var typeParameterNames = new string[declaration.Arity];\n var typeParameterVarianceKeywords = new string[declaration.Arity];\n var parameterBuilders1 = new List>();\n\n foreach (var syntaxRef in this.SyntaxReferences)\n {\n var typeDecl = (CSharpSyntaxNode)syntaxRef.GetSyntax();\n var syntaxTree = syntaxRef.SyntaxTree;\n\n TypeParameterListSyntax tpl;\n SyntaxKind typeKind = typeDecl.Kind();\n switch (typeKind)\n {\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n tpl = ((TypeDeclarationSyntax)typeDecl).TypeParameterList;\n break;\n\n case SyntaxKind.DelegateDeclaration:\n tpl = ((DelegateDeclarationSyntax)typeDecl).TypeParameterList;\n break;\n\n case SyntaxKind.EnumDeclaration:\n default:\n // there is no such thing as a generic enum, so code should never reach here.\n throw ExceptionUtilities.UnexpectedValue(typeDecl.Kind());\n }\n\n bool isInterfaceOrDelegate = typeKind == SyntaxKind.InterfaceDeclaration || typeKind == SyntaxKind.DelegateDeclaration;\n var parameterBuilder = new List();\n parameterBuilders1.Add(parameterBuilder);\n int i = 0;\n foreach (var tp in tpl.Parameters)\n {\n if (tp.VarianceKeyword.Kind() != SyntaxKind.None &&\n !isInterfaceOrDelegate)\n {\n diagnostics.Add(ErrorCode.ERR_IllegalVarianceSyntax, tp.VarianceKeyword.GetLocation());\n }\n\n var name = typeParameterNames[i];\n var location = new SourceLocation(tp.Identifier);\n var varianceKind = typeParameterVarianceKeywords[i];\n\n ReportTypeNamedRecord(tp.Identifier.Text, this.DeclaringCompilation, diagnostics.DiagnosticBag, location);\n\n if (name == null)\n {\n name = typeParameterNames[i] = tp.Identifier.ValueText;\n varianceKind = typeParameterVarianceKeywords[i] = tp.VarianceKeyword.ValueText;\n for (int j = 0; j < i; j++)\n {\n if (name == typeParameterNames[j])\n {\n typeParameterMismatchReported = true;\n diagnostics.Add(ErrorCode.ERR_DuplicateTypeParameter, location, name);\n goto next;\n }\n }\n\n if (!ReferenceEquals(ContainingType, null))\n {\n var tpEnclosing = ContainingType.FindEnclosingTypeParameter(name);\n if ((object)tpEnclosing != null)\n {\n // Type parameter '{0}' has the same name as the type parameter from outer type '{1}'\n diagnostics.Add(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, location, name, tpEnclosing.ContainingType);\n }\n }\nnext:;\n }\n else if (!typeParameterMismatchReported)\n {\n // Note: the \"this\", below, refers to the name of the current class, which includes its type\n // parameter names. But the type parameter names have not been computed yet. Therefore, we\n // take advantage of the fact that \"this\" won't undergo \"ToString()\" until later, when the\n // diagnostic is printed, by which time the type parameters field will have been filled in.\n if (varianceKind != tp.VarianceKeyword.ValueText)\n {\n // Dev10 reports CS1067, even if names also don't match\n typeParameterMismatchReported = true;\n diagnostics.Add(\n ErrorCode.ERR_PartialWrongTypeParamsVariance,\n declaration.NameLocations.First(),\n this); // see comment above\n }\n else if (name != tp.Identifier.ValueText)\n {\n typeParameterMismatchReported = true;\n diagnostics.Add(\n ErrorCode.ERR_PartialWrongTypeParams,\n declaration.NameLocations.First(),\n this); // see comment above\n }\n }\n parameterBuilder.Add(new TypeParameterBuilder(syntaxTree.GetReference(tp), this, location));\n i++;\n }\n }\n\n var parameterBuilders2 = parameterBuilders1.Transpose(); // type arguments are positional\n var parameters = parameterBuilders2.Select((builders, i) => builders[0].MakeSymbol(i, builders, diagnostics));\n return parameters.AsImmutable();\n }\n\n /// \n /// Returns the constraint types for the given type parameter.\n /// \n internal ImmutableArray GetTypeParameterConstraintTypes(int ordinal)\n {\n var constraintTypes = GetTypeParameterConstraintTypes();\n return (constraintTypes.Length > 0) ? constraintTypes[ordinal] : ImmutableArray.Empty;\n }\n\n private ImmutableArray> GetTypeParameterConstraintTypes()\n {\n var constraintTypes = _lazyTypeParameterConstraintTypes;\n if (constraintTypes.IsDefault)\n {\n GetTypeParameterConstraintKinds();\n\n var diagnostics = BindingDiagnosticBag.GetInstance();\n if (ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeParameterConstraintTypes, MakeTypeParameterConstraintTypes(diagnostics)))\n {\n this.AddDeclarationDiagnostics(diagnostics);\n }\n diagnostics.Free();\n constraintTypes = _lazyTypeParameterConstraintTypes;\n }\n\n return constraintTypes;\n }\n\n /// \n /// Returns the constraint kind for the given type parameter.\n /// \n internal TypeParameterConstraintKind GetTypeParameterConstraintKind(int ordinal)\n {\n var constraintKinds = GetTypeParameterConstraintKinds();\n return (constraintKinds.Length > 0) ? constraintKinds[ordinal] : TypeParameterConstraintKind.None;\n }\n\n private ImmutableArray GetTypeParameterConstraintKinds()\n {\n var constraintKinds = _lazyTypeParameterConstraintKinds;\n if (constraintKinds.IsDefault)\n {\n ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeParameterConstraintKinds, MakeTypeParameterConstraintKinds());\n constraintKinds = _lazyTypeParameterConstraintKinds;\n }\n\n return constraintKinds;\n }\n\n private ImmutableArray> MakeTypeParameterConstraintTypes(BindingDiagnosticBag diagnostics)\n {\n var typeParameters = this.TypeParameters;\n var results = ImmutableArray.Empty;\n\n int arity = typeParameters.Length;\n if (arity > 0)\n {\n bool skipPartialDeclarationsWithoutConstraintClauses = SkipPartialDeclarationsWithoutConstraintClauses();\n ArrayBuilder> otherPartialClauses = null;\n\n foreach (var decl in declaration.Declarations)\n {\n var syntaxRef = decl.SyntaxReference;\n var constraintClauses = GetConstraintClauses((CSharpSyntaxNode)syntaxRef.GetSyntax(), out TypeParameterListSyntax typeParameterList);\n\n if (skipPartialDeclarationsWithoutConstraintClauses && constraintClauses.Count == 0)\n {\n continue;\n }\n\n var binderFactory = this.DeclaringCompilation.GetBinderFactory(syntaxRef.SyntaxTree);\n Binder binder;\n ImmutableArray constraints;\n\n if (constraintClauses.Count == 0)\n {\n binder = binderFactory.GetBinder(typeParameterList.Parameters[0]);\n\n constraints = binder.GetDefaultTypeParameterConstraintClauses(typeParameterList);\n }\n else\n {\n binder = binderFactory.GetBinder(constraintClauses[0]);\n\n // Wrap binder from factory in a generic constraints specific binder \n // to avoid checking constraints when binding type names.\n Debug.Assert(!binder.Flags.Includes(BinderFlags.GenericConstraintsClause));\n binder = binder.WithContainingMemberOrLambda(this).WithAdditionalFlags(BinderFlags.GenericConstraintsClause | BinderFlags.SuppressConstraintChecks);\n\n constraints = binder.BindTypeParameterConstraintClauses(this, typeParameters, typeParameterList, constraintClauses, diagnostics, performOnlyCycleSafeValidation: false);\n }\n\n Debug.Assert(constraints.Length == arity);\n\n if (results.Length == 0)\n {\n results = constraints;\n }\n else\n {\n (otherPartialClauses ??= ArrayBuilder>.GetInstance()).Add(constraints);\n }\n }\n\n results = MergeConstraintTypesForPartialDeclarations(results, otherPartialClauses, diagnostics);\n\n if (results.All(clause => clause.ConstraintTypes.IsEmpty))\n {\n results = ImmutableArray.Empty;\n }\n\n otherPartialClauses?.Free();\n }\n\n return results.SelectAsArray(clause => clause.ConstraintTypes);\n }\n\n private bool SkipPartialDeclarationsWithoutConstraintClauses()\n {\n foreach (var decl in declaration.Declarations)\n {\n if (GetConstraintClauses((CSharpSyntaxNode)decl.SyntaxReference.GetSyntax(), out _).Count != 0)\n {\n return true;\n }\n }\n\n return false;\n }\n\n private ImmutableArray MakeTypeParameterConstraintKinds()\n {\n var typeParameters = this.TypeParameters;\n var results = ImmutableArray.Empty;\n\n int arity = typeParameters.Length;\n if (arity > 0)\n {\n bool skipPartialDeclarationsWithoutConstraintClauses = SkipPartialDeclarationsWithoutConstraintClauses();\n ArrayBuilder> otherPartialClauses = null;\n\n foreach (var decl in declaration.Declarations)\n {\n var syntaxRef = decl.SyntaxReference;\n var constraintClauses = GetConstraintClauses((CSharpSyntaxNode)syntaxRef.GetSyntax(), out TypeParameterListSyntax typeParameterList);\n\n if (skipPartialDeclarationsWithoutConstraintClauses && constraintClauses.Count == 0)\n {\n continue;\n }\n\n var binderFactory = this.DeclaringCompilation.GetBinderFactory(syntaxRef.SyntaxTree);\n Binder binder;\n ImmutableArray constraints;\n\n if (constraintClauses.Count == 0)\n {\n binder = binderFactory.GetBinder(typeParameterList.Parameters[0]);\n constraints = binder.GetDefaultTypeParameterConstraintClauses(typeParameterList);\n }\n else\n {\n binder = binderFactory.GetBinder(constraintClauses[0]);\n\n // Wrap binder from factory in a generic constraints specific binder \n // to avoid checking constraints when binding type names.\n // Also, suppress type argument binding in constraint types, this helps to avoid cycles while we figure out constraint kinds. \n Debug.Assert(!binder.Flags.Includes(BinderFlags.GenericConstraintsClause));\n binder = binder.WithContainingMemberOrLambda(this).WithAdditionalFlags(BinderFlags.GenericConstraintsClause | BinderFlags.SuppressConstraintChecks | BinderFlags.SuppressTypeArgumentBinding);\n\n // We will recompute this diagnostics more accurately later, when binding without BinderFlags.SuppressTypeArgumentBinding \n constraints = binder.BindTypeParameterConstraintClauses(this, typeParameters, typeParameterList, constraintClauses, BindingDiagnosticBag.Discarded, performOnlyCycleSafeValidation: true);\n }\n\n Debug.Assert(constraints.Length == arity);\n\n if (results.Length == 0)\n {\n results = constraints;\n }\n else\n {\n (otherPartialClauses ??= ArrayBuilder>.GetInstance()).Add(constraints);\n }\n }\n\n results = MergeConstraintKindsForPartialDeclarations(results, otherPartialClauses);\n results = ConstraintsHelper.AdjustConstraintKindsBasedOnConstraintTypes(this, typeParameters, results);\n\n if (results.All(clause => clause.Constraints == TypeParameterConstraintKind.None))\n {\n results = ImmutableArray.Empty;\n }\n\n otherPartialClauses?.Free();\n }\n\n return results.SelectAsArray(clause => clause.Constraints);\n }\n\n private static SyntaxList GetConstraintClauses(CSharpSyntaxNode node, out TypeParameterListSyntax typeParameterList)\n {\n switch (node.Kind())\n {\n case SyntaxKind.ClassDeclaration:\n case SyntaxKind.StructDeclaration:\n case SyntaxKind.InterfaceDeclaration:\n case SyntaxKind.RecordDeclaration:\n case SyntaxKind.RecordStructDeclaration:\n var typeDeclaration = (TypeDeclarationSyntax)node;\n typeParameterList = typeDeclaration.TypeParameterList;\n return typeDeclaration.ConstraintClauses;\n case SyntaxKind.DelegateDeclaration:\n var delegateDeclaration = (DelegateDeclarationSyntax)node;\n typeParameterList = delegateDeclaration.TypeParameterList;\n return delegateDeclaration.ConstraintClauses;\n default:\n throw ExceptionUtilities.UnexpectedValue(node.Kind());\n }\n }\n\n /// \n /// Note, only nullability aspects are merged if possible, other mismatches are treated as failures.\n /// \n private ImmutableArray MergeConstraintTypesForPartialDeclarations(ImmutableArray constraintClauses,\n ArrayBuilder> otherPartialClauses,\n BindingDiagnosticBag diagnostics)\n {\n if (otherPartialClauses == null)\n {\n return constraintClauses;\n }\n\n ArrayBuilder builder = null;\n var typeParameters = TypeParameters;\n int arity = typeParameters.Length;\n\n Debug.Assert(constraintClauses.Length == arity);\n\n for (int i = 0; i < arity; i++)\n {\n var constraint = constraintClauses[i];\n\n ImmutableArray originalConstraintTypes = constraint.ConstraintTypes;\n ArrayBuilder mergedConstraintTypes = null;\n SmallDictionary originalConstraintTypesMap = null;\n\n // Constraints defined on multiple partial declarations.\n // Report any mismatched constraints.\n bool report = (GetTypeParameterConstraintKind(i) & TypeParameterConstraintKind.PartialMismatch) != 0;\n foreach (ImmutableArray otherPartialConstraints in otherPartialClauses)\n {\n if (!mergeConstraints(originalConstraintTypes, ref originalConstraintTypesMap, ref mergedConstraintTypes, otherPartialConstraints[i]))\n {\n report = true;\n }\n }\n\n if (report)\n {\n // \"Partial declarations of '{0}' have inconsistent constraints for type parameter '{1}'\"\n diagnostics.Add(ErrorCode.ERR_PartialWrongConstraints, Locations[0], this, typeParameters[i]);\n }\n\n if (mergedConstraintTypes != null)\n {\n#if DEBUG\n Debug.Assert(originalConstraintTypes.Length == mergedConstraintTypes.Count);\n\n for (int j = 0; j < originalConstraintTypes.Length; j++)\n {\n Debug.Assert(originalConstraintTypes[j].Equals(mergedConstraintTypes[j], TypeCompareKind.ObliviousNullableModifierMatchesAny));\n }\n#endif\n if (builder == null)\n {\n builder = ArrayBuilder.GetInstance(constraintClauses.Length);\n builder.AddRange(constraintClauses);\n }\n\n builder[i] = TypeParameterConstraintClause.Create(constraint.Constraints,\n mergedConstraintTypes?.ToImmutableAndFree() ?? originalConstraintTypes);\n }\n }\n\n if (builder != null)\n {\n constraintClauses = builder.ToImmutableAndFree();\n }\n\n return constraintClauses;\n\n static bool mergeConstraints(ImmutableArray originalConstraintTypes,\n ref SmallDictionary originalConstraintTypesMap, ref ArrayBuilder mergedConstraintTypes,\n TypeParameterConstraintClause clause)\n {\n bool result = true;\n\n if (originalConstraintTypes.Length == 0)\n {\n if (clause.ConstraintTypes.Length == 0)\n {\n return result;\n }\n\n return false;\n }\n else if (clause.ConstraintTypes.Length == 0)\n {\n return false;\n }\n\n originalConstraintTypesMap ??= toDictionary(originalConstraintTypes,\n TypeWithAnnotations.EqualsComparer.IgnoreNullableModifiersForReferenceTypesComparer);\n SmallDictionary clauseConstraintTypesMap = toDictionary(clause.ConstraintTypes, originalConstraintTypesMap.Comparer);\n\n foreach (int index1 in originalConstraintTypesMap.Values)\n {\n TypeWithAnnotations constraintType1 = mergedConstraintTypes?[index1] ?? originalConstraintTypes[index1];\n int index2;\n\n if (!clauseConstraintTypesMap.TryGetValue(constraintType1, out index2))\n {\n // No matching type\n result = false;\n continue;\n }\n\n TypeWithAnnotations constraintType2 = clause.ConstraintTypes[index2];\n\n if (!constraintType1.Equals(constraintType2, TypeCompareKind.ObliviousNullableModifierMatchesAny))\n {\n // Nullability mismatch that doesn't involve oblivious\n result = false;\n continue;\n }\n\n if (!constraintType1.Equals(constraintType2, TypeCompareKind.ConsiderEverything))\n {\n // Mismatch with oblivious, merge\n if (mergedConstraintTypes == null)\n {\n mergedConstraintTypes = ArrayBuilder.GetInstance(originalConstraintTypes.Length);\n mergedConstraintTypes.AddRange(originalConstraintTypes);\n }\n\n mergedConstraintTypes[index1] = constraintType1.MergeEquivalentTypes(constraintType2, VarianceKind.None);\n }\n }\n\n foreach (var constraintType in clauseConstraintTypesMap.Keys)\n {\n if (!originalConstraintTypesMap.ContainsKey(constraintType))\n {\n result = false;\n break;\n }\n }\n\n return result;\n }\n\n static SmallDictionary toDictionary(ImmutableArray constraintTypes, IEqualityComparer comparer)\n {\n var result = new SmallDictionary(comparer);\n\n for (int i = constraintTypes.Length - 1; i >= 0; i--)\n {\n result[constraintTypes[i]] = i; // Use the first type among the duplicates as the source of the nullable information\n }\n\n return result;\n }\n }\n\n /// \n /// Note, only nullability aspects are merged if possible, other mismatches are treated as failures.\n /// \n private ImmutableArray MergeConstraintKindsForPartialDeclarations(ImmutableArray constraintClauses,\n ArrayBuilder> otherPartialClauses)\n {\n if (otherPartialClauses == null)\n {\n return constraintClauses;\n }\n\n ArrayBuilder builder = null;\n var typeParameters = TypeParameters;\n int arity = typeParameters.Length;\n\n Debug.Assert(constraintClauses.Length == arity);\n\n for (int i = 0; i < arity; i++)\n {\n var constraint = constraintClauses[i];\n\n TypeParameterConstraintKind mergedKind = constraint.Constraints;\n ImmutableArray originalConstraintTypes = constraint.ConstraintTypes;\n\n foreach (ImmutableArray otherPartialConstraints in otherPartialClauses)\n {\n mergeConstraints(ref mergedKind, originalConstraintTypes, otherPartialConstraints[i]);\n }\n\n if (constraint.Constraints != mergedKind)\n {\n Debug.Assert((constraint.Constraints & (TypeParameterConstraintKind.AllNonNullableKinds | TypeParameterConstraintKind.NotNull)) ==\n (mergedKind & (TypeParameterConstraintKind.AllNonNullableKinds | TypeParameterConstraintKind.NotNull)));\n Debug.Assert((mergedKind & TypeParameterConstraintKind.ObliviousNullabilityIfReferenceType) == 0 ||\n (constraint.Constraints & TypeParameterConstraintKind.ObliviousNullabilityIfReferenceType) != 0);\n Debug.Assert((constraint.Constraints & TypeParameterConstraintKind.AllReferenceTypeKinds) == (mergedKind & TypeParameterConstraintKind.AllReferenceTypeKinds) ||\n (constraint.Constraints & TypeParameterConstraintKind.AllReferenceTypeKinds) == TypeParameterConstraintKind.ReferenceType);\n\n if (builder == null)\n {\n builder = ArrayBuilder.GetInstance(constraintClauses.Length);\n builder.AddRange(constraintClauses);\n }\n\n builder[i] = TypeParameterConstraintClause.Create(mergedKind, originalConstraintTypes);\n }\n }\n\n if (builder != null)\n {\n constraintClauses = builder.ToImmutableAndFree();\n }\n\n return constraintClauses;\n\n static void mergeConstraints(ref TypeParameterConstraintKind mergedKind, ImmutableArray