forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ILLink: fix TypeProxy implementation of equality (dotnet#106990)
The equality check needs to determine whether two TypeProxy instances represent the same type. The check was incorrect when two different object instances were allocated to represent the same generic instantiated type. ILCompiler doesn't have this problem because it uses a cache to ensure that the same object instance represents a given instantiated generic type. Discovered while investigating dotnet#106215, see more context at dotnet#106215 (comment). The new testcase also uncovered an issue in the analyzer that was fixed in dotnet#106909.
- Loading branch information
1 parent
c1fcaa0
commit 8a5d981
Showing
14 changed files
with
115 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
17 changes: 17 additions & 0 deletions
17
src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/GenericsTests.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace ILLink.RoslynAnalyzer.Tests | ||
{ | ||
public sealed partial class GenericsTests : LinkerTestBase | ||
{ | ||
protected override string TestSuiteName => "Generics"; | ||
|
||
[Fact] | ||
public Task InstantiatedGenericEquality () | ||
{ | ||
return RunTest (); | ||
} | ||
} | ||
} |
This file contains 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
51 changes: 51 additions & 0 deletions
51
src/tools/illink/test/Mono.Linker.Tests.Cases/Generics/InstantiatedGenericEquality.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Helpers; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.Generics | ||
{ | ||
[ExpectedNoWarnings] | ||
class InstantiatedGenericEquality | ||
{ | ||
public static void Main () | ||
{ | ||
GenericReturnType.Test (); | ||
} | ||
|
||
class GenericReturnType | ||
{ | ||
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] | ||
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | ||
class ReturnType<T> | ||
{ | ||
[Kept] | ||
public void Method () { } | ||
} | ||
|
||
[Kept] | ||
static ReturnType<T> GetGenericReturnType<T> () => default; | ||
|
||
// Regression test for an issue where ILLink's representation of a generic instantiated type | ||
// was using reference equality. The test uses a lambda to ensure that it goes through the | ||
// interprocedural analysis code path that merges patterns and relies on a correct implementation | ||
// of equality. | ||
[Kept] | ||
public static void Test () | ||
{ | ||
var instance = GetGenericReturnType<int> (); | ||
|
||
var lambda = | ||
() => { | ||
var type = instance.GetType (); | ||
type.GetMethod ("Method"); | ||
}; | ||
|
||
lambda (); | ||
} | ||
} | ||
} | ||
} |