[LL API] Extract expect actual matching into separate phase

This commit is contained in:
Dmitriy Novozhilov
2022-04-18 11:13:26 +04:00
committed by teamcity
parent d66748d011
commit 9d4d55b3ce
21 changed files with 334 additions and 3 deletions
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDeclarationDesignationWithFile
import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator
import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.ResolveTreeBuilder
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirLazyTransformer.Companion.updatePhaseDeep
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.ensurePhase
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.transformers.mpp.FirExpectActualMatcherTransformer
internal class LLFirDesignatedExpectActualMatcherTransformer(
private val designation: FirDeclarationDesignationWithFile,
session: FirSession,
scopeSession: ScopeSession,
) : LLFirLazyTransformer, FirExpectActualMatcherTransformer(session, scopeSession) {
private val declarationTransformer = LLFirDeclarationTransformer(designation)
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): FirStatement {
return declarationTransformer.transformDeclarationContent(this, regularClass, data) {
super.transformRegularClass(regularClass, data) as FirDeclaration
} as FirStatement
}
override fun transformFile(file: FirFile, data: Nothing?): FirFile {
return declarationTransformer.transformDeclarationContent(this, file, data) {
super.transformFile(file, data)
} as FirFile
}
override fun transformDeclaration(phaseRunner: LLFirPhaseRunner) {
if (designation.declaration.resolvePhase >= FirResolvePhase.EXPECT_ACTUAL_MATCHING) return
designation.declaration.ensurePhase(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE)
FirLazyBodiesCalculator.calculateLazyBodiesInside(designation)
ResolveTreeBuilder.resolvePhase(designation.declaration, FirResolvePhase.EXPECT_ACTUAL_MATCHING) {
phaseRunner.runPhaseWithCustomResolve(FirResolvePhase.EXPECT_ACTUAL_MATCHING) {
designation.firFile.transform<FirFile, Nothing?>(this, null)
}
}
declarationTransformer.ensureDesignationPassed()
updatePhaseDeep(designation.declaration, FirResolvePhase.EXPECT_ACTUAL_MATCHING)
ensureResolved(designation.declaration)
ensureResolvedDeep(designation.declaration)
}
override fun ensureResolved(declaration: FirDeclaration) {
when (declaration) {
is FirSimpleFunction, is FirConstructor, is FirAnonymousInitializer ->
declaration.ensurePhase(FirResolvePhase.EXPECT_ACTUAL_MATCHING)
is FirProperty -> {
declaration.ensurePhase(FirResolvePhase.EXPECT_ACTUAL_MATCHING)
}
is FirClass, is FirTypeAlias, is FirEnumEntry, is FirField -> Unit
else -> error("Unexpected type: ${declaration::class.simpleName}")
}
}
}
@@ -75,6 +75,11 @@ internal object LazyTransformerFactory {
towerDataContextCollector,
firProviderInterceptor,
)
FirResolvePhase.EXPECT_ACTUAL_MATCHING -> LLFirDesignatedExpectActualMatcherTransformer(
designation,
designation.firFile.moduleData.session,
scopeSession
)
else -> error("Non-lazy phase $phase")
}
}
}
@@ -351,6 +351,42 @@ FILE: annotationParameters.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: annotationParameters.kt
public final [STATUS] enum class X : R|kotlin/Enum<X>| {
private [STATUS] [ContainingClassKey=X] constructor(): R|X| {
super<R|kotlin/Enum<X>|>()
}
public final static [STATUS] [ContainingClassKey=X] enum entry A: R|X|
public final static [BODY_RESOLVE] [ContainingClassKey=X] fun values(): R|kotlin/Array<X>| {
}
public final static [BODY_RESOLVE] [ContainingClassKey=X] fun valueOf([BODY_RESOLVE] value: R|kotlin/String|): R|X| {
}
}
public? final? [COMPILER_REQUIRED_ANNOTATIONS] annotation class Anno : R|kotlin/Annotation| {
public? [COMPILER_REQUIRED_ANNOTATIONS] [ContainingClassKey=Anno] constructor([RAW_FIR] [CorrespondingProperty=/Anno.args] args: A.X): R|Anno| {
super<R|kotlin/Any|>()
}
public? final? [COMPILER_REQUIRED_ANNOTATIONS] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
}
public final [STATUS] class B : R|kotlin/Any| {
public [STATUS] [ContainingClassKey=B] constructor(): R|B| {
super<R|kotlin/Any|>()
}
@R|Anno|(Q|X|.R|/X.A|) public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
}
@R|Anno|(X#.A#) public final [STATUS] fun foo(): R|kotlin/Unit| { LAZY_BLOCK }
}
BODY_RESOLVE:
FILE: annotationParameters.kt
public final [STATUS] enum class X : R|kotlin/Enum<X>| {
@@ -51,6 +51,12 @@ FILE: annotations.kt
@R|kotlin/Suppress|(String(2)) public final [IMPLICIT_TYPES_BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
}
EXPECT_ACTUAL_MATCHING:
FILE: annotations.kt
@FILE:Suppress(String(1))
@R|kotlin/Suppress|(String(2)) public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
}
BODY_RESOLVE:
FILE: annotations.kt
@FILE:Suppress(String(1))
@@ -183,6 +183,26 @@ FILE: classMembers.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: classMembers.kt
public final [STATUS] class A : R|kotlin/Any| {
public [STATUS] [ContainingClassKey=A] constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(functionWithLazyBody#())
}
public final [STATUS] val x: R|kotlin/Int| = LAZY_EXPRESSION
[STATUS] [ContainingClassKey=A] public get(): R|kotlin/Int| { LAZY_BLOCK }
public final [STATUS] fun receive([RAW_FIR] value: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
public final [STATUS] fun functionWithLazyBody(): R|kotlin/String| { LAZY_BLOCK }
}
BODY_RESOLVE:
FILE: classMembers.kt
public final [STATUS] class A : R|kotlin/Any| {
@@ -299,6 +299,40 @@ FILE: delegates.kt
D|/variableWithImplicitType|.setValue#(Null(null), ::R|/variableWithImplicitType|, R|<local>/variableWithImplicitType|)
}
EXPECT_ACTUAL_MATCHING:
FILE: delegates.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(valueWithExplicitType#)
receive#(valueWithImplicitType#)
variableWithExplicitType# = IntegerLiteral(10)
variableWithImplicitType# = IntegerLiteral(10)
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: Int): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] val delegate: <implicit> = LAZY_EXPRESSION
[TYPES] public? get(): <implicit>
public? final? [RAW_FIR] val valueWithExplicitType: Intby LAZY_EXPRESSION
[RAW_FIR] public? get(): <implicit> {
^ D|/valueWithExplicitType|.getValue#(Null(null), ::R|/valueWithExplicitType|)
}
public? final? [RAW_FIR] val valueWithImplicitType: <implicit>by LAZY_EXPRESSION
[RAW_FIR] public? get(): <implicit> {
^ D|/valueWithImplicitType|.getValue#(Null(null), ::R|/valueWithImplicitType|)
}
public? final? [RAW_FIR] var variableWithExplicitType: Intby LAZY_EXPRESSION
[RAW_FIR] public? get(): <implicit> {
^ D|/variableWithExplicitType|.getValue#(Null(null), ::R|/variableWithExplicitType|)
}
[RAW_FIR] public? set([RAW_FIR] <set-?>: <implicit>): R|kotlin/Unit| {
D|/variableWithExplicitType|.setValue#(Null(null), ::R|/variableWithExplicitType|, R|<local>/variableWithExplicitType|)
}
public? final? [RAW_FIR] var variableWithImplicitType: <implicit>by LAZY_EXPRESSION
[RAW_FIR] public? get(): <implicit> {
^ D|/variableWithImplicitType|.getValue#(Null(null), ::R|/variableWithImplicitType|)
}
[RAW_FIR] public? set([RAW_FIR] <set-?>: <implicit>): R|kotlin/Unit| {
D|/variableWithImplicitType|.setValue#(Null(null), ::R|/variableWithImplicitType|, R|<local>/variableWithImplicitType|)
}
BODY_RESOLVE:
FILE: delegates.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -63,6 +63,14 @@ FILE: functionWithParameter.kt
^resolveMe Q|kotlin/Unit|
}
EXPECT_ACTUAL_MATCHING:
FILE: functionWithParameter.kt
public? final? [COMPILER_REQUIRED_ANNOTATIONS] interface I : R|kotlin/Any| {
}
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe([RAW_FIR] param: R|I|): R|kotlin/Unit| {
^resolveMe Q|kotlin/Unit|
}
BODY_RESOLVE:
FILE: functionWithParameter.kt
public? final? [COMPILER_REQUIRED_ANNOTATIONS] interface I : R|kotlin/Any| {
@@ -133,6 +133,21 @@ FILE: parameterOfNonLocalSetter.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: parameterOfNonLocalSetter.kt
public final [STATUS] class X : R|kotlin/Any| {
public [STATUS] [ContainingClassKey=X] constructor(): R|X| {
super<R|kotlin/Any|>()
}
public final [EXPECT_ACTUAL_MATCHING] var x: R|kotlin/Int| = IntegerLiteral(2)
[BODY_RESOLVE] [ContainingClassKey=X] public get(): R|kotlin/Int|
[EXPECT_ACTUAL_MATCHING] [ContainingClassKey=X] public set([RAW_FIR] resolveMe: R|kotlin/Int|): R|kotlin/Unit| {
^ Unit#
}
}
BODY_RESOLVE:
FILE: parameterOfNonLocalSetter.kt
public final [STATUS] class X : R|kotlin/Any| {
@@ -73,6 +73,15 @@ FILE: propertyWithGetter.kt
public? final? [RAW_FIR] val withGetter: Int
[RAW_FIR] public? get(): Int { LAZY_BLOCK }
EXPECT_ACTUAL_MATCHING:
FILE: propertyWithGetter.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(withGetter#)
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: Int): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] val withGetter: Int
[RAW_FIR] public? get(): Int { LAZY_BLOCK }
BODY_RESOLVE:
FILE: propertyWithGetter.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -85,6 +85,17 @@ FILE: propertyWithGetterAndSetter.kt
[RAW_FIR] public? get(): Int { LAZY_BLOCK }
[RAW_FIR] public? set([RAW_FIR] value: Int): R|kotlin/Unit| { LAZY_BLOCK }
EXPECT_ACTUAL_MATCHING:
FILE: propertyWithGetterAndSetter.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(withGetterAndSetter#)
withGetterAndSetter# = IntegerLiteral(123)
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: Int): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] var withGetterAndSetter: Int = LAZY_EXPRESSION
[RAW_FIR] public? get(): Int { LAZY_BLOCK }
[RAW_FIR] public? set([RAW_FIR] value: Int): R|kotlin/Unit| { LAZY_BLOCK }
BODY_RESOLVE:
FILE: propertyWithGetterAndSetter.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -63,6 +63,14 @@ FILE: propertyWithInitializer.kt
public? final? [RAW_FIR] val property: Int = LAZY_EXPRESSION
[TYPES] public? get(): Int
EXPECT_ACTUAL_MATCHING:
FILE: propertyWithInitializer.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(property#)
}
public? final? [RAW_FIR] val property: Int = LAZY_EXPRESSION
[TYPES] public? get(): Int
BODY_RESOLVE:
FILE: propertyWithInitializer.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -123,6 +123,20 @@ FILE: secondaryConstructor.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: secondaryConstructor.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(A#(IntegerLiteral(42)))
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: A): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] class A : R|kotlin/Any| {
public? [RAW_FIR] [ContainingClassKey=A] constructor([RAW_FIR] x: Int): R|A| {
super<R|kotlin/Any|>()
[RAW_FIR] lval a: <implicit> = x#
}
}
BODY_RESOLVE:
FILE: secondaryConstructor.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -209,6 +209,27 @@ FILE: superTypes.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: superTypes.kt
public open [TYPES] class A : R|kotlin/Any| {
public [TYPES] [ContainingClassKey=A] constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public? open [RAW_FIR] class B : A {
public? [RAW_FIR] [ContainingClassKey=B] constructor(): R|B| {
super<A>()
}
}
public open [EXPECT_ACTUAL_MATCHING] class resolveMe : R|A| {
public [EXPECT_ACTUAL_MATCHING] [ContainingClassKey=resolveMe] constructor(): R|resolveMe| {
super<R|A|>()
}
}
BODY_RESOLVE:
FILE: superTypes.kt
public open [STATUS] class A : R|kotlin/Any| {
@@ -269,6 +269,33 @@ FILE: superTypesLoop.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: superTypesLoop.kt
public open [EXPECT_ACTUAL_MATCHING] class resolveMe : R|C| {
public [EXPECT_ACTUAL_MATCHING] [ContainingClassKey=resolveMe] constructor(): R|resolveMe| {
super<R|C|>()
}
}
public? open [COMPILER_REQUIRED_ANNOTATIONS] class A : <ERROR TYPE REF: Loop in supertype: /A -> /B> {
public? [COMPILER_REQUIRED_ANNOTATIONS] [ContainingClassKey=A] constructor(): R|A| {
super<B>()
}
}
public? open [COMPILER_REQUIRED_ANNOTATIONS] class B : <ERROR TYPE REF: Loop in supertype: /B -> /C> {
public? [COMPILER_REQUIRED_ANNOTATIONS] [ContainingClassKey=B] constructor(): R|B| {
super<C>()
}
}
public open [TYPES] class C : <ERROR TYPE REF: Loop in supertype: /C -> /A> {
public [TYPES] [ContainingClassKey=C] constructor(): R|C| {
super<R|A|>()
}
}
BODY_RESOLVE:
FILE: superTypesLoop.kt
public open [BODY_RESOLVE] class resolveMe : R|C| {
@@ -63,6 +63,14 @@ FILE: topLevelFunctions.kt
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): String { LAZY_BLOCK }
EXPECT_ACTUAL_MATCHING:
FILE: topLevelFunctions.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(functionWithLazyBody#())
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): String { LAZY_BLOCK }
BODY_RESOLVE:
FILE: topLevelFunctions.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -63,6 +63,14 @@ FILE: topLevelFunctionsWithExpressionBodyAndExplicitType.kt
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): String { LAZY_BLOCK }
EXPECT_ACTUAL_MATCHING:
FILE: topLevelFunctionsWithExpressionBodyAndExplicitType.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(functionWithLazyBody#())
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): String { LAZY_BLOCK }
BODY_RESOLVE:
FILE: topLevelFunctionsWithExpressionBodyAndExplicitType.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -63,6 +63,14 @@ FILE: topLevelFunctionsWithImplicitType.kt
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): <implicit> { LAZY_BLOCK }
EXPECT_ACTUAL_MATCHING:
FILE: topLevelFunctionsWithImplicitType.kt
public final [EXPECT_ACTUAL_MATCHING] fun resolveMe(): R|kotlin/Unit| {
receive#(functionWithLazyBody#())
}
public? final? [RAW_FIR] fun receive([RAW_FIR] value: String): R|kotlin/Unit| { LAZY_BLOCK }
public? final? [RAW_FIR] fun functionWithLazyBody(): <implicit> { LAZY_BLOCK }
BODY_RESOLVE:
FILE: topLevelFunctionsWithImplicitType.kt
public final [BODY_RESOLVE] fun resolveMe(): R|kotlin/Unit| {
@@ -111,6 +111,18 @@ FILE: typeParameterOfNonLocalFunction.kt
}
EXPECT_ACTUAL_MATCHING:
FILE: typeParameterOfNonLocalFunction.kt
public final [STATUS] class X : R|kotlin/Any| {
public [STATUS] [ContainingClassKey=X] constructor(): R|X| {
super<R|kotlin/Any|>()
}
public final [EXPECT_ACTUAL_MATCHING] fun <resolveMe> ddd(): R|kotlin/Unit| {
}
}
BODY_RESOLVE:
FILE: typeParameterOfNonLocalFunction.kt
public final [STATUS] class X : R|kotlin/Any| {
@@ -41,6 +41,11 @@ FILE: typeParameterOfTopFunction.kt
public final [IMPLICIT_TYPES_BODY_RESOLVE] fun <resolveMe> ddd(): R|kotlin/Unit| {
}
EXPECT_ACTUAL_MATCHING:
FILE: typeParameterOfTopFunction.kt
public final [EXPECT_ACTUAL_MATCHING] fun <resolveMe> ddd(): R|kotlin/Unit| {
}
BODY_RESOLVE:
FILE: typeParameterOfTopFunction.kt
public final [BODY_RESOLVE] fun <resolveMe> ddd(): R|kotlin/Unit| {
@@ -63,6 +63,14 @@ FILE: typeParameterOfTopSetter.kt
^ Unit#
}
EXPECT_ACTUAL_MATCHING:
FILE: typeParameterOfTopSetter.kt
public final [EXPECT_ACTUAL_MATCHING] var x: R|kotlin/Int| = IntegerLiteral(2)
[BODY_RESOLVE] public get(): R|kotlin/Int|
[EXPECT_ACTUAL_MATCHING] public set([RAW_FIR] resolveMe: R|kotlin/Int|): R|kotlin/Unit| {
^ Unit#
}
BODY_RESOLVE:
FILE: typeParameterOfTopSetter.kt
public final [BODY_RESOLVE] var x: R|kotlin/Int| = Int(2)
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.transformers.FirAbstractTreeTransformer
import org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
import org.jetbrains.kotlin.resolve.multiplatform.compatible
class FirExpectActualMatcherProcessor(
@@ -32,7 +31,7 @@ class FirExpectActualMatcherProcessor(
}
}
class FirExpectActualMatcherTransformer(
open class FirExpectActualMatcherTransformer(
override val session: FirSession,
private val scopeSession: ScopeSession
) : FirAbstractTreeTransformer<Nothing?>(FirResolvePhase.EXPECT_ACTUAL_MATCHING) {