[FE] Preserve legacy contract description calls in bodies
^KT-55231 Fixed ^KTIJ-21012 Fixed
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.contracts
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.contracts.description.ConeUnresolvedEffect
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirResolvedContractDescription : FirContractDescription() {
|
||||
abstract override val source: KtSourceElement?
|
||||
abstract val effects: List<FirEffectDeclaration>
|
||||
abstract val unresolvedEffects: List<FirStatement>
|
||||
abstract val unresolvedEffects: List<ConeUnresolvedEffect>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitResolvedContractDescription(this, data)
|
||||
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.contracts.description.ConeUnresolvedEffect
|
||||
import org.jetbrains.kotlin.fir.contracts.impl.FirResolvedContractDescriptionImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
class FirResolvedContractDescriptionBuilder {
|
||||
var source: KtSourceElement? = null
|
||||
val effects: MutableList<FirEffectDeclaration> = mutableListOf()
|
||||
val unresolvedEffects: MutableList<FirStatement> = mutableListOf()
|
||||
val unresolvedEffects: MutableList<ConeUnresolvedEffect> = mutableListOf()
|
||||
|
||||
fun build(): FirResolvedContractDescription {
|
||||
return FirResolvedContractDescriptionImpl(
|
||||
|
||||
+2
-4
@@ -10,7 +10,7 @@ package org.jetbrains.kotlin.fir.contracts.impl
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration
|
||||
import org.jetbrains.kotlin.fir.contracts.FirResolvedContractDescription
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.contracts.description.ConeUnresolvedEffect
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
@@ -21,16 +21,14 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
internal class FirResolvedContractDescriptionImpl(
|
||||
override val source: KtSourceElement?,
|
||||
override val effects: MutableList<FirEffectDeclaration>,
|
||||
override val unresolvedEffects: MutableList<FirStatement>,
|
||||
override val unresolvedEffects: MutableList<ConeUnresolvedEffect>,
|
||||
) : FirResolvedContractDescription() {
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
effects.forEach { it.accept(visitor, data) }
|
||||
unresolvedEffects.forEach { it.accept(visitor, data) }
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirResolvedContractDescriptionImpl {
|
||||
effects.transformInplace(transformer, data)
|
||||
unresolvedEffects.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* 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.fir.contracts.description
|
||||
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
|
||||
class ConeUnresolvedEffect(val statement: FirStatement)
|
||||
@@ -104,13 +104,14 @@ fun <D> FirBlock.transformStatementsIndexed(transformer: FirTransformer<D>, data
|
||||
return this
|
||||
}
|
||||
|
||||
fun FirBlock.replaceFirstStatement(statement: FirStatement): FirStatement {
|
||||
fun <T : FirStatement> FirBlock.replaceFirstStatement(factory: (T) -> FirStatement): T {
|
||||
require(this is FirBlockImpl) {
|
||||
"replaceFirstStatement should not be called for ${this::class.simpleName}"
|
||||
}
|
||||
val existed = statements[0]
|
||||
statements[0] = statement
|
||||
return existed
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val existing = statements[0] as T
|
||||
statements[0] = factory(existing)
|
||||
return existing
|
||||
}
|
||||
|
||||
fun FirExpression.unwrapArgument(): FirExpression = (this as? FirWrappedArgumentExpression)?.expression ?: this
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.fir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fakeElement
|
||||
import org.jetbrains.kotlin.fir.MutableOrEmptyList
|
||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.fir.visitors.transformInplace
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
|
||||
class FirContractCallBlock(var call: FirFunctionCall) : FirBlock() {
|
||||
override val source: KtSourceElement?
|
||||
get() = call.source?.fakeElement(KtFakeSourceElementKind.ContractBlock)
|
||||
|
||||
override val statements: List<FirStatement>
|
||||
get() = listOf(call)
|
||||
|
||||
override var annotations: MutableOrEmptyList<FirAnnotation> = MutableOrEmptyList.empty()
|
||||
override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null)
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
call.accept(visitor, data)
|
||||
typeRef.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirContractCallBlock {
|
||||
transformStatements(transformer, data)
|
||||
transformOtherChildren(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
|
||||
typeRef = newTypeRef
|
||||
}
|
||||
|
||||
override fun <D> transformStatements(transformer: FirTransformer<D>, data: D): FirBlock {
|
||||
call = call.transformSingle(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformOtherChildren(transformer: FirTransformer<D>, data: D): FirBlock {
|
||||
typeRef = typeRef.transformSingle(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
|
||||
annotations = newAnnotations.toMutableOrEmpty()
|
||||
}
|
||||
|
||||
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirBlock {
|
||||
annotations.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -726,7 +726,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
|
||||
resolvedContractDescription.configure {
|
||||
+fieldList("effects", effectDeclaration)
|
||||
+fieldList("unresolvedEffects", statement)
|
||||
+fieldList("unresolvedEffects", coneUnresolvedEffect)
|
||||
}
|
||||
|
||||
legacyRawContractDescription.configure {
|
||||
|
||||
@@ -80,6 +80,7 @@ val coneEffectDeclarationType = type("fir.contracts.description", "ConeEffectDec
|
||||
val emptyContractDescriptionType = generatedType("contracts.impl", "FirEmptyContractDescription")
|
||||
val coneDiagnosticType = generatedType("diagnostics", "ConeDiagnostic")
|
||||
val coneStubDiagnosticType = generatedType("diagnostics", "ConeStubDiagnostic")
|
||||
val coneUnresolvedEffect = type("fir.contracts.description", "ConeUnresolvedEffect")
|
||||
|
||||
val dslBuilderAnnotationType = generatedType("builder", "FirBuilderDsl")
|
||||
val firImplementationDetailType = generatedType("FirImplementationDetail")
|
||||
|
||||
Reference in New Issue
Block a user