Skip to content

Proposal: RegisterPreCompilationSourceOutput API for Incremental Generators#82680

Closed
chsienki wants to merge 1 commit into
dotnet:mainfrom
chsienki:features/pre-compilation-source-outputs
Closed

Proposal: RegisterPreCompilationSourceOutput API for Incremental Generators#82680
chsienki wants to merge 1 commit into
dotnet:mainfrom
chsienki:features/pre-compilation-source-outputs

Conversation

@chsienki

@chsienki chsienki commented Mar 10, 2026

Copy link
Copy Markdown
Member

This PR adds a proposal document for a new RegisterPreCompilationSourceOutput API for incremental source generators.

The document proposes a new incremental generator API that allows generators to produce source that is added to the initial compilation while reading from non-compilation inputs (additional files, parse options, analyzer config).

The primary motivation is Razor performance: this API eliminates the need for Razor to create an intermediate compilation for cross-file binding, reducing compilation phases from 3 to 2 and yielding roughly 50% performance improvement.

Secondary benefits include cross-generator type visibility and configurable post-initialization outputs.

See docs/features/pre-compilation-source-outputs.md for the full proposal.

Adds a new incremental source generator API that allows generators to produce
source added to the initial compilation before compilation-dependent phases
execute. This enables generators to produce source that is visible to other
generators' standard phases and to the compilation itself.

Key changes:
- New PreCompilationSourceProductionContext (no diagnostics, no compilation)
- RegisterPreCompilationSourceOutput overloads on IncrementalGeneratorInitializationContext
- Two-pass execution in GeneratorDriver: pre-compilation pass then standard pass
- DriverStateTable.Builder defers Compilation/SyntaxStore until after pre-compilation
- InputNode wraps _getInput exceptions as UserFunctionException for clean error handling
- AbstractSourceOutputNode base class shared by SourceOutputNode and PreCompilationSourceOutputNode
- New RSEXPERIMENTAL007 experimental feature ID
- 25 comprehensive tests covering functionality, caching, error handling, and step tracking

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chsienki chsienki force-pushed the features/pre-compilation-source-outputs branch from 60dba0f to 1dcf462 Compare April 7, 2026 20:40
@chsienki chsienki requested review from a team as code owners April 7, 2026 20:40
@dotnet-policy-service dotnet-policy-service Bot added the Needs API Review Needs to be reviewed by the API review council label Apr 7, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

@chsienki chsienki changed the title Proposal: RegisterPreCompilationSourceOutput API for Incremental Generators Add RegisterPreCompilationSourceOutput API for incremental generators Apr 7, 2026
@chsienki chsienki marked this pull request as draft April 7, 2026 20:41
@chsienki chsienki closed this Apr 7, 2026
@chsienki chsienki changed the title Add RegisterPreCompilationSourceOutput API for incremental generators Proposal: RegisterPreCompilationSourceOutput API for Incremental Generators Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Needs API Review Needs to be reviewed by the API review council

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant