Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding source generator #21725

Merged
merged 47 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7b61154
Add new public API SetBinding<TSource, TProperty>
simonrozsival Mar 4, 2024
632979b
Add source generator skeleton
simonrozsival Mar 5, 2024
403f476
Setup unit tests for binding intermediate representation
jkurdek Mar 26, 2024
f9747a3
Added basic nullability support
jkurdek Mar 29, 2024
a4b9335
Remove unnecessary Id from the binding record
simonrozsival Apr 2, 2024
62f613e
Generate casts
simonrozsival Apr 2, 2024
e5343a5
Split index and member access
simonrozsival Apr 3, 2024
5d719ca
Cleanup
simonrozsival Apr 3, 2024
dd8112f
Update test case
simonrozsival Apr 3, 2024
6b325ae
Cleanup
simonrozsival Apr 4, 2024
e9093af
Fix the semantic of conditional access
simonrozsival Apr 5, 2024
5298785
add as-cast suport to source generator
jkurdek Apr 4, 2024
d1fed61
improve nullability check
jkurdek Apr 4, 2024
c8130cf
specify params in tests only when not default
jkurdek Apr 4, 2024
c0b7da6
simplify diagnostics
jkurdek Apr 4, 2024
7e82570
move path parser to separate class
jkurdek Apr 4, 2024
7f3f2bb
small cleanup
jkurdek Apr 4, 2024
491a91e
Get nullability right in binding representation tests
jkurdek Apr 5, 2024
1bf4cad
Fix path parse to work with improved tests
jkurdek Apr 5, 2024
0355390
Integration tests (#14)
jkurdek Apr 8, 2024
d00f0d8
Implement setters (#16)
simonrozsival Apr 9, 2024
b4bf3e0
Simplify indexes (#18)
simonrozsival Apr 9, 2024
97721da
Fix overload check (#20)
jkurdek Apr 9, 2024
8617d5b
Implement detection of writable properties (#19)
simonrozsival Apr 9, 2024
1f733e2
Add TODOs to change arrays to equatable arrays
simonrozsival Apr 9, 2024
b375a60
Add projects to solutions
simonrozsival Apr 9, 2024
85d0a40
Try to run unit tests in CI
simonrozsival Apr 10, 2024
8708c17
Added custom indexer support
jkurdek Apr 11, 2024
78502ca
Fix typo
simonrozsival Apr 16, 2024
d2befa0
Avoid allocating line separators array
simonrozsival Apr 16, 2024
2039bb0
Hide the new SetBinding overload from editor suggestions for now
simonrozsival Apr 17, 2024
08f55d6
Incremental generation tests
jkurdek Apr 16, 2024
89dfa15
replaced array with equatable array
jkurdek Apr 19, 2024
df57581
Added source information + formatting
jkurdek Apr 19, 2024
6d6887e
added third party licenses
jkurdek Apr 19, 2024
4cb21c1
Add benchmark for source-generated SetBinding (#25)
simonrozsival Apr 23, 2024
19b6885
Improve diagnostic messages
simonrozsival Apr 23, 2024
f02cce5
Improved incrementality testing (#28)
jkurdek Apr 29, 2024
2f35e7e
Add C-Style casts support (#26)
jkurdek Apr 30, 2024
2cb89e8
Cleanup (#29)
simonrozsival Apr 30, 2024
0835449
Improved nullable support (#30)
jkurdek May 14, 2024
55e1aa2
Simplify building setter
simonrozsival May 14, 2024
44c0167
cleaned up methods in BindingSourceGeneratorUtilities
jkurdek May 17, 2024
296c5e0
replaced tuples with Result<T>
jkurdek May 17, 2024
1054597
simplified naming
jkurdek May 17, 2024
1f88a39
Fix and improve unit test project
simonrozsival Jun 4, 2024
afabedc
Fix bad conflict resolution in solution file
simonrozsival Jun 4, 2024
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
16 changes: 15 additions & 1 deletion Microsoft.Maui-dev.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -255,6 +255,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.Mac.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.WinUI.Tests", "src\Controls\tests\TestCases.WinUI.Tests\Controls.TestCases.WinUI.Tests.csproj", "{A3E22F99-F380-4005-8483-3ACA6C104220}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen", "src\Controls\src\BindingSourceGen\Controls.BindingSourceGen.csproj", "{9538341F-8A00-4356-A2B2-5C2959979F22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen.UnitTests", "src\Controls\tests\BindingSourceGen.UnitTests\Controls.BindingSourceGen.UnitTests.csproj", "{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -648,6 +652,14 @@ Global
{A3E22F99-F380-4005-8483-3ACA6C104220}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3E22F99-F380-4005-8483-3ACA6C104220}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3E22F99-F380-4005-8483-3ACA6C104220}.Release|Any CPU.Build.0 = Release|Any CPU
{9538341F-8A00-4356-A2B2-5C2959979F22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9538341F-8A00-4356-A2B2-5C2959979F22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9538341F-8A00-4356-A2B2-5C2959979F22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9538341F-8A00-4356-A2B2-5C2959979F22}.Release|Any CPU.Build.0 = Release|Any CPU
{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -766,6 +778,8 @@ Global
{5DDA6439-CDE0-4BFE-8BF9-77962BC69ACA} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{6E1ADE49-680E-4CA3-8FEA-6450802F8250} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{A3E22F99-F380-4005-8483-3ACA6C104220} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{9538341F-8A00-4356-A2B2-5C2959979F22} = {50C758FE-4E10-409A-94F5-A75480960864}
{23FEFC89-5D2F-491C-BBE0-0E73AFD8BA47} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
16 changes: 15 additions & 1 deletion Microsoft.Maui-vscode.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -225,6 +225,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.Mac.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.WinUI.Tests", "src\Controls\tests\TestCases.WinUI.Tests\Controls.TestCases.WinUI.Tests.csproj", "{DACF87DB-6354-4B18-A34C-923A55F317F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen", "src\Controls\src\BindingSourceGen\Controls.BindingSourceGen.csproj", "{F3E4596C-3047-42F8-9724-80BCE74C141C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen.UnitTests", "src\Controls\tests\BindingSourceGen.UnitTests\Controls.BindingSourceGen.UnitTests.csproj", "{0048EA9A-D751-4576-A2BB-2A37BFB385A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -558,6 +562,14 @@ Global
{DACF87DB-6354-4B18-A34C-923A55F317F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DACF87DB-6354-4B18-A34C-923A55F317F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DACF87DB-6354-4B18-A34C-923A55F317F0}.Release|Any CPU.Build.0 = Release|Any CPU
{F3E4596C-3047-42F8-9724-80BCE74C141C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3E4596C-3047-42F8-9724-80BCE74C141C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3E4596C-3047-42F8-9724-80BCE74C141C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3E4596C-3047-42F8-9724-80BCE74C141C}.Release|Any CPU.Build.0 = Release|Any CPU
{0048EA9A-D751-4576-A2BB-2A37BFB385A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0048EA9A-D751-4576-A2BB-2A37BFB385A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0048EA9A-D751-4576-A2BB-2A37BFB385A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0048EA9A-D751-4576-A2BB-2A37BFB385A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -661,6 +673,8 @@ Global
{AF5A8B2E-13E7-4D94-A44E-BC96180C1FCC} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{0B3AF328-82B8-431D-8AFF-45F0F86CEA0E} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{DACF87DB-6354-4B18-A34C-923A55F317F0} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{F3E4596C-3047-42F8-9724-80BCE74C141C} = {50C758FE-4E10-409A-94F5-A75480960864}
{0048EA9A-D751-4576-A2BB-2A37BFB385A5} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
16 changes: 15 additions & 1 deletion Microsoft.Maui.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -275,6 +275,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.Mac.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.TestCases.WinUI.Tests", "src\Controls\tests\TestCases.WinUI.Tests\Controls.TestCases.WinUI.Tests.csproj", "{A1D6B9E5-D8FF-436A-9ACF-703CA5E4BD02}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen", "src\Controls\src\BindingSourceGen\Controls.BindingSourceGen.csproj", "{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.BindingSourceGen.UnitTests", "src\Controls\tests\BindingSourceGen.UnitTests\Controls.BindingSourceGen.UnitTests.csproj", "{6AEE83CC-08CA-466A-BA86-774BE88A541B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -700,6 +704,14 @@ Global
{A1D6B9E5-D8FF-436A-9ACF-703CA5E4BD02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1D6B9E5-D8FF-436A-9ACF-703CA5E4BD02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1D6B9E5-D8FF-436A-9ACF-703CA5E4BD02}.Release|Any CPU.Build.0 = Release|Any CPU
{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5}.Release|Any CPU.Build.0 = Release|Any CPU
{6AEE83CC-08CA-466A-BA86-774BE88A541B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AEE83CC-08CA-466A-BA86-774BE88A541B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AEE83CC-08CA-466A-BA86-774BE88A541B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AEE83CC-08CA-466A-BA86-774BE88A541B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -828,6 +840,8 @@ Global
{29115330-6854-4715-B382-18EA3A8A8731} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{E8CAE2B6-62B3-431C-A76D-1CCD961A1FB4} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{A1D6B9E5-D8FF-436A-9ACF-703CA5E4BD02} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{83C5E677-A9C8-4E46-B72C-CAF04DC5D3D5} = {50C758FE-4E10-409A-94F5-A75480960864}
{6AEE83CC-08CA-466A-BA86-774BE88A541B} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
Expand Down
60 changes: 60 additions & 0 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,63 @@ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================


License notice for .NET Community Toolkit
=========================================
Comment on lines +526 to +527
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen is it OK to take in code from CommunityToolkit/dotnet (EquatableArray) and dotnet/BenchmarkDotNet (HashCode)?


(https://github.com/CommunityToolkit/dotnet/blob/main/License.md)

Copyright (c) .NET Foundation and Contributors

All rights reserved.

MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================


License notice for BenchmarkDotNet
=========================================

(https://github.com/dotnet/BenchmarkDotNet/blob/master/LICENSE.md)

The MIT License (MIT)

Copyright (c) 2013–2024 .NET Foundation and contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
1 change: 1 addition & 0 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ Task("dotnet-test")
// "**/Controls.Core.Design.UnitTests.csproj",
"**/Controls.Xaml.UnitTests.csproj",
"**/SourceGen.UnitTests.csproj",
"**/Controls.BindingSourceGen.UnitTests.csproj",
"**/Core.UnitTests.csproj",
"**/Essentials.UnitTests.csproj",
"**/Resizetizer.UnitTests.csproj",
Expand Down
18 changes: 18 additions & 0 deletions src/Controls/src/BindingSourceGen/AccessExpressionBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Microsoft.Maui.Controls.BindingSourceGen;

public static class AccessExpressionBuilder
{
public static string ExtendExpression(string previousExpression, IPathPart nextPart)
=> nextPart switch
{
Cast { TargetType: var targetType } => $"({previousExpression} as {CastTargetName(targetType)})",
ConditionalAccess conditionalAccess => ExtendExpression(previousExpression: $"{previousExpression}?", conditionalAccess.Part),
IndexAccess { Index: int numericIndex } => $"{previousExpression}[{numericIndex}]",
IndexAccess { Index: string stringIndex } => $"{previousExpression}[\"{stringIndex}\"]",
MemberAccess memberAccess => $"{previousExpression}.{memberAccess.MemberName}",
_ => throw new NotSupportedException($"Unsupported path part type: {nextPart.GetType()}"),
};

private static string CastTargetName(TypeDescription targetType)
=> targetType.IsValueType ? $"{targetType.GlobalName}?" : targetType.GlobalName;
}
Loading
Loading