Compiler: (Finally!) Remove ItemCollection#11939
Merged
DustinCampbell merged 30 commits intoJun 13, 2025
Merged
Conversation
Member
Author
|
Fixed now. |
davidwengier
approved these changes
Jun 11, 2025
davidwengier
left a comment
Member
There was a problem hiding this comment.
Tooling looks good. PR title brings nothing but joy :D
Store the RazorSyntaxTree produced before the tag helper rewrite as a field on RazorCodeDocument instead of the ItemCollection.
Store the IReadOnlyList<TagHelperDescriptors> as a field on RazorCodeDocument instead of the ItemCollection.
Store the ISet<TagHelperDescriptors> as a field on RazorCodeDocument instead of the ItemCollection.
Store the RazorSyntaxTree as a field on RazorCodeDocument instead of the ItemCollection.
Store the import RazorSyntaxTrees as a field on RazorCodeDocument instead of the ItemCollection.
Store the DocumentIntermediateNode as a field on RazorCodeDocument instead of the ItemCollection.
Store the RazorCSharpDocument as a field on RazorCodeDocument instead of the ItemCollection.
Store CssScope on RazonCodeGenerationOptions instead of the RazorCodeDocument's ItemCollection.
This is just a bit of clean up. The code generation options do not need to be stored on RazorCSharpDocument or RazorHtmlDocument, since they're already stored on RazorCodeDocument.
Avoid creating a new NamespaceDirectiveVisitor for each RazorSyntaxTree
Store the computed namespace name and span on RazorCodeDocument instead of the ItemCollection.
Store the RazorHtmlDocument as a field on RazorCodeDocument instead of the ItemCollection.
Tooling stashes a couple of items in RazorCodeDocument.Items. Employ a ConditionalWeakTable to avoid this.
At long last, ItemCollection is now deleted.
Introduce PropertyTable, which wraps an array of values and exposes each slot as a property. Properties can be reference types or value types. For value types, a StrongBox<T> is used in the array to hold the value.
When searching imports for @namespace directives, we need to iterate them in reverse order to ensure that we prefer imports closer to the source document.
aa89304 to
5efed97
Compare
ToddGrun
reviewed
Jun 12, 2025
| return syntaxTree.Root is RazorSyntaxNode root | ||
| ? root.FindInnermostNode(absoluteIndex) | ||
| : null; | ||
| return codeDocument.GetRequiredSyntaxRoot().FindInnermostNode(absoluteIndex); |
Member
Author
There was a problem hiding this comment.
Yes, but this was wrong and unnecessarily paranoid, so I changed it here. RazorSyntaxTree.Root is annotated as non-null and RazorSyntaxTree's constructor throws if root is null:
ToddGrun
reviewed
Jun 12, 2025
chsienki
reviewed
Jun 12, 2025
- Remove the index consts because they don't really add much value, since they're just used once and its clear what they mean. - Make Property<T> reference the _values slot directly on modern .NET with a ref field. - Make BoxedProperty<T>.StrongBox a readonly field. - Add comments
333fred
approved these changes
Jun 13, 2025
Member
Author
|
Thanks everyone! |
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.
ItemCollectionis essentially a property bag that results in dictionaries being used instead of plain ol' fields, and it's been overused in Razor. I've been trying to get rid of it for nearly a year. #10720, #10764, #11360, and #11931 each represent changes that remove a use ofItemCollection. This pull request finally gets rid ofItemCollectioncompletely.The last use of
ItemCollectionis theRazorCodeDocument.Items, which is used by the compiler to store various objects during compilation, and tooling uses it to cache some expensive-to-create data. This change stores all of the compiler objects onRazorCodeDocumentdirectly. The data cached by tooling is stored on the side in aConditionalWeakTable.As part of this, I've refactoring the
RazorCodeDocument.TryComputeNamespaceextension method to be more understandable and maintainable.CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2728842&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/643246
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2728843&view=results