Skip to content

Commit c556788

Browse files
author
Julien Couvreur
committed
Address feedback
1 parent e5261d8 commit c556788

File tree

9 files changed

+75
-95
lines changed

9 files changed

+75
-95
lines changed

src/Compilers/CSharp/Portable/Compiler/DocumentationCommentCompiler.DocumentationCommentWalker.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private class DocumentationCommentWalker : CSharpSyntaxWalker
3535
private readonly ArrayBuilder<CSharpSyntaxNode> _includeElementNodes;
3636

3737
private HashSet<ParameterSymbol> _documentedParameters;
38-
private HashSet<TypeParameterSymbol> _documentedTypeParameters;
38+
private HashSet<string> _documentedTypeParameterNames;
3939

4040
private DocumentationCommentWalker(
4141
CSharpCompilation compilation,
@@ -44,7 +44,7 @@ private DocumentationCommentWalker(
4444
StringWriter writer,
4545
ArrayBuilder<CSharpSyntaxNode> includeElementNodes,
4646
HashSet<ParameterSymbol> documentedParameters,
47-
HashSet<TypeParameterSymbol> documentedTypeParameters)
47+
HashSet<string> documentedTypeParameterNames)
4848
: base(SyntaxWalkerDepth.StructuredTrivia)
4949
{
5050
_compilation = compilation;
@@ -54,7 +54,7 @@ private DocumentationCommentWalker(
5454
_includeElementNodes = includeElementNodes;
5555

5656
_documentedParameters = documentedParameters;
57-
_documentedTypeParameters = documentedTypeParameters;
57+
_documentedTypeParameterNames = documentedTypeParameterNames;
5858
}
5959

6060
/// <summary>
@@ -71,7 +71,7 @@ public static void GetSubstitutedText(
7171
StringBuilder builder)
7272
{
7373
StringWriter writer = new StringWriter(builder, CultureInfo.InvariantCulture);
74-
DocumentationCommentWalker walker = new DocumentationCommentWalker(compilation, BindingDiagnosticBag.Discarded, symbol, writer, includeElementNodes, documentedParameters: null, documentedTypeParameters: null);
74+
DocumentationCommentWalker walker = new DocumentationCommentWalker(compilation, BindingDiagnosticBag.Discarded, symbol, writer, includeElementNodes, documentedParameters: null, documentedTypeParameterNames: null);
7575

7676
// Before: <param name="NAME">CONTENT</param>
7777
// After: <summary>CONTENT</summary>
@@ -121,17 +121,17 @@ public static string GetSubstitutedText(
121121
DocumentationCommentTriviaSyntax trivia,
122122
ArrayBuilder<CSharpSyntaxNode> includeElementNodes,
123123
ref HashSet<ParameterSymbol> documentedParameters,
124-
ref HashSet<TypeParameterSymbol> documentedTypeParameters)
124+
ref HashSet<string> documentedTypeParameterNames)
125125
{
126126
PooledStringBuilder pooled = PooledStringBuilder.GetInstance();
127127
using (StringWriter writer = new StringWriter(pooled.Builder, CultureInfo.InvariantCulture))
128128
{
129-
DocumentationCommentWalker walker = new DocumentationCommentWalker(compilation, diagnostics, symbol, writer, includeElementNodes, documentedParameters, documentedTypeParameters);
129+
DocumentationCommentWalker walker = new DocumentationCommentWalker(compilation, diagnostics, symbol, writer, includeElementNodes, documentedParameters, documentedTypeParameterNames);
130130
walker.Visit(trivia);
131131

132132
// Copy back out in case they have been initialized.
133133
documentedParameters = walker._documentedParameters;
134-
documentedTypeParameters = walker._documentedTypeParameters;
134+
documentedTypeParameterNames = walker._documentedTypeParameterNames;
135135
}
136136
return pooled.ToStringAndFree();
137137
}
@@ -187,7 +187,7 @@ public override void DefaultVisit(SyntaxNode node)
187187
Binder binder = factory.GetBinder(nameAttr, nameAttr.Identifier.SpanStart);
188188

189189
// Do this for diagnostics, even if we aren't writing.
190-
BindName(nameAttr, binder, _memberSymbol, ref _documentedParameters, ref _documentedTypeParameters, _diagnostics);
190+
BindName(nameAttr, binder, _memberSymbol, ref _documentedParameters, ref _documentedTypeParameterNames, _diagnostics);
191191

192192
// Do descend - we still need to write out the tokens of the attribute.
193193
}

src/Compilers/CSharp/Portable/Compiler/DocumentationCommentCompiler.IncludeElementExpander.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ private class IncludeElementExpander
3636
private int _nextSourceIncludeElementIndex;
3737
private HashSet<Location> _inProgressIncludeElementNodes;
3838
private HashSet<ParameterSymbol> _documentedParameters;
39-
private HashSet<TypeParameterSymbol> _documentedTypeParameters;
39+
private HashSet<string> _documentedTypeParameterNames;
4040
private DocumentationCommentIncludeCache _includedFileCache;
4141

4242
private IncludeElementExpander(
4343
Symbol memberSymbol,
4444
ImmutableArray<CSharpSyntaxNode> sourceIncludeElementNodes,
4545
CSharpCompilation compilation,
4646
HashSet<ParameterSymbol> documentedParameters,
47-
HashSet<TypeParameterSymbol> documentedTypeParameters,
47+
HashSet<string> documentedTypeParameterNames,
4848
DocumentationCommentIncludeCache includedFileCache,
4949
BindingDiagnosticBag diagnostics,
5050
CancellationToken cancellationToken)
@@ -56,7 +56,7 @@ private IncludeElementExpander(
5656
_cancellationToken = cancellationToken;
5757

5858
_documentedParameters = documentedParameters;
59-
_documentedTypeParameters = documentedTypeParameters;
59+
_documentedTypeParameterNames = documentedTypeParameterNames;
6060
_includedFileCache = includedFileCache;
6161

6262
_nextSourceIncludeElementIndex = 0;
@@ -68,7 +68,7 @@ public static void ProcessIncludes(
6868
ImmutableArray<CSharpSyntaxNode> sourceIncludeElementNodes,
6969
CSharpCompilation compilation,
7070
ref HashSet<ParameterSymbol> documentedParameters,
71-
ref HashSet<TypeParameterSymbol> documentedTypeParameters,
71+
ref HashSet<string> documentedTypeParameterNames,
7272
ref DocumentationCommentIncludeCache includedFileCache,
7373
TextWriter writer,
7474
BindingDiagnosticBag diagnostics,
@@ -117,7 +117,7 @@ public static void ProcessIncludes(
117117
sourceIncludeElementNodes,
118118
compilation,
119119
documentedParameters,
120-
documentedTypeParameters,
120+
documentedTypeParameterNames,
121121
includedFileCache,
122122
diagnostics,
123123
cancellationToken);
@@ -135,7 +135,7 @@ public static void ProcessIncludes(
135135
Debug.Assert(expander._nextSourceIncludeElementIndex == expander._sourceIncludeElementNodes.Length);
136136

137137
documentedParameters = expander._documentedParameters;
138-
documentedTypeParameters = expander._documentedTypeParameters;
138+
documentedTypeParameterNames = expander._documentedTypeParameterNames;
139139
includedFileCache = expander._includedFileCache;
140140
}
141141

@@ -537,7 +537,7 @@ private void BindName(XAttribute attribute, CSharpSyntaxNode originatingSyntax,
537537

538538
var nameDiagnostics = BindingDiagnosticBag.GetInstance(_diagnostics);
539539
Binder binder = MakeNameBinder(isParameter, isTypeParameterRef, _memberSymbol, _compilation, originatingSyntax.SyntaxTree);
540-
DocumentationCommentCompiler.BindName(attrSyntax, binder, _memberSymbol, ref _documentedParameters, ref _documentedTypeParameters, nameDiagnostics);
540+
DocumentationCommentCompiler.BindName(attrSyntax, binder, _memberSymbol, ref _documentedParameters, ref _documentedTypeParameterNames, nameDiagnostics);
541541
RecordBindingDiagnostics(nameDiagnostics, sourceLocation); // Respects DocumentationMode.
542542
nameDiagnostics.Free();
543543
}

src/Compilers/CSharp/Portable/Compiler/DocumentationCommentCompiler.cs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ public override void VisitNamedType(NamedTypeSymbol symbol)
226226
// 1. visit the type
227227
if (symbol.IsExtension && (SourceNamedTypeSymbol)symbol.ContainingType is { } containingType)
228228
{
229-
ImmutableArray<SourceNamedTypeSymbol> extensions = containingType.GetExtensionGroupingInfo().GetMatchingExtensions((SourceNamedTypeSymbol)symbol);
229+
// We've been asked to generate the docs for a given extension block. We'll produce the merged docs for the merged blocks.
230+
ImmutableArray<SourceNamedTypeSymbol> extensions = containingType.GetExtensionGroupingInfo().GetMergedExtensions((SourceNamedTypeSymbol)symbol);
230231
appendMergedExtensionBlocks(extensions);
231232
}
232233
else
@@ -264,7 +265,7 @@ void appendContainedExtensions(NamedTypeSymbol containingType)
264265
Debug.Assert(!_isForSingleSymbol);
265266
ExtensionGroupingInfo extensionGroupingInfo = ((SourceMemberContainerTypeSymbol)containingType).GetExtensionGroupingInfo();
266267

267-
foreach (ArrayBuilder<SourceNamedTypeSymbol> extensions in extensionGroupingInfo.EnumerateMergedExtensionBlocks())
268+
foreach (ImmutableArray<SourceNamedTypeSymbol> extensions in extensionGroupingInfo.EnumerateMergedExtensionBlocks())
268269
{
269270
appendMergedExtensionBlocks(extensions);
270271

@@ -309,8 +310,12 @@ bool collectDocCommentNodes(IEnumerable<SourceNamedTypeSymbol> extensions, Array
309310
{
310311
firstExtension = extension;
311312
}
313+
else
314+
{
315+
Debug.Assert(firstExtension.GetEscapedDocumentationCommentId() == extension.GetEscapedDocumentationCommentId());
316+
}
312317

313-
if (!TryGetDocumentationCommentNodes(extension, out var maxDocumentationMode, out var foundDocCommentNodes))
318+
if (!TryGetDocumentationCommentNodes(extension, out DocumentationMode maxDocumentationMode, out ImmutableArray<DocumentationCommentTriviaSyntax> foundDocCommentNodes))
314319
{
315320
// If the XML in any of the doc comments is invalid, skip all further processing (for this symbol) and
316321
// just write a comment saying that info was lost for this symbol.
@@ -530,10 +535,10 @@ private void ProcessDocumentationCommentTriviaNodes(
530535
{
531536
string? withUnprocessedIncludes;
532537
bool haveParseError;
533-
HashSet<TypeParameterSymbol>? documentedTypeParameters;
538+
HashSet<string>? documentedTypeParameterNames;
534539
HashSet<ParameterSymbol>? documentedParameters;
535540
ImmutableArray<CSharpSyntaxNode> includeElementNodes;
536-
if (!tryProcessDocumentationCommentTriviaNodes(symbol, shouldSkipPartialDefinitionComments, docCommentNodes, out withUnprocessedIncludes, out haveParseError, out documentedTypeParameters, out documentedParameters, out includeElementNodes))
541+
if (!tryProcessDocumentationCommentTriviaNodes(symbol, shouldSkipPartialDefinitionComments, docCommentNodes, out withUnprocessedIncludes, out haveParseError, out documentedTypeParameterNames, out documentedParameters, out includeElementNodes))
537542
{
538543
return;
539544
}
@@ -557,7 +562,7 @@ private void ProcessDocumentationCommentTriviaNodes(
557562
// the formatting engine would have trouble determining what prefix to remove from each line.
558563
TextWriter? expanderWriter = shouldSkipPartialDefinitionComments ? null : _writer; // Don't actually write partial method definition parts.
559564
IncludeElementExpander.ProcessIncludes(withUnprocessedIncludes, symbol, includeElementNodes,
560-
_compilation, ref documentedParameters, ref documentedTypeParameters, ref _includedFileCache, expanderWriter, _diagnostics, _cancellationToken);
565+
_compilation, ref documentedParameters, ref documentedTypeParameterNames, ref _includedFileCache, expanderWriter, _diagnostics, _cancellationToken);
561566
}
562567
else if (_writer != null && !shouldSkipPartialDefinitionComments)
563568
{
@@ -588,14 +593,8 @@ private void ProcessDocumentationCommentTriviaNodes(
588593
}
589594
}
590595

591-
if (documentedTypeParameters != null)
596+
if (documentedTypeParameterNames != null)
592597
{
593-
PooledHashSet<string> documentedTypeParameterNames = PooledHashSet<string>.GetInstance();
594-
foreach (var documentedTypeParameter in documentedTypeParameters)
595-
{
596-
documentedTypeParameterNames.Add(documentedTypeParameter.Name);
597-
}
598-
599598
foreach (TypeParameterSymbol typeParameter in GetTypeParameters(symbol))
600599
{
601600
if (!documentedTypeParameterNames.Contains(typeParameter.Name))
@@ -606,8 +605,6 @@ private void ProcessDocumentationCommentTriviaNodes(
606605
_diagnostics.Add(ErrorCode.WRN_MissingTypeParamTag, location, typeParameter, symbol);
607606
}
608607
}
609-
610-
documentedTypeParameterNames.Free();
611608
}
612609
}
613610
return;
@@ -625,7 +622,7 @@ bool tryProcessDocumentationCommentTriviaNodes(
625622
ImmutableArray<DocumentationCommentTriviaSyntax> docCommentNodes,
626623
[NotNullWhen(true)] out string? withUnprocessedIncludes,
627624
out bool haveParseError,
628-
out HashSet<TypeParameterSymbol>? documentedTypeParameters,
625+
out HashSet<string>? documentedTypeParameterNames,
629626
out HashSet<ParameterSymbol>? documentedParameters,
630627
out ImmutableArray<CSharpSyntaxNode> includeElementNodes)
631628
{
@@ -636,7 +633,7 @@ bool tryProcessDocumentationCommentTriviaNodes(
636633
ArrayBuilder<CSharpSyntaxNode>? includeElementNodesBuilder = null;
637634

638635
documentedParameters = null;
639-
documentedTypeParameters = null;
636+
documentedTypeParameterNames = null;
640637

641638
// Saw an XmlException while parsing one of the DocumentationCommentTriviaSyntax nodes.
642639
haveParseError = false;
@@ -678,7 +675,7 @@ bool tryProcessDocumentationCommentTriviaNodes(
678675

679676
// Will respect the DocumentationMode.
680677
string substitutedText = DocumentationCommentWalker.GetSubstitutedText(_compilation, _diagnostics, symbol, trivia,
681-
includeElementNodesBuilder, ref documentedParameters, ref documentedTypeParameters);
678+
includeElementNodesBuilder, ref documentedParameters, ref documentedTypeParameterNames);
682679

683680
string formattedXml = FormatComment(substitutedText);
684681

@@ -1260,7 +1257,7 @@ private static void BindName(
12601257
Binder binder,
12611258
Symbol memberSymbol,
12621259
ref HashSet<ParameterSymbol> documentedParameters,
1263-
ref HashSet<TypeParameterSymbol> documentedTypeParameters,
1260+
ref HashSet<string> documentedTypeParameterNames,
12641261
BindingDiagnosticBag diagnostics)
12651262
{
12661263
XmlNameAttributeElementKind elementKind = syntax.GetElementKind();
@@ -1277,9 +1274,9 @@ private static void BindName(
12771274
}
12781275
else if (elementKind == XmlNameAttributeElementKind.TypeParameter)
12791276
{
1280-
if (documentedTypeParameters == null)
1277+
if (documentedTypeParameterNames == null)
12811278
{
1282-
documentedTypeParameters = new HashSet<TypeParameterSymbol>();
1279+
documentedTypeParameterNames = new HashSet<string>();
12831280
}
12841281
}
12851282

@@ -1335,9 +1332,9 @@ private static void BindName(
13351332
else if (elementKind == XmlNameAttributeElementKind.TypeParameter)
13361333
{
13371334
Debug.Assert(referencedSymbol.Kind == SymbolKind.TypeParameter);
1338-
Debug.Assert(documentedTypeParameters != null);
1335+
Debug.Assert(documentedTypeParameterNames != null);
13391336

1340-
if (!documentedTypeParameters.Add((TypeParameterSymbol)referencedSymbol))
1337+
if (!documentedTypeParameterNames.Add(((TypeParameterSymbol)referencedSymbol).Name))
13411338
{
13421339
diagnostics.Add(ErrorCode.WRN_DuplicateTypeParamTag, syntax.Location, identifier);
13431340
}

src/Compilers/CSharp/Portable/Symbols/ConstructedNamedTypeSymbol.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ protected override NamedTypeSymbol WithTupleDataCore(TupleExtraData newData)
4949
{
5050
throw ExceptionUtilities.Unreachable();
5151
}
52+
53+
internal override string ExtensionGroupingName
54+
=> _underlyingType.ExtensionGroupingName;
55+
56+
internal override string ExtensionMarkerName
57+
=> _underlyingType.ExtensionMarkerName;
5258
}
5359

5460
/// <summary>
@@ -134,5 +140,11 @@ public sealed override bool AreLocalsZeroed
134140
{
135141
get { throw ExceptionUtilities.Unreachable(); }
136142
}
143+
144+
internal override string ExtensionGroupingName
145+
=> _underlyingType.ExtensionGroupingName;
146+
147+
internal override string ExtensionMarkerName
148+
=> _underlyingType.ExtensionMarkerName;
137149
}
138150
}

src/Compilers/CSharp/Portable/Symbols/NativeIntegerTypeSymbol.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui
300300
return false;
301301
}
302302

303+
internal override string ExtensionGroupingName
304+
=> throw ExceptionUtilities.Unreachable();
305+
306+
internal override string ExtensionMarkerName
307+
=> throw ExceptionUtilities.Unreachable();
308+
303309
private sealed class NativeIntegerTypeMap : AbstractTypeMap
304310
{
305311
private readonly NativeIntegerTypeSymbol _type;

src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingNamedTypeSymbol.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,5 +471,11 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui
471471
}
472472

473473
internal override bool HasCompilerLoweringPreserveAttribute => _underlyingType.HasCompilerLoweringPreserveAttribute;
474+
475+
internal override string ExtensionGroupingName
476+
=> _underlyingType.ExtensionGroupingName;
477+
478+
internal override string ExtensionMarkerName
479+
=> _underlyingType.ExtensionMarkerName;
474480
}
475481
}

0 commit comments

Comments
 (0)