Skip to content

Commit

Permalink
Merge pull request #72979 from CyrusNajmabadi/cleanupCollect
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Apr 12, 2024
2 parents 6337bb3 + d584ef9 commit 9f22861
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ public partial struct SyntaxValueProvider

// Create a provider that provides (and updates) the global aliases for any particular file when it is edited.
var individualFileGlobalAliasesProvider = syntaxTreesProvider
.Where((info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsGlobalAliases))
.Where(static (info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsGlobalAliases))
.Select((info, cancellationToken) => getGlobalAliasesInCompilationUnit(syntaxHelper, info.Tree.GetRoot(cancellationToken)))
.WithTrackingName("individualFileGlobalAliases_ForAttribute");

// Create an aggregated view of all global aliases across all files. This should only update when an individual
// file changes its global aliases or a file is added / removed from the compilation
var collectedGlobalAliasesProvider = individualFileGlobalAliasesProvider
.Collect()
.WithComparer(ImmutableArrayValueComparer<GlobalAliases>.Instance)
.WithTrackingName("collectedGlobalAliases_ForAttribute");

var allUpGlobalAliasesProvider = collectedGlobalAliasesProvider
Expand All @@ -95,19 +94,19 @@ public partial struct SyntaxValueProvider

allUpGlobalAliasesProvider = allUpGlobalAliasesProvider
.Combine(compilationGlobalAliases)
.Select((tuple, _) => GlobalAliases.Concat(tuple.Left, tuple.Right))
.Select(static (tuple, _) => GlobalAliases.Concat(tuple.Left, tuple.Right))
.WithTrackingName("allUpIncludingCompilationGlobalAliases_ForAttribute");

// Combine the two providers so that we reanalyze every file if the global aliases change, or we reanalyze a
// particular file when it's compilation unit changes.
var syntaxTreeAndGlobalAliasesProvider = syntaxTreesProvider
.Where((info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsAttributeList))
.Where(static (info, _) => info.Info.HasFlag(SourceGeneratorSyntaxTreeInfo.ContainsAttributeList))
.Combine(allUpGlobalAliasesProvider)
.WithTrackingName("compilationUnitAndGlobalAliases_ForAttribute");

return syntaxTreeAndGlobalAliasesProvider
.Select((tuple, c) => (tuple.Left.Tree, GetMatchingNodes(syntaxHelper, tuple.Right, tuple.Left.Tree, simpleName, predicate, c)))
.Where(tuple => tuple.Item2.Length > 0)
.Where(static tuple => tuple.Item2.Length > 0)
.WithTrackingName("result_ForAttributeInternal");

static GlobalAliases getGlobalAliasesInCompilationUnit(
Expand Down

0 comments on commit 9f22861

Please sign in to comment.