[FE1.0] Optimize search of expect class member in annotation checker

In the following scenario, when we search corresponding expect member
for actual `A.B`, we can skip checking compatibility of `B` scope.
```
class A {
  class B {
    fun foo() {}
  }
}
actual typealias AImpl = A
```

This is because:

1. Annotation checker runs no matter if found expect class is compatible
or not.
2. Class always has at most one corresponding `expect` class (unlike for
functions, which may have several overrides), so we are sure that we
found the right member.

^KT-60668
^KT-60936
This commit is contained in:
Roman Efremov
2023-08-17 16:16:27 +02:00
committed by Space Team
parent f1ea6545eb
commit b57940a59b
13 changed files with 102 additions and 11 deletions
@@ -687,6 +687,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/annotationMatching")
@TestDataPath("$PROJECT_ROOT")
public class AnnotationMatching {
@Test
@TestMetadata("actualInnerClassMissingMember.kt")
public void testActualInnerClassMissingMember() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/actualInnerClassMissingMember.kt");
}
@Test
public void testAllFilesPresentInAnnotationMatching() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/annotationMatching"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
@@ -687,6 +687,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
@TestMetadata("compiler/testData/diagnostics/tests/multiplatform/annotationMatching")
@TestDataPath("$PROJECT_ROOT")
public class AnnotationMatching {
@Test
@TestMetadata("actualInnerClassMissingMember.kt")
public void testActualInnerClassMissingMember() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/actualInnerClassMissingMember.kt");
}
@Test
public void testAllFilesPresentInAnnotationMatching() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/annotationMatching"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), TargetBackend.JVM_IR, true);
@@ -469,6 +469,7 @@ class FirExpectActualMatchingContextImpl private constructor(
expectClass: RegularClassSymbolMarker,
actualClass: RegularClassSymbolMarker,
actualMember: DeclarationSymbolMarker,
checkClassScopesCompatibility: Boolean,
): Map<FirBasedSymbol<*>, ExpectActualCompatibility<*>> {
val mapping = actualClass.asSymbol().fir.memberExpectForActual
return mapping?.get(actualMember to expectClass) ?: emptyMap()
@@ -90,7 +90,12 @@ object FirExpectActualResolver {
is FirClassLikeSymbol<*> -> {
val expectClassSymbol = useSiteSession.dependenciesSymbolProvider
.getClassLikeSymbolByClassId(actualSymbol.classId) as? FirRegularClassSymbol ?: return null
val compatibility = AbstractExpectActualCompatibilityChecker.getClassifiersCompatibility(expectClassSymbol, actualSymbol, context)
val compatibility = AbstractExpectActualCompatibilityChecker.getClassifiersCompatibility(
expectClassSymbol,
actualSymbol,
checkClassScopesCompatibility = true,
context
)
mapOf(compatibility to listOf(expectClassSymbol))
}
else -> null