Skip to content

Commit

Permalink
Minor changes to IIDOptimizer and AOTOptimizer (#1626)
Browse files Browse the repository at this point in the history
* Fix value type assignment scenarios getting misdetected

* Make IIDOptimizer not write binary if it patched nothing

* Fix return code and remove message which has caused confusion in the past
  • Loading branch information
manodasanW authored Jun 1, 2024
1 parent cdaa5f1 commit 6257088
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,9 @@ void AddVtableAttributesForType(Microsoft.CodeAnalysis.TypeInfo instantiatedType
// type need to be put on the CCW.
if (instantiatedType.Type is IArrayTypeSymbol arrayType)
{
if (convertedToTypeSymbol is not IArrayTypeSymbol)
if (convertedToTypeSymbol is not IArrayTypeSymbol &&
// Make sure we aren't just assigning it to a value type such as ReadOnlySpan
!convertedToTypeSymbol.IsValueType)
{
if (visitedTypes.Contains(arrayType))
{
Expand Down
23 changes: 16 additions & 7 deletions src/Perf/IIDOptimizer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,28 @@ private static int GuidPatch(string targetAssembly, string outputDirectory, IEnu
var winRTRuntimeAssembly = ResolveWinRTRuntime(targetAssemblyDefinition, resolver);
if (winRTRuntimeAssembly is null)
{
Console.WriteLine("Failed to resolve WinRT.Runtime.dll.");
return -1;
}

var guidPatcher = new GuidPatcher(winRTRuntimeAssembly, targetAssemblyDefinition);

int numPatches = guidPatcher.ProcessAssembly();
int numPatches = guidPatcher.ProcessAssembly();
Console.WriteLine($"{numPatches} IID calculations/fetches patched");

guidPatcher.SaveAssembly(outputDirectory);

Console.WriteLine($"Saved patched .dll to {outputDirectory}");
Console.WriteLine($"{numPatches} IID calculations/fetches patched");
return 0;
// Only write assembly if we actually patched anything.
// Otherwise we would just write a type we use as part of our implementation
// when it is actually not needed.
if (numPatches > 0)
{
guidPatcher.SaveAssembly(outputDirectory);
Console.WriteLine($"Saved patched .dll to {outputDirectory}");
return 0;
}
else
{
// Exit code is checked by caller to copy patched file over.
return -1;
}
}
catch (AssemblyResolutionException e)
{
Expand Down

0 comments on commit 6257088

Please sign in to comment.