Skip to content

Phase 3: Incremental generator migration, decomposition, and API polish - #367

Merged
kzu merged 1 commit into
mainfrom
feat/phase-3-incremental-generator
Nov 29, 2026
Merged

kzu merged 1 commit into
mainfrom
feat/phase-3-incremental-generator

Conversation

@kzu

@kzu kzu commented Nov 29, 2026

Copy link
Copy Markdown
Member

Summary

Phase 3 of the Stunts codebase audit: migrates StuntGenerator to IIncrementalGenerator, decomposes the monolithic generator and rewriter files, fixes standalone Stunts.CompiledProxy packaging, and improves runtime factory isolation and behavior chaining APIs.

Generator Decomposition & Line-Ending Normalization

  • Split StuntGenerator.cs into StuntDiscovery, StuntPipeline, CSharpFormatter, SyntaxText, and instance-scoped GenProfile (removing static mutable profiler state).
  • Split CSharpRewrite.cs into HolderEmitter and ForwardingEmitter, keeping INamedTypeSymbolExtensions public.
  • Centralized optional metadata type lookups in WellKnownTypes across StuntFingerprint, CSharpAot, and StuntRegistrations.
  • Normalized all generated source line endings to \n (LF) and chunked StuntRegistrations.Initialize() into [MethodImpl(MethodImplOptions.NoInlining)] batches above 256 statements to prevent stack overflows in large assemblies (e.g. Acceptance/Static on Windows Debug).

IIncrementalGenerator Migration & Standalone Packaging

  • Abstracted ProcessorContext away from GeneratorExecutionContext/ISyntaxReceiver and replaced IStuntCandidatesReceiver with incremental IStuntCandidatesProvider (WithCandidateProvider).
  • Migrated StuntGenerator to IIncrementalGenerator (CreateSyntaxProvider with equatable discovery records and tracking names + RegisterSourceOutput).
  • Removed RS1042 suppressions from Stunts.CompiledProxy.csproj, build/Stunts.CompiledProxy.targets, and tests.
  • Fixed literal Pack="!$(IsPackable)" in Stunts.CompiledProxy.targets using a computed _PackProjectReferences property so the standalone Stunts.CompiledProxy NuGet package no longer packs Stunts.dll directly into lib/.

Runtime & Packaging API Polish

  • Added per-assembly StuntFactory.Register, Unregister, and GetFactory so compiled and DynamicProxy assemblies coexist safely within the same process (preserving LocalDefault precedence and StuntFactory.Default fallback).
  • Added typed AddBehavior<TBehavior>() and InsertBehavior<TBehavior>(int) chaining on StuntReference<T>, StuntBuilder, and StuntExtensions (C# and VB).

Verification

  • dotnet format whitespace --verify-no-changes and dotnet format style --verify-no-changes
  • Full dotnet build and dnx --yes retest (460 passed, 0 failed)
  • dotnet pack + verified Stunts.CompiledProxy and Stunts package layouts
  • Acceptance.slnx (Static, Dynamic, and VB Dynamic.Basic) all passed

This pull request was created by CodeAlta.

…or pipeline

- Decompose StuntGenerator.cs and CSharpRewrite.cs into StuntDiscovery, StuntPipeline,
  CSharpFormatter, SyntaxText, HolderEmitter, ForwardingEmitter, WellKnownTypes, and
  instance-scoped GenProfile.
- Migrate StuntGenerator and ProcessorContext to IIncrementalGenerator with
  CreateSyntaxProvider, equatable discovery records, and IStuntCandidatesProvider
  (WithCandidateProvider), removing RS1042 suppressions.
- Normalize all generated source line endings to LF and batch large
  StuntRegistrations.Initialize bodies into NoInlining helpers to prevent stack overflow
  with thousands of generated stunts.
- Fix literal Pack="!$(IsPackable)" in Stunts.CompiledProxy.targets so standalone
  Stunts.CompiledProxy packages do not erroneously pack Stunts.dll into lib/.
- Add per-assembly StuntFactory.Register/Unregister/GetFactory so compiled and
  DynamicProxy assemblies coexist safely.
- Add typed AddBehavior<TBehavior>/InsertBehavior<TBehavior> chaining on StuntReference,
  StuntBuilder, and StuntExtensions (C# and VB).

Co-authored-by: CodeAlta <noreply@codealta.io>
@kzu kzu added the enhancement New feature or request label Nov 29, 2026
@kzu
kzu enabled auto-merge (rebase) November 29, 2026 20:29
@kzu
kzu merged commit b2e39d7 into main Nov 29, 2026
7 checks passed
@kzu
kzu deleted the feat/phase-3-incremental-generator branch November 29, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant