Skip to content

Commit fe2877e

Browse files
authored
Merge pull request #119 from Cysharp/incremental-incremental
True Incremental Generator
2 parents b188553 + addfba1 commit fe2877e

27 files changed

+1532
-200
lines changed

ConsoleAppFramework.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppFramework.Generat
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeAot", "sandbox\NativeAot\NativeAot.csproj", "{EC1A3299-6597-4AD2-92DE-EDF309875A97}"
3030
EndProject
31-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppFramework.Abstractions", "src\ConsoleAppFramework.Abstractions\ConsoleAppFramework.Abstractions.csproj", "{855B0D28-DC69-470B-B3D9-481EE52737AA}"
31+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppFramework.Abstractions", "src\ConsoleAppFramework.Abstractions\ConsoleAppFramework.Abstractions.csproj", "{855B0D28-DC69-470B-B3D9-481EE52737AA}"
3232
EndProject
33-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilterShareProject", "sandbox\FilterShareProject\FilterShareProject.csproj", "{2A1E8ED1-CEB9-47CB-8497-A0C4F5A8F025}"
33+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilterShareProject", "sandbox\FilterShareProject\FilterShareProject.csproj", "{2A1E8ED1-CEB9-47CB-8497-A0C4F5A8F025}"
3434
EndProject
3535
Global
3636
GlobalSection(SolutionConfigurationPlatforms) = preSolution

sandbox/CliFrameworkBenchmark/CliFrameworkBenchmark.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<nullable>annotations</nullable>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<IsPackable>false</IsPackable>
10+
<Configurations>Debug;Release</Configurations>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

sandbox/FilterShareProject/FilterShareProject.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsPackable>false</IsPackable>
77
<Nullable>enable</Nullable>
8+
<Configurations>Debug;Release</Configurations>
89
</PropertyGroup>
910

1011
<ItemGroup>

sandbox/GeneratorSandbox/GeneratorSandbox.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<IsPackable>false</IsPackable>
1111

1212
<DefineConstants>USE_EXTERNAL_CONSOLEAPP_ABSTRACTIONS</DefineConstants>
13+
14+
<Configurations>Debug;Release</Configurations>
1315
</PropertyGroup>
1416

1517
<ItemGroup>
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
using System.ComponentModel.DataAnnotations;
2-
using System.Diagnostics.CodeAnalysis;
3-
using ConsoleAppFramework;
1+
using ConsoleAppFramework;
42

3+
var app = ConsoleApp.Create();
4+
5+
app.Add("aaa", () =>
6+
{
7+
});
58

69

7-
args = ["show", "--aaa", "a", "value", "10.2"];
810

9-
var app = ConsoleApp.Create();
10-
app.Add<Test>();
11-
app.Run(args);
1211

13-
public class Test
12+
app.Add("aabcdefg", int (int x, string y) =>
1413
{
15-
public void Show(string aaa, [Range(0, 1)] double value) => ConsoleApp.Log($"{value}");
16-
}
14+
return default!;
15+
});
1716

17+
app.Run(args);

sandbox/NativeAot/NativeAot.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<PublishAot>true</PublishAot>
1111
<IsAotCompatible>true</IsAotCompatible>
12+
<Configurations>Debug;Release</Configurations>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

sandbox/NativeAot/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
using ConsoleAppFramework;
22

3-
ConsoleApp.Run(args, (int x, int y) => Console.WriteLine(x + y));
3+
4+
var app = ConsoleApp.Create();
5+
6+
//ConsoleApp.Run(args, (int x, int y) => Console.WriteLine(x + y));
7+
8+
app.Run(args);

src/ConsoleAppFramework.Abstractions/ConsoleAppFramework.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<!-- NuGet -->
99
<PackageId>ConsoleAppFramework.Abstractions</PackageId>
1010
<Description>ConsoleAppFramework external abstractions library.</Description>
11+
<Configurations>Debug;Release</Configurations>
1112
</PropertyGroup>
1213

1314
<ItemGroup>

src/ConsoleAppFramework/Command.cs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using Microsoft.CodeAnalysis;
2-
using System;
3-
using System.Data.Common;
4-
using System.Diagnostics.CodeAnalysis;
5-
using System.Reflection;
6-
using System.Reflection.Metadata;
72
using System.Text;
83

94
namespace ConsoleAppFramework;
@@ -24,16 +19,16 @@ public record class Command
2419
{
2520
public required bool IsAsync { get; init; } // Task or Task<int>
2621
public required bool IsVoid { get; init; } // void or int
27-
22+
2823
public bool IsRootCommand => Name == "";
2924
public required string Name { get; init; }
3025

31-
public required CommandParameter[] Parameters { get; init; }
26+
public required EquatableArray<CommandParameter> Parameters { get; init; }
3227
public required string Description { get; init; }
3328
public required MethodKind MethodKind { get; init; }
3429
public required DelegateBuildType DelegateBuildType { get; init; }
3530
public CommandMethodInfo? CommandMethodInfo { get; set; } // can set...!
36-
public required FilterInfo[] Filters { get; init; }
31+
public required EquatableArray<FilterInfo> Filters { get; init; }
3732
public bool HasFilter => Filters.Length != 0;
3833

3934
public string? BuildDelegateSignature(out string? delegateType)
@@ -148,15 +143,16 @@ public string BuildDelegateType(string delegateName)
148143

149144
public record class CommandParameter
150145
{
151-
public required ITypeSymbol Type { get; init; }
152-
public required Location Location { get; init; }
146+
public required EquatableTypeSymbol Type { get; init; }
147+
public required IgnoreEquality<Location> Location { get; init; }
148+
public required IgnoreEquality<WellKnownTypes> WellKnownTypes { get; init; }
153149
public required bool IsNullableReference { get; init; }
154150
public required bool IsParams { get; init; }
155151
public required string Name { get; init; }
156152
public required string OriginalParameterName { get; init; }
157153
public required bool HasDefaultValue { get; init; }
158154
public object? DefaultValue { get; init; }
159-
public required ITypeSymbol? CustomParserType { get; init; }
155+
public required EquatableTypeSymbol? CustomParserType { get; init; }
160156
public required bool IsFromServices { get; init; }
161157
public required bool IsConsoleAppContext { get; init; }
162158
public required bool IsCancellationToken { get; init; }
@@ -165,15 +161,15 @@ public record class CommandParameter
165161
public required bool HasValidation { get; init; }
166162
public required int ArgumentIndex { get; init; } // -1 is not Argument, other than marked as [Argument]
167163
public bool IsArgument => ArgumentIndex != -1;
168-
public required string[] Aliases { get; init; }
164+
public required EquatableArray<string> Aliases { get; init; }
169165
public required string Description { get; init; }
170166
public bool RequireCheckArgumentParsed => !(HasDefaultValue || IsParams || IsFlag);
171167

172168
// increment = false when passed from [Argument]
173-
public string BuildParseMethod(int argCount, string argumentName, WellKnownTypes wellKnownTypes, bool increment)
169+
public string BuildParseMethod(int argCount, string argumentName, bool increment)
174170
{
175171
var incrementIndex = increment ? "!TryIncrementIndex(ref i, args.Length) || " : "";
176-
return Core(Type, false);
172+
return Core(Type.TypeSymbol, false);
177173

178174
string Core(ITypeSymbol type, bool nullable)
179175
{
@@ -207,7 +203,7 @@ string Core(ITypeSymbol type, bool nullable)
207203
{
208204
return $"arg{argCount} = args[i];";
209205
}
210-
206+
211207
case SpecialType.System_Boolean:
212208
return $"arg{argCount} = true;"; // bool is true flag
213209
case SpecialType.System_Char:
@@ -242,7 +238,7 @@ string Core(ITypeSymbol type, bool nullable)
242238
if (type.TypeKind == TypeKind.Array)
243239
{
244240
var elementType = (type as IArrayTypeSymbol)!.ElementType;
245-
var parsable = wellKnownTypes.ISpanParsable;
241+
var parsable = WellKnownTypes.Value.ISpanParsable;
246242
if (parsable != null) // has parsable
247243
{
248244
if (elementType.AllInterfaces.Any(x => x.EqualsUnconstructedGenericType(parsable)))
@@ -254,12 +250,12 @@ string Core(ITypeSymbol type, bool nullable)
254250
}
255251

256252
// System.DateTimeOffset, System.Guid, System.Version
257-
tryParseKnownPrimitive = wellKnownTypes.HasTryParse(type);
253+
tryParseKnownPrimitive = WellKnownTypes.Value.HasTryParse(type);
258254

259255
if (!tryParseKnownPrimitive)
260256
{
261257
// ISpanParsable<T> (BigInteger, Complex, Half, Int128, etc...)
262-
var parsable = wellKnownTypes.ISpanParsable;
258+
var parsable = WellKnownTypes.Value.ISpanParsable;
263259
if (parsable != null) // has parsable
264260
{
265261
tryParseIParsable = type.AllInterfaces.Any(x => x.EqualsUnconstructedGenericType(parsable));
@@ -316,13 +312,6 @@ public string DefaultValueToString(bool castValue = true, bool enumIncludeTypeNa
316312
return $"({Type.ToFullyQualifiedFormatDisplayString()}){DefaultValue}";
317313
}
318314

319-
public string? GetEnumSymbolName(object value)
320-
{
321-
var symbol = Type.GetMembers().OfType<IFieldSymbol>().FirstOrDefault(x => x.ConstantValue == value);
322-
if (symbol == null) return "";
323-
return symbol.Name;
324-
}
325-
326315
public string ToTypeDisplayString()
327316
{
328317
var t = Type.ToFullyQualifiedFormatDisplayString();
@@ -359,7 +348,7 @@ public record class CommandMethodInfo
359348
{
360349
public required string TypeFullName { get; init; }
361350
public required string MethodName { get; init; }
362-
public required ITypeSymbol[] ConstructorParameterTypes { get; init; }
351+
public required EquatableArray<EquatableTypeSymbol> ConstructorParameterTypes { get; init; }
363352
public required bool IsIDisposable { get; init; }
364353
public required bool IsIAsyncDisposable { get; init; }
365354

@@ -378,7 +367,7 @@ public string BuildNew()
378367
public record class FilterInfo
379368
{
380369
public required string TypeFullName { get; init; }
381-
public required ITypeSymbol[] ConstructorParameterTypes { get; init; }
370+
public required EquatableArray<EquatableTypeSymbol> ConstructorParameterTypes { get; init; }
382371

383372
FilterInfo()
384373
{
@@ -400,7 +389,7 @@ public record class FilterInfo
400389
var filter = new FilterInfo
401390
{
402391
TypeFullName = type.ToFullyQualifiedFormatDisplayString(),
403-
ConstructorParameterTypes = publicConstructors[0].Parameters.Select(x => x.Type).ToArray()
392+
ConstructorParameterTypes = publicConstructors[0].Parameters.Select(x => new EquatableTypeSymbol(x.Type)).ToArray()
404393
};
405394

406395
return filter;

src/ConsoleAppFramework/ConsoleAppFramework.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
1515
<IncludeSymbols>false</IncludeSymbols>
1616
<DevelopmentDependency>true</DevelopmentDependency>
17+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
1718

1819
<!-- NuGet -->
1920
<PackageId>ConsoleAppFramework</PackageId>
2021
<Description>Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.</Description>
22+
<Configurations>Debug;Release</Configurations>
2123
</PropertyGroup>
22-
24+
2325
<ItemGroup>
24-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
26+
<!-- Roslyn for .NET 8 / C# 12 -->
27+
<!-- https://learn.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support -->
28+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
2529
<PackageReference Include="PolySharp" Version="1.14.1">
2630
<PrivateAssets>all</PrivateAssets>
2731
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)