-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 incremental generator for LinqGen
- Loading branch information
Showing
9 changed files
with
368 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// LinqGen.Generator, Maxwell Keonwoo Kang <[email protected]>, 2022 | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
namespace Cathei.LinqGen.Generator; | ||
|
@@ -96,7 +97,7 @@ symbol.TypeArguments[1] is not INamedTypeSymbol resultSignatureSymbol || | |
} | ||
|
||
public static bool TryParseStubMethod(IMethodSymbol methodSymbol, | ||
out ITypeSymbol inputElementSymbol, out INamedTypeSymbol[] signatureSymbols) | ||
out ITypeSymbol inputElementSymbol, out IEnumerable<INamedTypeSymbol> signatureSymbols) | ||
{ | ||
if (methodSymbol.ReceiverType is not INamedTypeSymbol receiverTypeSymbol || | ||
!TryParseStubInterface(receiverTypeSymbol, out inputElementSymbol, out var receiverSignatureSymbol)) | ||
|
@@ -124,7 +125,7 @@ public static bool TryParseStubMethod(IMethodSymbol methodSymbol, | |
signatureSymbolsList.Add(paramSignatureSymbol); | ||
} | ||
|
||
signatureSymbols = signatureSymbolsList.ToArray(); | ||
signatureSymbols = signatureSymbolsList; | ||
return true; | ||
} | ||
|
||
|
@@ -782,4 +783,9 @@ public static BlockSyntax AddStatements(this BlockSyntax block, SyntaxList<State | |
{ | ||
return block.WithStatements(block.Statements.AddRange(statements)); | ||
} | ||
|
||
public static int HashCombine(int a, int b) | ||
{ | ||
return unchecked((a * 397) ^ b); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
// LinqGen.Generator, Maxwell Keonwoo Kang <[email protected]>, 2022 | ||
|
||
using System; | ||
|
||
namespace Cathei.LinqGen.Generator; | ||
|
||
public readonly struct EvaluationKey : IEqualityComparer<EvaluationKey> | ||
public readonly struct EvaluationKey : IEquatable<EvaluationKey> | ||
{ | ||
private static readonly SymbolEqualityComparer SymbolComparer = SymbolEqualityComparer.Default; | ||
|
||
|
@@ -18,17 +20,18 @@ public EvaluationKey( | |
InputElementSymbol = inputElementSymbol; | ||
} | ||
|
||
public bool Equals(EvaluationKey x, EvaluationKey y) | ||
public bool Equals(EvaluationKey other) | ||
{ | ||
return SymbolComparer.Equals(x.SignatureSymbol, y.SignatureSymbol) && | ||
SymbolComparer.Equals(x.MethodSymbol, y.MethodSymbol) && | ||
SymbolComparer.Equals(x.InputElementSymbol, y.InputElementSymbol); | ||
return SymbolComparer.Equals(SignatureSymbol, other.SignatureSymbol) && | ||
SymbolComparer.Equals(MethodSymbol, other.MethodSymbol) && | ||
SymbolComparer.Equals(InputElementSymbol, other.InputElementSymbol); | ||
} | ||
|
||
public int GetHashCode(EvaluationKey obj) | ||
public override int GetHashCode() | ||
{ | ||
return SymbolComparer.GetHashCode(obj.SignatureSymbol) ^ | ||
SymbolComparer.GetHashCode(obj.MethodSymbol) ^ | ||
SymbolComparer.GetHashCode(obj.InputElementSymbol); | ||
int hashCode = SymbolComparer.GetHashCode(SignatureSymbol); | ||
hashCode = HashCombine(hashCode, SymbolComparer.GetHashCode(MethodSymbol)); | ||
hashCode = HashCombine(hashCode, SymbolComparer.GetHashCode(InputElementSymbol)); | ||
return hashCode; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// LinqGen.Generator, Maxwell Keonwoo Kang <[email protected]>, 2022 | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
namespace Cathei.LinqGen.Generator; | ||
|
@@ -13,10 +14,10 @@ namespace Cathei.LinqGen.Generator; | |
/// </summary> | ||
public abstract class Instruction | ||
{ | ||
public INamedTypeSymbol[]? UpstreamSignatureSymbols { get; } | ||
public ImmutableArray<INamedTypeSymbol> UpstreamSignatureSymbols { get; } | ||
public string Id { get; } | ||
|
||
protected Instruction(in LinqGenExpression expression, int id) | ||
protected Instruction(in LinqGenExpression expression, uint id) | ||
{ | ||
UpstreamSignatureSymbols = expression.UpstreamSignatureSymbols; | ||
Id = Base62.Encode(id); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// LinqGen.Generator, Maxwell Keonwoo Kang <[email protected]>, 2022 | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
|
||
namespace Cathei.LinqGen.Generator; | ||
|
@@ -10,10 +11,10 @@ public readonly struct LinqGenExpression | |
public IMethodSymbol MethodSymbol { get; } | ||
public INamedTypeSymbol? SignatureSymbol { get; } | ||
public ITypeSymbol? InputElementSymbol { get; } | ||
public INamedTypeSymbol[]? UpstreamSignatureSymbols { get; } | ||
public ImmutableArray<INamedTypeSymbol> UpstreamSignatureSymbols { get; } | ||
|
||
private LinqGenExpression(IMethodSymbol methodSymbol, INamedTypeSymbol? signatureSymbol, | ||
ITypeSymbol? inputElementSymbol, INamedTypeSymbol[]? upstreamSignatureSymbols) | ||
ITypeSymbol? inputElementSymbol, ImmutableArray<INamedTypeSymbol> upstreamSignatureSymbols) | ||
{ | ||
MethodSymbol = methodSymbol; | ||
SignatureSymbol = signatureSymbol; | ||
|
@@ -57,7 +58,7 @@ public static bool TryParse(SemanticModel semanticModel, | |
} | ||
|
||
ITypeSymbol? inputElementSymbol = null; | ||
INamedTypeSymbol[]? upstreamSignatureSymbols = null; | ||
IEnumerable<INamedTypeSymbol>? upstreamSignatureSymbols = null; | ||
|
||
// this means it takes LinqGen enumerable as input, and upstream type is required | ||
if (methodSymbol.ReceiverType is INamedTypeSymbol receiverTypeSymbol && | ||
|
@@ -80,10 +81,11 @@ public static bool TryParse(SemanticModel semanticModel, | |
signatureSymbol = NormalizeSignature(signatureSymbol); | ||
|
||
if (upstreamSignatureSymbols != null) | ||
upstreamSignatureSymbols = upstreamSignatureSymbols.Select(NormalizeSignature).ToArray(); | ||
upstreamSignatureSymbols = upstreamSignatureSymbols.Select(NormalizeSignature); | ||
|
||
result = new LinqGenExpression( | ||
methodSymbol, signatureSymbol, inputElementSymbol, upstreamSignatureSymbols); | ||
methodSymbol, signatureSymbol, inputElementSymbol, | ||
upstreamSignatureSymbols?.ToImmutableArray() ?? ImmutableArray<INamedTypeSymbol>.Empty); | ||
|
||
return true; | ||
} | ||
|
@@ -129,7 +131,7 @@ public static bool TryParse(SemanticModel semanticModel, | |
} | ||
|
||
result = new LinqGenExpression( | ||
methodSymbol, null, inputElementSymbol, new[] { NormalizeSignature(upstreamSignatureSymbol) }); | ||
methodSymbol, null, inputElementSymbol, ImmutableArray.Create(upstreamSignatureSymbol)); | ||
|
||
return true; | ||
} | ||
|
Oops, something went wrong.