-
Notifications
You must be signed in to change notification settings - Fork 217
Compiler: (Finally!) Remove ItemCollection #11939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler: (Finally!) Remove ItemCollection #11939
Conversation
|
Fixed now. |
davidwengier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tooling looks good. PR title brings nothing but joy :D
...Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/RazorCodeDocumentExtensions.CachedData.cs
Outdated
Show resolved
Hide resolved
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
| return syntaxTree.Root is RazorSyntaxNode root | ||
| ? root.FindInnermostNode(absoluteIndex) | ||
| : null; | ||
| return codeDocument.GetRequiredSyntaxRoot().FindInnermostNode(absoluteIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
razor/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorSyntaxTree.cs
Lines 20 to 34 in a81a6da
| internal RazorSyntaxTree( | |
| SyntaxNode root, | |
| RazorSourceDocument source, | |
| ImmutableArray<RazorDiagnostic> diagnostics, | |
| RazorParserOptions options) | |
| { | |
| ArgHelper.ThrowIfNull(root); | |
| ArgHelper.ThrowIfNull(source); | |
| ArgHelper.ThrowIfNull(options); | |
| Root = root; | |
| Source = source; | |
| _diagnostics = diagnostics.NullToEmpty(); | |
| Options = options; | |
| } |
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/NamespaceComputer.cs
Outdated
Show resolved
Hide resolved
ToddGrun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
...mpiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeDocument.PropertyTable.cs
Outdated
Show resolved
Hide resolved
- 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
chsienki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. ![]()
|
Thanks everyone! |
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