TagHelperCollection Part 1: The new bits#12504
Merged
DustinCampbell merged 15 commits intodotnet:mainfrom Nov 24, 2025
Merged
Conversation
This was referenced Nov 18, 2025
Merged
davidwengier
approved these changes
Nov 19, 2025
Member
davidwengier
left a comment
There was a problem hiding this comment.
That was all very much over my head, other than I did wonder if "SameItems" should be called "SequenceSame", to match SequenceEqual.
Valuable feedback!
ToddGrun
reviewed
Nov 19, 2025
...ompiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection.RefBuilder.cs
Outdated
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...rosoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection.RefBuilder.Enumerator.cs
Outdated
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection.Builder.Enumerator.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection_Factories.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection_Factories.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection_Factories.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection_Factories.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection_Factories.cs
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/TagHelperCollection.cs
Outdated
Show resolved
Hide resolved
ToddGrun
reviewed
Nov 19, 2025
...r.Workspaces/Serialization/MessagePack/Formatters/TagHelpers/TagHelperCollectionFormatter.cs
Show resolved
Hide resolved
Member
Author
DustinCampbell
added a commit
that referenced
this pull request
Nov 20, 2025
| Prelude | [Part 1](#12504) | [Part 2](#12505) | [Part 3](#12506) | [Part 4](#12507) | [Part 5](#12509) | This is a set of support utilities and helpers added as part of the `TagHelperCollection` changes: - Added `InterlockedOperations.Initialize(...)` overloads for lock free initialization with a factory method. (f3686aa) - Added two `LazyValue` structs that use the new `InterlockedOperations.Initialize(...)` overloads. These are useful for lazily initializing a value without extra allocations or locks. (81795f5) - Added `OverloadResolutionPriorityAttribute` polyfill type. (27ab174) - Refactored `TagHelperCache` to extract `CleanableWeakCache<TKey, TValue>`. This caches items as weak references. When the number of items added reaches a configurable threshold, the cache is cleaned up, and any dead weak references are removed. (673a9b5) ---- CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842136&view=results Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842197&view=results
DustinCampbell
added a commit
that referenced
this pull request
Nov 24, 2025
| [Prelude](#12503) | [Part 1](#12504) | Part 2 | [Part 3](#12506) | [Part 4](#12507) | [Part 5](#12509) | > [!WARNING] > This pull request contains breaking changes for the RazorSdk. Once this is merged and flows to the VMR, dotnet/dotnet@9a7e708 will need to be cherry-picked to resolve build breaks in `src/sdk/src/RazorSdk`. These commits represent the (mostly) mechanical changes needed to integrate `TagHelperCollection` across the Razor code base. Most references to `ImmutableArrary<TagHelperDescriptor>`, `IReadOnlyList<TagHelperDescriptor>`, `IEnumerable<TagHelperDescriptor>`, and `TagHelperDescriptor[]` have been replaced with `TagHelperCollection`. This is **by far** the largest of the `TagHelperCollection` pull requests. While most of the commits contain mechanical changes across the code base, there are few that include more substantial work that require a bit more scrutiny: - **Update `RenameService` to remove `ImmutableArray<TagHelperDescriptor>`** (fa3ad2b) This includes a fair amount of refactoring in `RenameService` to fix bugs found when moving to `TagHelperCollection`. - **Update `TagHelperFacts` to use `TagHelperCollection`** Extra work was done in `DirectiveAttributeComplationItemProvider` to clean up a bit following #12473. ---- CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842165&view=results Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842237&view=results
DustinCampbell
added a commit
that referenced
this pull request
Nov 24, 2025
…c in source generator (#12506) | [Prelude](#12503) | [Part 1](#12504) | [Part 2](#12505) | Part 3 | [Part 4](#12507) | [Part 5](#12509) | This is a relatively small change to remove LINQ from the Razor source generator and use `TagHelperCollection` when checking for added/removed tag helpers. ---- CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842169&view=results Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842240&view=results
DustinCampbell
added a commit
that referenced
this pull request
Nov 24, 2025
| [Prelude](#12503) | [Part 1](#12504) | [Part 2](#12505) | [Part 3](#12506) | Part 4 | [Part 5](#12509) | > [!WARNING] > This pull request contains breaking changes for the RazorSdk. Once this is merged and flows to the VMR, dotnet/dotnet@dc17a09 will need to be cherry-picked to resolve build breaks in `src/sdk/src/RazorSdk`. Previously, tag helpers were discovered by `ITagHelperDescriptorProvider`. Each provider was responsible for walking a compilation's assemblies and producing `TagHelperDescriptors` from the types within. This change inverts the tag helper discovery process by introducing `ITagHelperDiscoveryService` and moving the tag helper construction logic into a set of `TagHelperProducers`. The `ITagHelperDiscoveryService` performs a single walk of the compilation or assembly and calls the producers as needed. Importantly, the new process allows a more expansive cache to be maintained. There is now a per-assembly cache that holds onto `TagHelperCollection` instances. The old cache that was owned by providers via `TagHelperCollector` has been removed. To complete this change, `ITagHelperDescriptorProvider` and related types have been _deleted_. ---- CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842196&view=results Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842249&view=results
DustinCampbell
added a commit
that referenced
this pull request
Nov 24, 2025
…xt (#12509) | [Prelude](#12503) | [Part 1](#12504) | [Part 2](#12505) | [Part 3](#12506) | [Part 4](#12507) | Part 5 | This change introduces a weak cache for `TagHelperDocumentContext` keyed by the tag helper prefix string and `TagHelperCollection` checksum. This helps avoid creating new `TagHelperBinders` for the same set of tag helpers, since `TagHelperBinder` is expensive to create. ---- CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842228&view=results Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842250&view=results
This was referenced Nov 25, 2025
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.


| Prelude | Part 1 | Part 2 | Part 3 | Part 4 | Part 5 |
This pull request represents all new code! It introduces a new immutable collection type,
TagHelperCollection, that is designed to containTagHelperDescriptors. It is built with the following principles:Tip
Since this is all new code, I recommend reviewing commit-by-commit. Each commit represents a cohesive portion of new code.
CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842145&view=results
Toolset Run: https://dev.azure.com/dnceng/internal/_build/results?buildId=2842216&view=results