Remove LazyContent and eagerize intermediate token content creation#13054
Draft
Copilot wants to merge 3 commits into
Draft
Remove LazyContent and eagerize intermediate token content creation#13054Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/dotnet/razor/sessions/aab22442-6f3a-43d3-beb8-dc1adf0a2242 Co-authored-by: chsienki <16246502+chsienki@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Remove LazyContent and simplify IntermediateToken
Remove LazyContent and eagerize intermediate token content creation
Apr 15, 2026
…rators.Transport 9.0.0-preview.26159.4 Agent-Logs-Url: https://github.com/dotnet/razor/sessions/91349015-46a0-4857-b955-27c31a157c0a Co-authored-by: chsienki <16246502+chsienki@users.noreply.github.com>
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.
9.0.0-preview.26159.4fromdotnet8-transportfeed)7.0.0-preview.5.22528.1to9.0.0-preview.26159.4dotnet8-transportfeed (network download blocked in sandbox)Original prompt
Summary
Remove the entire
LazyContent/ lazyIntermediateTokeninfrastructure. We recently removed a whole bunch of lazy intermediate token usages and the remaining ones add complexity for marginal benefit since almost all token content gets read anyway during code generation.What to remove/change
1. Delete
LazyContent.cssrc/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/LazyContent.cs2. Delete
LazyContentTests.cssrc/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/LazyContentTests.cs3. Simplify
IntermediateToken.csIn
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateToken.cs:IsLazyproperty entirelyprivate object _contenttoprivate string _contentContentgetter from_content is LazyContent lazy ? lazy.Value : (string)_contentto just return_contentprivate protected IntermediateToken(LazyContent content, SourceSpan? source)constructor4. Remove
LazyContentconstructors from token typesCSharpIntermediateToken.cs: Remove theinternal CSharpIntermediateToken(LazyContent content, SourceSpan? source)constructorHtmlIntermediateToken.cs: Remove theinternal HtmlIntermediateToken(LazyContent content, SourceSpan? source)constructor5. Remove generic factory methods from
IntermediateNodeFactory.csIn
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateNodeFactory.cs:CSharpToken<T>(T arg, Func<T, string> contentFactory, SourceSpan? source = null)methodHtmlToken<T>(T arg, Func<T, string> contentFactory, SourceSpan? source = null)methodusing System;import can likely be removed too6. Update all producers to eagerly evaluate content
In
DefaultRazorIntermediateNodeLoweringPhase.cs, every call like:should become:
Similarly for CSharp tokens:
should become:
There are multiple such call sites in the lowering phase — make sure to update all of them. Key methods to check:
VisitMarkupTextLiteral(both in the attribute context and the HTML content context, and theCombinemethod)VisitMarkupLiteralAttributeValueVisitCSharpExpressionLiteralAlso in
VisitMarkupLiteralAttributeValuefor the unresolved attribute case, the pattern:should become:
7. Remove
IsLazychecks in downstream consumersIn
ComponentTypeArgumentIntermediateNode.cs, theGetValuemethod currently has:This should be simplified to just:
In
DefaultTagHelperResolutionPhase.cs, theToCSharpTokenmethod:Should be simplified to:
8. Update test infrastructure
In
src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs, theWriteNamemethod has:This should be simplified to:
9. Update test baseline files
All
.ir.txttest baseline files that containLazyIntermediateTokenneed to have those occurrences replaced withIntermediateToken. The ma...This pull request was created from Copilot chat.