Do not rely on descriptors in KTypeParameterImpl.equals/hashCode

Descriptors are cached via weak references in moduleByClassLoader.kt and
can be garbage-collected at any point. So relying on identity of
descriptors in KTypeParameterImpl is dangerous because the same type
parameter can be represented by different descriptors. For example, the
test equalsOnFunctionParameters.kt was flaky before this change because
of this issue, and that could be reproduced by running it a few hundred
times in the same process.

Instead, use the type parameter's container (which is either KClass or
KCallable) and name, in equals/hashCode. KClass and KCallable already
have equals/hashCode independent of descriptors, so this works in case
the descriptor is invalidated.
This commit is contained in:
Alexander Udalov
2020-05-27 15:54:06 +02:00
parent d25f9dee62
commit 55f384cb04
14 changed files with 279 additions and 53 deletions
@@ -27778,6 +27778,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/typeParametersEqualsHashCode.kt");
}
@TestMetadata("typeParametersEqualsWithClearCaches.kt")
public void testTypeParametersEqualsWithClearCaches() throws Exception {
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/typeParametersEqualsWithClearCaches.kt");
}
@TestMetadata("typeParametersToString.kt")
public void testTypeParametersToString() throws Exception {
runTest("compiler/testData/codegen/box/reflection/methodsFromAny/typeParametersToString.kt");
@@ -28664,6 +28669,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/typeParameters/declarationSiteVariance.kt");
}
@TestMetadata("innerGenericParameter.kt")
public void testInnerGenericParameter() throws Exception {
runTest("compiler/testData/codegen/box/reflection/typeParameters/innerGenericParameter.kt");
}
@TestMetadata("javaGenericTypeConstructor.kt")
public void testJavaGenericTypeConstructor() throws Exception {
runTest("compiler/testData/codegen/box/reflection/typeParameters/javaGenericTypeConstructor.kt");
}
@TestMetadata("typeParametersAndNames.kt")
public void testTypeParametersAndNames() throws Exception {
runTest("compiler/testData/codegen/box/reflection/typeParameters/typeParametersAndNames.kt");