Reimplement the Razor compiler using source generators & support incrementality
pranavkm opened this issue ยท 3 comments
Summary
The Razor compiler today represents a significant portion of time experienced by developers in inner-loop scenarios. We should investigate reimplementing it to be based on source generators to avoid the cost of an extra discrete step and removal of another process associated with building.
Today, the Razor compilation process is non-incremental, meaning even the smallest change to any Razor file results in a complete build of all Razor assets in a project. We should investigate the potential for adding further incrementality to Razor compilation so that unnecessary compilation time is not spent between edits.
Notes
The hypothesis is that an additional compile step can be eliminated along with state management if we are able to use source generators. We might also benefit of not producing janky types in design time builds.
Tasks
- Draft PR: #28807
- SDK PR PR: dotnet/sdk#15756
- Combine views and app assembly: #29862
- Add tests for SourceGenerators
- Migrate tests for SG-specific SourceDocuments from Razor.Language
- Add integration tests for SG-specific scenarios
- Tooling EnC support for source generated files: dotnet/roslyn#50039 (ETA 2/8)
- Tooling EnC support for swapping between Razor design time and source generated files: ETA 2/15. No tracking issue.
- Compiler: Framework to support incrementalism in source generators: No tracking issue, but this is not blocking (dotnet/roslyn#51257)
Speaking as someone who implemented a few source generators for Blazor, I absolutely love that this is one of the things potentially coming in net6.0!
However, please make sure that SGs should also support some sort of sequencing by that time. Otherwise all current SGs which rely on evaluating any of the generated code (the .g.cs files, e.g. for analyzing parameters) would break.
Thanks!
(See also: dotnet/roslyn#48358)
@captainsafia let's use the smaller line items to track further work. We'll consider this issue resolved for preview4.
@stefanloerwald we made the Roslyn folks aware of your requirement. In addition, there are some ordering requirements for some of the in-box source generators e.g. System.Text.Json's source generator needs to run after the Razor one, so we have vested interest in seeing it addressed.
@pranavkm Agreed -- I removed the working label for that very reason. Up, up, and away.