Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ToImmutableAndClear #73010

Merged
merged 40 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
72d701e
Switch to ToImmutableAndClear
CyrusNajmabadi Apr 13, 2024
14c321d
Merge remote-tracking branch 'upstream/main' into toImmutableAndClear
CyrusNajmabadi Apr 13, 2024
352ca30
revert
CyrusNajmabadi Apr 13, 2024
2dffdfb
Use collection expressoins
CyrusNajmabadi Apr 13, 2024
ac8070a
Move to better type
CyrusNajmabadi Apr 13, 2024
c42c713
Move to better type
CyrusNajmabadi Apr 13, 2024
f40ad02
Move to better type
CyrusNajmabadi Apr 13, 2024
bbeb8e3
Move to better type
CyrusNajmabadi Apr 13, 2024
d575871
Move to better type
CyrusNajmabadi Apr 13, 2024
4bd15f8
Move to better type
CyrusNajmabadi Apr 13, 2024
a1d8a1e
Move to better type
CyrusNajmabadi Apr 13, 2024
86a73a4
Move to better type
CyrusNajmabadi Apr 13, 2024
f2e6fad
Move to better type
CyrusNajmabadi Apr 13, 2024
89acd32
Move to better type
CyrusNajmabadi Apr 13, 2024
288e932
Move to better type
CyrusNajmabadi Apr 13, 2024
bbcac94
Move to better type
CyrusNajmabadi Apr 13, 2024
df87955
Move to better type
CyrusNajmabadi Apr 13, 2024
bac93e1
Move to better type
CyrusNajmabadi Apr 13, 2024
c3d51d7
Move to better type
CyrusNajmabadi Apr 13, 2024
437f247
Move to better type
CyrusNajmabadi Apr 13, 2024
035fd29
Move to better type
CyrusNajmabadi Apr 13, 2024
5ea3504
Move to better type
CyrusNajmabadi Apr 13, 2024
a360d67
Move to better type
CyrusNajmabadi Apr 13, 2024
3c8bcaa
Move to better type
CyrusNajmabadi Apr 13, 2024
c72a167
Move to better type
CyrusNajmabadi Apr 13, 2024
e9c8ff5
Move to better type
CyrusNajmabadi Apr 13, 2024
3e7c13e
Move to better type
CyrusNajmabadi Apr 13, 2024
43b0ba8
Move to better type
CyrusNajmabadi Apr 13, 2024
e2f7317
Move to better type
CyrusNajmabadi Apr 13, 2024
74e0900
Move to better type
CyrusNajmabadi Apr 13, 2024
d5a4dd2
Move to better type
CyrusNajmabadi Apr 13, 2024
56419f2
Move to better type
CyrusNajmabadi Apr 13, 2024
e28c5bb
Move to better type
CyrusNajmabadi Apr 13, 2024
6241a0c
Move to better type
CyrusNajmabadi Apr 13, 2024
5cf909c
Mix
CyrusNajmabadi Apr 13, 2024
7e73d26
Merge branch 'main' into toImmutableAndClear
CyrusNajmabadi Apr 13, 2024
8c74d24
Remove explicit free
CyrusNajmabadi Apr 13, 2024
baa4bce
Merge branch 'toImmutableAndClear' of https://github.com/CyrusNajmaba…
CyrusNajmabadi Apr 13, 2024
305bb8e
Remove explicit free
CyrusNajmabadi Apr 13, 2024
0789664
Simplify
CyrusNajmabadi Apr 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public static ImmutableArray<CollectionExpressionMatch<StatementSyntax>> TryGetM
return default;
}

return matches.ToImmutable();
return matches.ToImmutableAndClear();
}

public static bool IsCollectionFactoryCreate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private static ImmutableArray<IFieldSymbol> GetEqualizedFields(
value, successRequirement: true, type, fields, out var _2))
{
// we're done, no more statements to check
return fields.ToImmutable();
return fields.ToImmutableAndClear();
}
// check for the first statement as an explicit cast to a variable declaration
// like: var otherC = other as C;
Expand All @@ -557,7 +557,7 @@ private static ImmutableArray<IFieldSymbol> GetEqualizedFields(
return [];
}

return fields.ToImmutable();
return fields.ToImmutableAndClear();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static ImmutableArray<PositionalParameterInfo> GetPropertiesForPositional
_ => throw ExceptionUtilities.Unreachable(),
}).WhereNotNull());

return resultBuilder.ToImmutable();
return resultBuilder.ToImmutableAndClear();
}

public static ImmutableArray<IPropertySymbol> GetInheritedPositionalParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static ImmutableArray<UsingDirectiveSyntax> GetAllUsingDirectives(Compil

Recurse(compilationUnit.Members);

return result.ToImmutable();
return result.ToImmutableAndClear();

void Recurse(SyntaxList<MemberDeclarationSyntax> members)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static ImmutableArray<StatementSyntax> Expand(UsingStatementSyntax using
for (int i = 0, n = result.Count; i < n; i++)
result[i] = result[i].WithAdditionalAnnotations(Formatter.Annotation);

return result.ToImmutable();
return result.ToImmutableAndClear();
}

private static SyntaxTriviaList Expand(ArrayBuilder<StatementSyntax> result, UsingStatementSyntax usingStatement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public void Clear() { }
}
""";

public static readonly IEnumerable<object[]> FailureCreationPatterns = new[]
{
new[] {"var builder = ImmutableArray.CreateBuilder<int>();" },
new[] {"var builder = ArrayBuilder<int>.GetInstance();" },
new[] {"using var _ = ArrayBuilder<int>.GetInstance(out var builder);" },
};

public static readonly IEnumerable<object[]> SuccessCreationPatterns = new[]
{
new[] {"[|var builder = ImmutableArray.[|CreateBuilder|]<int>();|]" },
new[] {"[|var builder = ArrayBuilder<int>.[|GetInstance|]();|]" },
new[] {"[|using var _ = ArrayBuilder<int>.[|GetInstance|](out var builder);|]" },
};
public static readonly IEnumerable<object[]> FailureCreationPatterns =
[
["var builder = ImmutableArray.CreateBuilder<int>();"],
["var builder = ArrayBuilder<int>.GetInstance();"],
["using var _ = ArrayBuilder<int>.GetInstance(out var builder);"],
];

public static readonly IEnumerable<object[]> SuccessCreationPatterns =
[
["[|var builder = ImmutableArray.[|CreateBuilder|]<int>();|]"],
["[|var builder = ArrayBuilder<int>.[|GetInstance|]();|]"],
["[|using var _ = ArrayBuilder<int>.[|GetInstance|](out var builder);|]"],
];

[Theory, MemberData(nameof(FailureCreationPatterns))]
public async Task TestNotInCSharp11(string pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected ImmutableArray<TMatch> AnalyzeWorker(CancellationToken cancellationTok
if (!TryAddMatches(matches, cancellationToken))
return default;

return matches.ToImmutable();
return matches.ToImmutableAndClear();
}

protected UpdateExpressionState<TExpressionSyntax, TStatementSyntax>? TryInitializeState(
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzers/Core/CodeFixes/AddExplicitCast/Fixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected abstract class Fixer<TArgumentSyntax, TArgumentListSyntax, TInvocation
// operations are in order and user can choose least specific types(more accurate)
mutablePotentialConversionTypes.Sort(new InheritanceDistanceComparer<TExpressionSyntax>(semanticModel));

return mutablePotentialConversionTypes.ToImmutable();
return mutablePotentialConversionTypes.ToImmutableAndClear();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static async Task<ImmutableArray<Diagnostic>> GetSolutionDiagnosticsAsync(FixAll
diagnostics.AddRange(projectDiagnostics);
}

return diagnostics.ToImmutable();
return diagnostics.ToImmutableAndClear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private ImmutableArray<TextChange> DetermineTotalEditsToMakeToRawString(
if (quotesToAdd != null)
edits.Add(new TextChange(new TextSpan(StringExpressionBeforePasteInfo.EndDelimiterSpanWithoutSuffix.End, 0), quotesToAdd));

return edits.ToImmutable();
return edits.ToImmutableAndClear();
}

private void UpdateExistingInterpolationBraces(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private ImmutableArray<TextChange> GetEditsForRawString()
if (quotesToAdd != null)
edits.Add(new TextChange(new TextSpan(StringExpressionBeforePasteInfo.EndDelimiterSpanWithoutSuffix.End, 0), quotesToAdd));

return edits.ToImmutable();
return edits.ToImmutableAndClear();
}

/// <inheritdoc cref="AbstractPasteProcessor.GetQuotesToAddToRawString(SourceText, ImmutableArray{TextSpan})" />
Expand Down
2 changes: 1 addition & 1 deletion src/EditorFeatures/Core.Wpf/Peek/PeekableItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<IEnumerable<IPeekableItem>> GetPeekableItemsAsync(
}
}

return results.ToImmutable();
return results.ToImmutableAndClear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private VisibleBlock(double x, ImmutableArray<(double start, double end)> ySegme
if ((currentSegmentBottom - currentSegmentTop) >= MinLineHeight)
segments.Add((currentSegmentTop, currentSegmentBottom));

return segments.ToImmutable();
return segments.ToImmutableAndClear();
}

private static bool IsInHole(ImmutableArray<SnapshotSpan> orderedHoleSpans, ITextViewLine line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal async Task<ImmutableArray<CodeDefinitionWindowLocation>> GetContextFrom
}
}

return builder.ToImmutable();
return builder.ToImmutableAndClear();
}

// We didn't have regular source references, but possibly:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static ImmutableArray<TextSpan> GetSpans(RoslynNavigationBarItem underly
using var _ = ArrayBuilder<TextSpan>.GetInstance(out var spans);
AddSpans(underlyingItem, spans);
spans.SortAndRemoveDuplicates(Comparer<TextSpan>.Default);
return spans.ToImmutable();
return spans.ToImmutableAndClear();

static void AddSpans(RoslynNavigationBarItem underlyingItem, ArrayBuilder<TextSpan> spans)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task<ImmutableArray<IntentSource>> ComputeIntentsAsync(IntentReques
convertedResults.AddIfNotNull(convertedIntent);
}

return convertedResults.ToImmutable();
return convertedResults.ToImmutableAndClear();
}

private static async Task<IntentSource?> ConvertToIntelliCodeResultAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public ImmutableArray<CompletionFilterWithState> GetFilterStatesInSet()
}
}

return builder.ToImmutable();
return builder.ToImmutableAndClear();
}

/// <summary>
Expand All @@ -218,7 +218,7 @@ public static ImmutableArray<CompletionFilterWithState> CombineFilterStates(Immu
}
}

return builder.ToImmutable();
return builder.ToImmutableAndClear();

void AddFilterState(ImmutableArray<CompletionFilterWithState> filterStates)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static ImmutableArray<SnapshotSpan> GetTags(
tags.AddRange(tag.Span.GetSpans(span.Snapshot.TextBuffer));

tags.Sort(static (ss1, ss2) => ss1.Start - ss2.Start);
return tags.ToImmutable();
return tags.ToImmutableAndClear();
}

private static SnapshotSpan GetDestinationTag(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ public ImmutableArray<SyntaxNode> ParseStatements(string statements)
}
}

return list.ToImmutable();
return list.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}

public void Dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private static ImmutableArray<SnippetPlaceholder> GetSnippetPlaceholders(string
}
}

return arrayBuilder.ToImmutable();
return arrayBuilder.ToImmutableAndClear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static ImmutableArray<TextChange> GetMergedChanges(TextChange? newLineEdit, Immu
mergedChanges.Add(new TextChange(newTextChangeSpan, newTextChangeText));
}

return mergedChanges.ToImmutable();
return mergedChanges.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private ImmutableArray<T> TransferLeadingWhitespaceTrivia<T, U>(IEnumerable<T> n
index++;
}

return result.ToImmutable();
return result.ToImmutableAndClear();
}

private async ValueTask<ImmutableArray<SyntaxTrivia>> UpdateParamTagsInLeadingTriviaAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<ImmutableArray<CodeLensMember>> GetCodeLensMembersAsync(Docume

visitor.Visit(root);

return codeLensNodes.ToImmutable();
return codeLensNodes.ToImmutableAndClear();
}

private sealed class CSharpCodeLensVisitor(ArrayBuilder<CodeLensMember> memberBuilder) : CSharpSyntaxWalker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DeclarationNameRecommender()
GetRecommendedNames(names, nameInfo, context, result, namingStyleOptions, cancellationToken);
}

return result.ToImmutable();
return result.ToImmutableAndClear();
}

private ImmutableArray<ImmutableArray<string>> GetBaseNames(SemanticModel semanticModel, NameDeclarationInfo nameInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private static ImmutableArray<StatementSyntax> GenerateProgramMainStatements(
}
}

return statements.ToImmutable();
return statements.ToImmutableAndClear();
}

private static TSyntaxNode FixupComments<TSyntaxNode>(TSyntaxNode node) where TSyntaxNode : SyntaxNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static ImmutableArray<GlobalStatementSyntax> GetGlobalStatements(
foreach (var statement in statements)
globalStatements.Add(GlobalStatement(statement).WithAdditionalAnnotations(Formatter.Annotation));

return globalStatements.ToImmutable();
return globalStatements.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}

private static VariableDeclarationSyntax ConvertDeclaration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ protected override async Task<ImmutableArray<Location>> GetAdditionalReferencesA
}
}

return results.ToImmutable();
return results.ToImmutableAndClear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override ImmutableArray<StatementSyntax> GetInitialStatementsForMethod
}
}

return list.ToImmutable();
return list.ToImmutableAndClear();
}

private static IEnumerable<StatementSyntax> GetStatementsFromContainer(SyntaxNode node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private ImmutableArray<StatementSyntax> MoveDeclarationOutFromMethodDefinition(
result.AddRange(expressionStatements);
}

return result.ToImmutable();
return result.ToImmutableAndClear();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private ImmutableArray<StatementSyntax> MergeDeclarationStatementsWorker(Immutab
if (map.Count > 0)
result.AddRange(GetMergedDeclarationStatements(map));

return result.ToImmutable();
return result.ToImmutableAndClear();
}

private void AppendDeclarationStatementToMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override ImmutableArray<ITypeParameterSymbol> GenerateTypeParameters(C
list.Add(typeParameter);
}

return list.ToImmutable();
return list.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ protected override ImmutableArray<ITypeSymbol> DetermineTypeArguments(Cancellati
}
}

return result.ToImmutable();
return result.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ protected override ImmutableArray<SymbolDisplayPart> GetNormalAnonymousTypeParts
members.AddRange(Space());
members.Add(Punctuation(SyntaxFacts.GetText(SyntaxKind.CloseBraceToken)));

return members.ToImmutable();
return members.ToImmutableAndClear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<ImmutableArray<TextSpan>> GetLineSeparatorsAsync(
}
}

return spans.ToImmutable();
return spans.ToImmutableAndClear();
}

/// <summary>Node types that are interesting for line separation.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static ImmutableArray<RoslynNavigationBarItem> GetMembersInTypes(
}

items.Sort((x1, x2) => x1.Text.CompareTo(x2.Text));
return items.ToImmutable();
return items.ToImmutableAndClear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static ImmutableArray<SyntaxNode> ConvertPropertyToMembers(
cancellationToken));
}

return result.ToImmutable();
return result.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}

private static SyntaxNode GetSetMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected override ImmutableArray<SnippetPlaceholder> GetPlaceHolderLocationsLis
if (!ConstructedFromInlineExpression)
arrayBuilder.Add(new SnippetPlaceholder(node.Expression.ToString(), node.Expression.SpanStart));

return arrayBuilder.ToImmutable();
return arrayBuilder.ToImmutableAndClear();
}

protected override int GetTargetCaretPosition(ForEachStatementSyntax forEachStatement, SourceText sourceText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<ImmutableArray<StringIndentationRegion>> GetStringIndentationR

Recurse(text, root, textSpan, result, cancellationToken);

return result.ToImmutable();
return result.ToImmutableAndClear();
}

private static void Recurse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static async Task<ImmutableArray<CodeAction>> ComputeRefactoringsAsync(
title));
}

return result.ToImmutable();
return result.ToImmutableAndClear();
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
}

private static async Task<Document> UpdateDocumentAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected override ImmutableArray<string> UnsupportedDiagnosticIds
}
}

return builder.ToImmutable();
return builder.ToImmutableAndClear();
}
}
}
Expand Down
Loading
Loading