Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6e03dca
Add the initial roslyn files
CyrusNajmabadi Jun 17, 2022
539b248
Merge remote-tracking branch 'upstream/main' into polyfill
CyrusNajmabadi Jun 17, 2022
e8f0a8e
IN progress
CyrusNajmabadi Jun 17, 2022
1c0fbf2
Builds
CyrusNajmabadi Jun 17, 2022
b533f26
Use api
CyrusNajmabadi Jun 17, 2022
c1a76b1
ifdef
CyrusNajmabadi Jun 17, 2022
2ef0717
Merge remote-tracking branch 'upstream/main' into polyfill
CyrusNajmabadi Jun 20, 2022
1f35a7e
Move using outside namespace
CyrusNajmabadi Jun 20, 2022
f5d8137
Move to debug assert
CyrusNajmabadi Jun 20, 2022
be4ef0f
Optimize common cases
CyrusNajmabadi Jun 20, 2022
2babd86
Merge remote-tracking branch 'upstream/main' into polyfill
CyrusNajmabadi Jun 20, 2022
1cdc428
Explain if'defed regions
CyrusNajmabadi Jun 20, 2022
cfce553
Explain if'defed regions
CyrusNajmabadi Jun 20, 2022
fd9a27e
Update System.Text.RegularExpressions.Generator.csproj
CyrusNajmabadi Jun 21, 2022
e2613b6
Port latest changes over
CyrusNajmabadi Jun 22, 2022
a0e9d88
Merge branch 'polyfill' of https://github.com/CyrusNajmabadi/runtime …
CyrusNajmabadi Jun 22, 2022
91672fe
Renames
CyrusNajmabadi Jun 28, 2022
86de769
Merge branch 'main' into polyfill
CyrusNajmabadi Jun 28, 2022
cc933a2
Update src/libraries/Common/src/Roslyn/CSharpSyntaxHelper.cs
CyrusNajmabadi Jun 28, 2022
8a5a8d0
Simplify
CyrusNajmabadi Jun 28, 2022
4eb00d1
Dispose builders
CyrusNajmabadi Jun 28, 2022
59cdea7
Dispose builders
CyrusNajmabadi Jun 28, 2022
e7a1f3e
Simplify by removing support for nested attributes
CyrusNajmabadi Jun 28, 2022
20d62a2
Simplify
CyrusNajmabadi Jun 28, 2022
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
Prev Previous commit
Next Next commit
Port latest changes over
  • Loading branch information
CyrusNajmabadi committed Jun 22, 2022
commit e2613b6c38e4d360b38eeeb2a0fbd0e4a4f47634
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static IncrementalValuesProvider<T> ForAttributeWithMetadataName<T>(
? MetadataTypeName.FromFullName(fullyQualifiedMetadataName.Split(s_nestedTypeNameSeparators).Last())
: MetadataTypeName.FromFullName(fullyQualifiedMetadataName);

var nodesWithAttributesMatchingSimpleName = @this.ForAttributeWithSimpleName(metadataName.UnmangledTypeName, predicate);
var nodesWithAttributesMatchingSimpleName = @this.ForAttributeWithSimpleName(context, metadataName.UnmangledTypeName, predicate);

var collectedNodes = nodesWithAttributesMatchingSimpleName
.Collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ internal static partial class SyntaxValueProviderExtensions
/// </summary>
public static IncrementalValuesProvider<SyntaxNode> ForAttributeWithSimpleName(
this SyntaxValueProvider @this,
IncrementalGeneratorInitializationContext context,
string simpleName,
Func<SyntaxNode, CancellationToken, bool> predicate)
{
var syntaxHelper = CSharpSyntaxHelper.Instance;

// Create a provider over all the syntax trees in the compilation. This is better than CreateSyntaxProvider as
// using SyntaxTrees is purely syntax and will not update the incremental node for a tree when another tree is
// changed. CreateSyntaxProvider will have to rerun all incremental nodes since it passes along the
// SemanticModel, and that model is updated whenever any tree changes (since it is tied to the compilation).
var syntaxTreesProvider = context.CompilationProvider
.SelectMany(static (c, _) => c.SyntaxTrees)
/*.WithTrackingName("compilationUnit_ForAttribute")*/;

// Create a provider that provides (and updates) the global aliases for any particular file when it is edited.
var individualFileGlobalAliasesProvider = @this.CreateSyntaxProvider(
static (n, _) => n is ICompilationUnitSyntax,
static (context, _) => getGlobalAliasesInCompilationUnit(context.Node))/*.WithTrackingName("individualFileGlobalAliases_ForAttribute")*/;
var individualFileGlobalAliasesProvider = syntaxTreesProvider.Select(
(s, c) => getGlobalAliasesInCompilationUnit(s.GetRoot(c)))/*.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
Expand Down Expand Up @@ -79,19 +87,14 @@ public static IncrementalValuesProvider<SyntaxNode> ForAttributeWithSimpleName(

#endif

// Create a syntax provider for every compilation unit.
var compilationUnitProvider = @this.CreateSyntaxProvider(
static (n, _) => n is ICompilationUnitSyntax,
static (context, _) => context.Node)/*.WithTrackingName("compilationUnit_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 compilationUnitAndGlobalAliasesProvider = compilationUnitProvider
var syntaxTreeAndGlobalAliasesProvider = syntaxTreesProvider
.Combine(allUpGlobalAliasesProvider)
/*.WithTrackingName("compilationUnitAndGlobalAliases_ForAttribute")*/;

// For each pair of compilation unit + global aliases, walk the compilation unit
var result = compilationUnitAndGlobalAliasesProvider
var result = syntaxTreeAndGlobalAliasesProvider
.SelectMany((globalAliasesAndCompilationUnit, cancellationToken) => GetMatchingNodes(
syntaxHelper, globalAliasesAndCompilationUnit.Right, globalAliasesAndCompilationUnit.Left, simpleName, predicate, cancellationToken))
/*.WithTrackingName("result_ForAttribute")*/;
Expand All @@ -113,11 +116,12 @@ static GlobalAliases getGlobalAliasesInCompilationUnit(
private static ImmutableArray<SyntaxNode> GetMatchingNodes(
ISyntaxHelper syntaxHelper,
GlobalAliases globalAliases,
SyntaxNode compilationUnit,
SyntaxTree syntaxTree,
string name,
Func<SyntaxNode, CancellationToken, bool> predicate,
CancellationToken cancellationToken)
{
var compilationUnit = syntaxTree.GetRoot(cancellationToken);
Debug.Assert(compilationUnit is ICompilationUnitSyntax);

var isCaseSensitive = syntaxHelper.IsCaseSensitive;
Expand Down