Repository navigation
feat: expression, value-computer and unbound columns (#378) - #514
Open
michaelstonis wants to merge 4 commits into
Open
michaelstonis wants to merge 4 commits into
michaelstonis wants to merge 4 commits into
Conversation
10 tasks
| or TokenKind.And or TokenKind.Or or TokenKind.Not) || segment.Bracketed) | ||
| throw Error("Expected a property name after '.'", segment); | ||
| _index++; | ||
| path += "." + segment.Text; |
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #378.
Changes
Columns can now show values the item does not have as a property, declared in XAML: an expression over the item's properties, a reusable value computer, or per-row unbound storage kept by the column.
Expression engine (Core,
KumikoUI.Core.Data.Expressions, internal). A hand-written tokenizer and precedence-climbing parser build a tree of nodes that is evaluated by walking it. There is noSystem.Linq.Expressions, noReflection.Emitand no other runtime code generation. Property paths resolve throughKumikoAccessorRegistry.GetPathonce per item type (an immutable, volatile cache per node, so one tree is evaluated from several threads at once).Address.City, or[Address.City]for keyword names), int/long/decimal/double literals (invariant), single- or double-quoted strings with escapes,true/false/null, parentheses.- + ! not,* / %,+ -,< <= > >=,== = != <>,&& and,|| or,??,?:.KumikoComparer.TryGetNumber): exactdecimalwhen both operands are integral or decimal, falling back todoubleon overflow, anddoublewhen either operand is floating-point.+concatenates when either side is text (invariant formatting). Dates subtract to aTimeSpanand take aTimeSpanadded or subtracted. Comparisons always give a Boolean. Logic treats null as false.KumikoExpressionException(Position,Expression,Reason) when the expression is assigned, so a XAML typo fails at page load. Nesting depth and token count are bounded, so a hostile expression cannot overflow the stack.Columns.
KumikoColumngetsExpression,ValueComputer(IKumikoValueComputer:Compute, plus optional default-implementedCanSetValue/TrySetValue) andIsUnbound. Unbound storage is aConditionalWeakTable<object, StrongBox<object?>>per column, keyed by item reference and safe to read from a background build.GetUnboundValue,SetUnboundValue,HasUnboundValueandClearUnboundValuesgive access from code.SetUnboundValuerefreshes the grid: cells, sort, filter, grouping and summaries. Value-type items are refused, and unbound values are not part ofKumikoLayoutState.ValueAccessor>ValueComputer>Expression> unbound storage >PropertyName.ValueSetter> the computer's write-back (falls back to unbound storage when the column is also unbound) > unbound storage >PropertyName.SetCellValuereturns false).ColumnTypeand raiseCellValueChanged.One read path. The column exposes one internal
EffectiveAccessordelegate, rebuilt only when a value setting changes, so caches can compare it by reference.KumikoSource.ReadColumnValue,ItemReader(sort, filter, grouping, summaries, search, background builds),CellTextCache, clipboard and export (KumikoExportColumn) all read through it.Change tracking.
ValueDependsOn). An expression depends only on the paths it reads (and their parents). An unbound column depends on its own value changes, reported under its name. A computer depends on any property, likeValueAccessor.Naming. Group and summary descriptions find a column by
PropertyName, else byKeyfor a column without a property. The column menu's Group by uses the same name.Keyis documented as required for unbound columns, and a warning is traced when one has none.Event.
KumikoSource.UnboundValueRequested(KumikoUnboundValueEventArgs:Column,Item,Error, settableValue,HasValue) is raised for two cases:Errorsays why, and the handler may supply a value. With no handler, the error is traced once per column and message.Erroris null, and a supplied value is stored.During background builds it is raised on the worker thread (documented).
Public API added (Core
PublicAPI.Unshipped.txt):IKumikoValueComputer(Compute,CanSetValue,TrySetValue)KumikoExpressionException(ctor,Expression,Position,Reason)KumikoColumn.Expression,ValueComputer,IsUnbound,GetUnboundValue,SetUnboundValue,HasUnboundValue,ClearUnboundValuesKumikoSource.UnboundValueRequestedKumikoUnboundValueEventArgs(ctor,Column,Item,Error,Value,HasValue)KumikoColumnbecamepartial(no API change). No MAUI or Uno API changes: columns are Core objects in host XAML, and both hosts pass them through as is.Samples.
MainPage(MAUI) andBasicGridPage(Uno) each add three columns:Salary / 12)TenureYearsComputerpage resource (samples/Shared/TenureYearsComputer.cs)Employeetypes implement a small sharedIHasHireDateinterface.Other changes.
bench/KumikoUI.Benchmarks/ExpressionColumnBenchmarks.cssorts 100,000 rows by an expression, a lambda accessor and a bound property.eng/AotSmokechecks expression and unbound columns: decimal arithmetic, the conditional, concatenation, sort, group and summary.docs/RENDERING.md(cache invalidation),docs/EXPORT.md, and a CHANGELOG entry.One small change outside Core models. In
KumikoInputController.ColumnMenu.csthe Group by / Ungroup item now names the column byValueName(PropertyName, elseKey) instead ofPropertyName, so computed columns can be grouped from the menu. Nothing else in the input controller changed, and the renderer, its drawing and layout code, and the hit tester are untouched.Acceptance criteria
Expression,ValueComputerandIsUnboundcolumns work from XAML on MAUI and Uno, with the documented precedence. MAUI is covered by a runtime-XAML host test (KumikoDataGridComputedColumnsTests, with aStaticResourcecomputer) and by the XamlC-compiled sample. Uno is covered byBasicGridPage, which declares all three column kinds and builds through the Uno XAML generator; the Uno test project cannot load XAML at runtime, so there is no Uno runtime test. Precedence is covered byValueSources_FollowTheDocumentedPrecedence.eng/AotSmoke). New AotSmoke checks were added, and the published binary runs with no IL2xxx/IL3xxx warnings.tests/KumikoUI.Core.Tests: 55 parser/evaluation tests inData/ColumnExpressionTests.csand 36 tests inComputedColumnTests.cs. They cover precedence, literals, nulls, types, dates, parse-error positions, depth limits, thread safety, invalidation, unbound storage, editing, background builds, layout state, and errors reported rather than thrown.PublicAPI.Unshipped.txtupdated.eng/update-public-api.sh Coreemptied the file on this machine becausedotnet formatreported no fixes, so the file was restored and the 28 RS0016 symbols from the build were added and sorted by hand. The build is clean.Verification
dotnet build src/KumikoUI.Core,src/KumikoUI.SkiaSharp,src/KumikoUI.Export.Excel: succeeded, 0 warnings.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst,dotnet build src/KumikoUI.Uno -f net10.0-desktop: succeeded.dotnet test tests/KumikoUI.Core.Tests: 4452 passed, 5 skipped, 0 failed.dotnet test tests/KumikoUI.Maui.Tests: 450 passed.dotnet test tests/KumikoUI.Uno.Tests: 321 passed.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.dotnet test tests/KumikoUI.Export.Excel.Tests: 122 passed.dotnet test tests/KumikoUI.SourceGenerators.Tests: 10 passed.dotnet build samples/SampleApp.Uno/SampleApp.Uno.csproj -f net10.0-desktop: succeeded.dotnet build samples/SampleApp.Maui/SampleApp.Maui.csproj -f net10.0-maccatalyst -c Release(as CI builds it): succeeded. The Debug build fails restore with NU1605 from the DevFlow package pin on this machine, which this change does not affect.dotnet run --project eng/DocsSnippets -c Release, thendotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Releaseanddotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: succeeded.dotnet publish eng/AotSmoke -c Release -r osx-arm64: no trim or AOT warnings, and the binary prints "AOT smoke OK". This machine's .NET install neededLIBRARY_PATHpointing at OpenSSL and Brotli to link.dotnet run -c Release --project bench/KumikoUI.Benchmarks -- --filter '*ExpressionColumn*' --job short, sorting 100,000 rows:ValueAccessorlambdaQuantity * UnitPriceHeld for Foundations
Grouping a computed column from the built-in column menu (Group by / Ungroup) is not included: the menu items are built in
KumikoInputController.ColumnMenu.cs, which stays untouched until #446/#448 land. Grouping a computed column from code (GroupDescriptionwith the column'sKey) works.