-
Notifications
You must be signed in to change notification settings - Fork 195
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
Adopt WellKnownTypeProvider for type lookup by name #8310
base: main
Are you sure you want to change the base?
Conversation
sharwell
commented
Feb 22, 2023
•
edited
Loading
edited
- Store WellKnownTypeProvider (from dotnet/roslyn-analyzers) in TagHelperDescriptorProviderContext
- Match by type instead of name
…erDescriptorProviderContext
69dc9c7
to
6e78f5a
Compare
7b77a7c
to
23b7552
Compare
9cdb43d
to
a653a5b
Compare
We'll need to run the benchmarks on this to make sure it doesn't regress. Currently the path that we changed name lookup for isn't being hit. So we'll need to incorporate the perf/generator PR on top of this to ensure it doesn't regress in the new scenario. |
@sharwell I merged everything together in order to run the benchmarks, and it looks good.
Note that the 'old' doesn't include #8297 so the allocations are a little higher, but generally looks like the perf impact is minimal (it was like 10x slower with |
|
||
namespace Microsoft.CodeAnalysis.Razor; | ||
|
||
internal static class ImmutableArrayExtensions |
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.
➡️ Moving to new location
@@ -1 +1,2 @@ | |||
#nullable enable | |||
*REMOVED*~static Microsoft.CodeAnalysis.Razor.TagHelperDescriptorProviderContextExtensions.SetCompilation(this Microsoft.AspNetCore.Razor.Language.TagHelperDescriptorProviderContext context, Microsoft.CodeAnalysis.Compilation compilation) -> void |
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.
We can't break the public API yet.
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.
➡️ Restoring the method, marking obsolete, and implementing by creating a new WellKnownTypeProvider
and forwarding the call to SetTypeProvider
var compilation = context.GetCompilation(); | ||
if (compilation == null) | ||
var typeProvider = context.GetTypeProvider(); | ||
if (typeProvider == null || !ComponentSymbols.TryCreate(typeProvider, out var symbols)) |
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.
Feels like it might be cleaner to move the typeProvider == null
into TryCreate
.
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.
➡️ Added the null check to TryCreate
switch (symbol.Kind) | ||
{ | ||
case SymbolKind.Alias: | ||
// Aliases are uber private. They're only visible in the same file that they |
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.
I just know this is a Cyrus comment.
Public = 0, | ||
Internal = 1, | ||
Private = 2, | ||
Friend = Internal, |
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.
We don't deal with VB, this alias isn't required.
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.
➡️ Removing
/// <summary> | ||
/// Provides and caches well known types in a compilation. | ||
/// </summary> | ||
public class WellKnownTypeProvider |
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.
Feels like maybe we should pull this from roslyn-analyzers into a shared package, like we do for pooled objects. I'm somewhat concerned about trying to keep this up to date: razor already has plenty of things copied over that have received significant changes from the original code.
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.
It's certainly possible. I'm not happy with the current API shape so I'd be hoping for a significant rewrite.
Ideally this would be moved to the compiler as part of a source generator helper API, and instead of operating on Compilation
it would operate on IAssemblySymbol
in a manner than allows symbols from metadata references to be carried forward in an incremental source generator without changing every time the compilation changes.
➡️ Not planning on making any changes here as part of this pull request.
@chsienki correct me if I'm reading this wrong, but those benchmarks don't look good? Cold compilation, in particular, looks bad. The minor memory savings don't seem to be paying off with wall-clock time. |