[FIR] Enable asserts for not building AST tree in lazy mode
Make interface delegate expressions lazy
This commit is contained in:
+22
@@ -183,6 +183,20 @@ internal object FirLazyBodiesCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateLazyBodiesForField(designation: FirDesignation) {
|
||||
val field = designation.target as FirField
|
||||
require(field.initializer is FirLazyExpression)
|
||||
val newField = RawFirNonLocalDeclarationBuilder.buildWithFunctionSymbolRebind(
|
||||
session = field.moduleData.session,
|
||||
scopeProvider = field.moduleData.session.kotlinScopeProvider,
|
||||
designation = designation,
|
||||
rootNonLocalDeclaration = designation.path.last().psi as KtClassOrObject,
|
||||
) as FirField
|
||||
field.apply {
|
||||
replaceInitializer(newField.initializer)
|
||||
}
|
||||
}
|
||||
|
||||
fun needCalculatingLazyBodyForConstructor(firConstructor: FirConstructor): Boolean =
|
||||
needCalculatingLazyBodyForFunction(firConstructor) || firConstructor.delegatedConstructor is FirLazyDelegatedConstructorCall
|
||||
|
||||
@@ -301,6 +315,14 @@ private object FirLazyBodiesCalculatorTransformer : FirTransformer<PersistentLis
|
||||
return element
|
||||
}
|
||||
|
||||
override fun transformField(field: FirField, data: PersistentList<FirRegularClass>): FirStatement {
|
||||
if (field.initializer is FirLazyExpression) {
|
||||
val designation = FirDesignation(data, field)
|
||||
FirLazyBodiesCalculator.calculateLazyBodiesForField(designation)
|
||||
}
|
||||
return field
|
||||
}
|
||||
|
||||
override fun transformSimpleFunction(
|
||||
simpleFunction: FirSimpleFunction,
|
||||
data: PersistentList<FirRegularClass>
|
||||
|
||||
+21
-4
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
@@ -276,6 +277,22 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
val selfType = classOrObject.toDelegatedSelfType(typeParameters, owner.symbol)
|
||||
return enumEntry.toFirEnumEntry(selfType, ownerClassHasDefaultConstructor)
|
||||
}
|
||||
|
||||
fun processField(classOrObject: KtClassOrObject, originalDeclaration: FirField): FirField? {
|
||||
var index = 0
|
||||
classOrObject.superTypeListEntries.forEach { superTypeListEntry ->
|
||||
if (superTypeListEntry is KtDelegatedSuperTypeEntry) {
|
||||
val expectedName = NameUtils.delegateFieldName(index)
|
||||
if (originalDeclaration.name == expectedName) {
|
||||
return buildFieldForSupertypeDelegate(
|
||||
superTypeListEntry, superTypeListEntry.typeReference.toFirOrErrorType(), index
|
||||
)
|
||||
}
|
||||
index++
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveNext(iterator: Iterator<FirDeclaration>, containingClass: FirRegularClass?): FirDeclaration {
|
||||
@@ -296,10 +313,10 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
||||
}
|
||||
}
|
||||
is KtClassOrObject -> {
|
||||
if (originalDeclaration is FirConstructor) {
|
||||
visitor.processPrimaryConstructor(declarationToBuild, null)
|
||||
} else {
|
||||
visitor.convertElement(declarationToBuild)
|
||||
when {
|
||||
originalDeclaration is FirConstructor -> visitor.processPrimaryConstructor(declarationToBuild, null)
|
||||
originalDeclaration is FirField -> visitor.processField(declarationToBuild, originalDeclaration)
|
||||
else -> visitor.convertElement(declarationToBuild)
|
||||
}
|
||||
}
|
||||
else -> visitor.convertElement(declarationToBuild)
|
||||
|
||||
@@ -16,7 +16,7 @@ FILE: [ResolvedTo(RAW_FIR)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Foo = prop#
|
||||
private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Foo = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -40,7 +40,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Foo = prop#
|
||||
private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Foo = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -64,7 +64,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] field $$delegate_0: Foo = prop#
|
||||
private final [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] field $$delegate_0: Foo = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -88,7 +88,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(COMPANION_GENERATION)] field $$delegate_0: Foo = prop#
|
||||
private final [ResolvedTo(COMPANION_GENERATION)] field $$delegate_0: Foo = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -112,7 +112,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(SUPER_TYPES)] field $$delegate_0: Foo = prop#
|
||||
private final [ResolvedTo(SUPER_TYPES)] field $$delegate_0: Foo = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -136,7 +136,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(TYPES)] field $$delegate_0: R|one/Foo| = prop#
|
||||
private final [ResolvedTo(TYPES)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
|
||||
|
||||
public? final? [ResolvedTo(RAW_FIR)] fun baz([ResolvedTo(RAW_FIR)] s: String): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -160,7 +160,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(STATUS)] field $$delegate_0: R|one/Foo| = prop#
|
||||
private final [ResolvedTo(STATUS)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
|
||||
|
||||
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -184,7 +184,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] field $$delegate_0: R|one/Foo| = prop#
|
||||
private final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
|
||||
|
||||
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
@@ -208,7 +208,7 @@ FILE: [ResolvedTo(IMPORTS)] delegatedField.kt
|
||||
LAZY_super<<implicit>>
|
||||
}
|
||||
|
||||
private final [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] field $$delegate_0: R|one/Foo| = prop#
|
||||
private final [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] field $$delegate_0: R|one/Foo| = LAZY_EXPRESSION
|
||||
|
||||
public final [ResolvedTo(STATUS)] fun baz([ResolvedTo(STATUS)] s: R|kotlin/String|): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user