[LL] Run LLFirExpectActualMatchingTargetResolver only for KMP projects
Review: https://jetbrains.team/p/kt/reviews/13244 Motivation: Performance. When I fix KT-59887 in later commits, I will make actual-to-expect resolve to work not only for actual declarations. Considering that LLFirExpectActualMatcherLazyResolver worked even for non-KMP projects that might be a potential performance regression FirExpectActualMatcherProcessor in the compiler does the same thing (it checks for MultiPlatformProjects before running the transformer)
This commit is contained in:
+13
-5
@@ -8,10 +8,12 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveTarget
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkExpectForActualIsResolved
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.FirElementWithResolveState
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.mpp.FirExpectActualMatcherTransformer
|
||||
@@ -29,8 +31,12 @@ internal object LLFirExpectActualMatcherLazyResolver : LLFirLazyResolver(FirReso
|
||||
}
|
||||
|
||||
override fun phaseSpecificCheckIsResolved(target: FirElementWithResolveState) {
|
||||
if (target !is FirMemberDeclaration || !target.canHaveExpectCounterPart()) return
|
||||
checkExpectForActualIsResolved(target)
|
||||
if (target.moduleData.session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects) &&
|
||||
target is FirMemberDeclaration &&
|
||||
target.canHaveExpectCounterPart()
|
||||
) {
|
||||
checkExpectForActualIsResolved(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +46,8 @@ private class LLFirExpectActualMatchingTargetResolver(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
) : LLFirTargetResolver(target, lockProvider, FirResolvePhase.EXPECT_ACTUAL_MATCHING) {
|
||||
private val enabled = session.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)
|
||||
|
||||
private val transformer = object : FirExpectActualMatcherTransformer(session, scopeSession) {
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): FirStatement {
|
||||
transformMemberDeclaration(regularClass)
|
||||
@@ -48,9 +56,9 @@ private class LLFirExpectActualMatchingTargetResolver(
|
||||
}
|
||||
|
||||
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
|
||||
if (target !is FirMemberDeclaration) return
|
||||
if (!target.canHaveExpectCounterPart()) return
|
||||
transformer.transformMemberDeclaration(target)
|
||||
if (enabled && target is FirMemberDeclaration && target.canHaveExpectCounterPart()) {
|
||||
transformer.transformMemberDeclaration(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -10,6 +10,6 @@ FILE: [ResolvedTo(IMPORTS)] expectAndActualInTheSameFile.kt
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun main(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? expect [ResolvedTo(RAW_FIR)] fun f(): R|kotlin/Unit|
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun test(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] [ExpectForActualAttributeKey={}] fun f(): R|kotlin/Unit| {
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] fun f(): R|kotlin/Unit| {
|
||||
<Unresolved name: println>#(String(Hello))
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
EXPECT_ACTUAL_MATCHING:
|
||||
FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
public final actual [ResolvedTo(EXPECT_ACTUAL_MATCHING)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(EXPECT_ACTUAL_MATCHING)] class Actual : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
@@ -184,7 +184,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
CONTRACTS:
|
||||
FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
public final actual [ResolvedTo(CONTRACTS)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(CONTRACTS)] class Actual : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
@@ -207,7 +207,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
IMPLICIT_TYPES_BODY_RESOLVE:
|
||||
FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
public final actual [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] class Actual : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
@@ -230,7 +230,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
ANNOTATION_ARGUMENTS:
|
||||
FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
public final actual [ResolvedTo(ANNOTATION_ARGUMENTS)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(ANNOTATION_ARGUMENTS)] class Actual : R|kotlin/Any| {
|
||||
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
@@ -253,7 +253,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
BODY_RESOLVE:
|
||||
FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] class Actual : R|kotlin/Any| {
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
@@ -276,7 +276,7 @@ FILE: [ResolvedTo(IMPORTS)] actual.kt
|
||||
|
||||
FILE RAW TO BODY:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] actual.kt
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] [ExpectForActualAttributeKey={}] class Actual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] class Actual : R|kotlin/Any| {
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Actual] constructor(): R|Actual| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
@@ -287,7 +287,7 @@ FILE: [ResolvedTo(BODY_RESOLVE)] actual.kt
|
||||
public final [ResolvedTo(BODY_RESOLVE)] val a: R|kotlin/Int| = Int(1)
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Actual] get(): R|kotlin/Int|
|
||||
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] [ExpectForActualAttributeKey={}] class NestedActual : R|kotlin/Any| {
|
||||
public final actual [ResolvedTo(BODY_RESOLVE)] class NestedActual : R|kotlin/Any| {
|
||||
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=NestedActual] constructor(): R|Actual.NestedActual| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user