-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport extensions for new generators
- Loading branch information
1 parent
418a2e8
commit 1f63560
Showing
18 changed files
with
276 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/ComputeSharp.SourceGeneration/Constants/WellKnownTrackingNames.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace ComputeSharp.SourceGeneration.Constants; | ||
|
||
/// <summary> | ||
/// The well known names for tracking steps, to test the incremental generators. | ||
/// </summary> | ||
internal static class WellKnownTrackingNames | ||
{ | ||
/// <summary> | ||
/// The initial <see cref="Microsoft.CodeAnalysis.SyntaxValueProvider.ForAttributeWithMetadataName"/> transform node. | ||
/// </summary> | ||
public const string Execute = nameof(Execute); | ||
|
||
/// <summary> | ||
/// The filtered transform with just output diagnostics. | ||
/// </summary> | ||
public const string Diagnostics = nameof(Diagnostics); | ||
|
||
/// <summary> | ||
/// The filtered transform with just output sources. | ||
/// </summary> | ||
public const string Output = nameof(Output); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/ComputeSharp.SourceGeneration/Extensions/AccessibilityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace ComputeSharp.SourceGeneration.Extensions; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="Accessibility"/> type. | ||
/// </summary> | ||
internal static class AccessibilityExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the expression for a given <see cref="Accessibility"/> value. | ||
/// </summary> | ||
/// <param name="accessibility">The input <see cref="Accessibility"/> value.</param> | ||
/// <returns>The expression for <paramref name="accessibility"/>.</returns> | ||
public static string GetExpression(this Accessibility accessibility) | ||
{ | ||
return accessibility switch | ||
{ | ||
Accessibility.Private => "private", | ||
Accessibility.ProtectedAndInternal => "private protected", | ||
Accessibility.Protected => "protected", | ||
Accessibility.Internal => "internal", | ||
Accessibility.ProtectedOrInternal => "protected internal", | ||
Accessibility.Public => "public", | ||
_ => "" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/ComputeSharp.SourceGeneration/Extensions/IncrementalValuesProviderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using ComputeSharp.SourceGeneration.Helpers; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace ComputeSharp.SourceGeneration.Extensions; | ||
|
||
/// <summary> | ||
/// Extension methods for <see cref="IncrementalValuesProvider{TValues}"/>. | ||
/// </summary> | ||
internal static class IncrementalValuesProviderExtensions | ||
{ | ||
/// <summary> | ||
/// Groups items in a given <see cref="IncrementalValuesProvider{TValue}"/> sequence by a specified key. | ||
/// </summary> | ||
/// <typeparam name="TValues">The type of value that this source provides access to.</typeparam> | ||
/// <typeparam name="TKey">The type of resulting key elements.</typeparam> | ||
/// <typeparam name="TElement">The type of resulting projected elements.</typeparam> | ||
/// <param name="source">The input <see cref="IncrementalValuesProvider{TValues}"/> instance.</param> | ||
/// <param name="keySelector">The key selection <see cref="Func{T, TResult}"/>.</param> | ||
/// <param name="elementSelector">The element selection <see cref="Func{T, TResult}"/>.</param> | ||
/// <returns>An <see cref="IncrementalValuesProvider{TValues}"/> with the grouped results.</returns> | ||
public static IncrementalValuesProvider<(TKey Key, EquatableArray<TElement> Right)> GroupBy<TValues, TKey, TElement>( | ||
this IncrementalValuesProvider<TValues> source, | ||
Func<TValues, TKey> keySelector, | ||
Func<TValues, TElement> elementSelector) | ||
where TValues : IEquatable<TValues> | ||
where TKey : IEquatable<TKey> | ||
where TElement : IEquatable<TElement> | ||
{ | ||
return source.Collect().SelectMany((item, token) => | ||
{ | ||
Dictionary<TKey, ImmutableArray<TElement>.Builder> map = new(); | ||
|
||
foreach (TValues value in item) | ||
{ | ||
TKey key = keySelector(value); | ||
TElement element = elementSelector(value); | ||
|
||
if (!map.TryGetValue(key, out ImmutableArray<TElement>.Builder builder)) | ||
{ | ||
builder = ImmutableArray.CreateBuilder<TElement>(); | ||
|
||
map.Add(key, builder); | ||
} | ||
|
||
builder.Add(element); | ||
} | ||
|
||
token.ThrowIfCancellationRequested(); | ||
|
||
ImmutableArray<(TKey Key, EquatableArray<TElement> Elements)>.Builder result = | ||
ImmutableArray.CreateBuilder<(TKey, EquatableArray<TElement>)>(); | ||
|
||
foreach (KeyValuePair<TKey, ImmutableArray<TElement>.Builder> entry in map) | ||
{ | ||
result.Add((entry.Key, entry.Value.ToImmutable())); | ||
} | ||
|
||
return result; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.