Skip to content

Build Roslyn-first framework-neutral XAML compiler#35

Merged
wieslawsoltes merged 89 commits into
mainfrom
agent/roslyn-xaml-compiler
Jul 24, 2026
Merged

Build Roslyn-first framework-neutral XAML compiler#35
wieslawsoltes merged 89 commits into
mainfrom
agent/roslyn-xaml-compiler

Conversation

@wieslawsoltes

@wieslawsoltes wieslawsoltes commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What changed

  • adds a clean-room, framework-neutral XAML tokenizer, parser, Roslyn-isomorphic syntax/infoset/binding/IR pipeline, semantic type system, formatter, editor, reverse projection, and structured Roslyn code emitter
  • adds the incremental source generator, standalone CLI, Workspaces integration, MSBuild/NuGet wiring, diagnostics, hot-reload hooks, preview compiler, and generator test harnesses
  • expands the ProGPU WinUI object model and attribute/convention metadata needed by current WinUI XAML
  • adds ProGPU.WinUI.Themes.Fluent, compiling and packaging the unchanged external Microsoft UI XAML generic.xaml
  • adds XAML compiler showcase pages, binding/function/resource/layout/markup examples, and an interactive XAML playground
  • records normative requirements, architecture, feature inventory, clean-room research, implementation plan, and support matrix

Why

ProGPU needs one high-performance, extensible XAML compiler core that can serve WinUI first and later Avalonia, WPF, MAUI, and custom dialects without duplicating parser, type-system, workspace, formatting, or generation infrastructure. Generated C# is constructed exclusively as Roslyn syntax nodes rather than emitted as strings.

Current status

This is intentionally a draft and remains under active development. Ordinary {Binding} and compiled {x:Bind} have distinct bound/IR models and independent transactional lifetimes. Typed ordinary source inference covers lexical x:DataType, literals, exact x:Static, RelativeSource Self, same-namescope ElementName, profile-resolved RelativeSource TemplatedParent, and exact local or external resource-graph sources.

The shared netstandard2.0 markup language has an immutable versioned plugin registry. Framework and user plugins declare contexts, triggers, precedence, associativity, capabilities, and conflict policy; token recognition is trigger-indexed; custom root and attribute syntax projects into the canonical AST and normal infoset pipeline; and registered formatting/generation inverses must parse and structurally round-trip before publication.

The downstream immutable Roslyn extension host supports ordered bound-document transforms, bound validators over the enriched resource graph, audited construction-program transforms, and markup-expression handlers that return only structured ExpressionSyntax. Framework and caller extensions share one deterministic order, strict bounded audits, explicit diagnostics, and cancellation.

Generator, direct, Workspace, and CLI hosts share one compilation-dependent semantic-manifest compiler. It resolves build metadata/resource identity, applies profile/caller transforms, and derives dependency manifests from the accepted document. Workspace compilation removes only prior reserved *.ProGPU.Xaml.g.cs trees before rebinding. Generated identities use canonical SHA-256 and final C# is deterministic BOM-free UTF-8.

The parser has snapshotted limits, a 1,024 absolute depth ceiling, long-token cancellation, deterministic malformed-input lossless fuzzing, excessive-depth recovery, and bounded-allocation tests. Bounded inspection services expose the exact canonical syntax/token/infoset/bound/resource/transformed-IR/generated-syntax stages to the CLI and playground without a display-only compiler pipeline.

The playground uses cancellable versioned background inspection and explicit-permission live preview. It derives edited x:Class and root types through the neutral type system, synthesizes hosts entirely as Roslyn syntax, emits in-memory PE images without C# parse-back, gates dynamic loading on runtime support, validates typed WinUI roots in collectible contexts, and swaps through canonical state transfer with last-good retention.

Project-context preview is implemented in the reusable Workspaces layer. It accepts an immutable Roslyn Project/XAML AdditionalDocument plus optional unsaved SourceText, preserves real C# parse options, compiles every recognized sibling XAML document against one semantic resource index, and emits one complete structured-tree PE without mutating the Workspace. The standalone progpu-xaml preview command exposes this through MSBuildWorkspace and transactional output; it compiles the real six-document ProGPU sample project with zero visible diagnostics.

Immutable project-delta planning matches documents by canonical resource URI, distinguishes formatting-only, semantic target, unrelated sibling, imported-resource-provider, and host-metadata changes, and exposes stable infoset/projection identity deltas from accepted structured Roslyn trees. Unrelated sibling changes do not churn the visible target. A stateful prepare/apply/commit coordinator compiles outside its lock, serializes host publication, rejects stale/foreign/invalid candidates before invoking the publisher, and advances its last-good comparison baseline only after success. The WinUI adapter validates and activates a collectible candidate before coordinating metadata, publishes through canonical state transfer, and commits the compiler generation only after runtime success. Missing or failed metadata coordination and invalid artifacts retain both the last good tree and comparison baseline.

The unchanged Fluent corpus emits and compiles with zero diagnostics against the completed public template-settings contracts. Remaining MVP gates include broader multi-file diagnostics/manifest/linked-item/checkout-root host equivalence, parser fuzz/performance baselines, IDE/playground project selection and watch integration, namescope-aware fine-grained template patching, resource-generation invalidation, a Roslyn metadata-delta producer, and collection-root replacement.

Validation

  • dotnet test src/ProGPU.Xaml.Tests/ProGPU.Xaml.Tests.csproj -c Release --no-restore — 243 passed
  • dotnet test src/ProGPU.Tests/ProGPU.Tests.csproj --no-restore — 2347 passed at the last full runtime checkpoint
  • dotnet test src/ProGPU.Tests/ProGPU.Tests.csproj -c Release --filter FullyQualifiedName~HotReload --no-restore — 16 passed
  • dotnet test src/ProGPU.Tests.Headless/ProGPU.Tests.Headless.csproj -c Release --no-restore — 197 passed at the last headless checkpoint
  • affected Workspaces and WinUI Designer Release builds — zero warnings/errors
  • dotnet build tools/ProGPU.Xaml.Cli/ProGPU.Xaml.Cli.csproj -c Release --no-restore — zero warnings/errors at the last CLI checkpoint
  • progpu-xaml preview ...XamlCompilerWelcomePage.xaml --project ...ProGPU.Samples.csproj --json — committed a complete six-document project preview PE with zero visible diagnostics
  • ./eng/progpu-verify-docs.sh — succeeded
  • dotnet build src/ProGPU.slnx --no-restore — succeeded at the last full solution checkpoint
  • portable package manifest — 30 shipping and 12 non-shipping projects classified
  • portable package verification — 28 packages and required symbol artifacts passed
  • isolated package consumer — clean restore/build/run, generated-source inspection, packaged CLI install/parse/compile, byte-identical BOM-free generator/CLI C#, and deterministic zero/two-facade rejection passed
  • ProGPU.WinUI.Themes.Fluent pack succeeded; source and packaged Generic.xaml remain byte-identical with SHA-256 4c4085838721c0afcb1a9ee17591c0655cdddadb26d330788e08bcd7f1af8285

@wieslawsoltes
wieslawsoltes marked this pull request as ready for review July 24, 2026 05:30
@wieslawsoltes
wieslawsoltes merged commit 66ee399 into main Jul 24, 2026
7 checks passed
@wieslawsoltes
wieslawsoltes deleted the agent/roslyn-xaml-compiler branch July 24, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant