Skip to content
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

Don't cache 'RegisterTypeRuntimeClassNameLookup' #1586

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,9 @@ internal static void GenerateVtableLookupTable(Action<string, string> addSource,
// referenced and that can run into issues because they can have their own lookup tables that
// get registered in their module initializer, but will fail to due to the reader writer lock we have around it
// (i.e. we are traversing the lookup tables here while one is being registered).
//
// Note: just like with the authoring metadata function, we don't use a method group expression but rather construct a 'Func<Type, string>' ourselves.
// This is done to opt-out of the implicit caching that Roslyn does. We don't need that extra code and overhead, as this is only done once.
var hasRuntimeClasNameEntries = value.vtableAttributes.Any(v => !string.IsNullOrEmpty(v.RuntimeClassName));
if (value.vtableAttributes.Any())
{
Expand All @@ -930,7 +933,7 @@ internal static class {{classPrefix}}GlobalVtableLookup
internal static void InitializeGlobalVtableLookup()
{
ComWrappersSupport.RegisterTypeComInterfaceEntriesLookup(LookupVtableEntries);
{{(hasRuntimeClasNameEntries ? "ComWrappersSupport.RegisterTypeRuntimeClassNameLookup(LookupRuntimeClassName);" : "")}}
{{(hasRuntimeClasNameEntries ? "ComWrappersSupport.RegisterTypeRuntimeClassNameLookup(new Func<Type, string>(LookupRuntimeClassName));" : "")}}
}

private static ComWrappers.ComInterfaceEntry[] LookupVtableEntries(Type type)
Expand Down