FIR: Get rid of old FirImplicitTypeBodyResolveTransformerAdapter
This commit is contained in:
-1
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirBodyResolveTransformerAdapter
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitTypeBodyResolveTransformerAdapter
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitTypeBodyResolveTransformerAdapter2
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
|
||||
|
||||
+8
-71
@@ -5,92 +5,29 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDesignatedBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirComputingImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirErrorTypeRefImpl
|
||||
|
||||
interface ReturnTypeCalculator {
|
||||
fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef
|
||||
}
|
||||
|
||||
class ReturnTypeCalculatorWithJump(val session: FirSession, val scopeSession: ScopeSession) :
|
||||
ReturnTypeCalculator {
|
||||
|
||||
private fun cycleErrorType(declaration: FirTypedDeclaration): FirResolvedTypeRef? {
|
||||
if (declaration.returnTypeRef is FirComputingImplicitTypeRef) {
|
||||
declaration.transformReturnTypeRef(
|
||||
TransformImplicitType,
|
||||
FirErrorTypeRefImpl(null, FirSimpleDiagnostic("cycle", DiagnosticKind.RecursionInImplicitTypes))
|
||||
)
|
||||
return declaration.returnTypeRef as FirResolvedTypeRef
|
||||
}
|
||||
return null
|
||||
}
|
||||
class ReturnTypeCalculatorForFullBodyResolve : ReturnTypeCalculator {
|
||||
|
||||
override fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef {
|
||||
|
||||
if (declaration is FirValueParameter && declaration.returnTypeRef is FirImplicitTypeRef) {
|
||||
// TODO?
|
||||
declaration.transformReturnTypeRef(
|
||||
TransformImplicitType,
|
||||
FirErrorTypeRefImpl(
|
||||
null,
|
||||
FirSimpleDiagnostic("Unsupported: implicit VP type")
|
||||
)
|
||||
)
|
||||
}
|
||||
val returnTypeRef = declaration.returnTypeRef
|
||||
if (returnTypeRef is FirResolvedTypeRef) return returnTypeRef
|
||||
cycleErrorType(declaration)?.let { return it }
|
||||
require(declaration is FirCallableMemberDeclaration<*>) { "${declaration::class}: ${declaration.render()}" }
|
||||
|
||||
|
||||
val symbol = declaration.symbol as FirCallableSymbol<*>
|
||||
val id = symbol.callableId
|
||||
|
||||
val provider = session.firProvider
|
||||
|
||||
val file = provider.getFirCallableContainerFile(symbol)
|
||||
|
||||
val outerClasses = generateSequence(id.classId) { classId ->
|
||||
classId.outerClassId
|
||||
}.mapTo(mutableListOf()) { provider.getFirClassifierByFqName(it) }
|
||||
|
||||
if (file == null || outerClasses.any { it == null }) {
|
||||
return FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Cannot calculate return type (local class/object?)", DiagnosticKind.InferenceError))
|
||||
}
|
||||
|
||||
declaration.transformReturnTypeRef(
|
||||
TransformImplicitType,
|
||||
FirComputingImplicitTypeRef
|
||||
return FirErrorTypeRefImpl(
|
||||
null,
|
||||
FirSimpleDiagnostic(
|
||||
"Cannot calculate return type during full-body resolution (local class/object?): ${declaration.render()}",
|
||||
DiagnosticKind.InferenceError
|
||||
)
|
||||
)
|
||||
|
||||
val transformer = FirDesignatedBodyResolveTransformer(
|
||||
(listOf(file) + outerClasses.filterNotNull().asReversed() + listOf(declaration)).iterator(),
|
||||
file.session,
|
||||
scopeSession
|
||||
)
|
||||
|
||||
file.transform<FirElement, ResolutionMode>(transformer, ResolutionMode.ContextDependent)
|
||||
|
||||
|
||||
val newReturnTypeRef = declaration.returnTypeRef
|
||||
cycleErrorType(declaration)?.let { return it }
|
||||
require(newReturnTypeRef is FirResolvedTypeRef) { declaration.render() }
|
||||
return newReturnTypeRef
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorWithJump
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.scopes.addImportingScopes
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
@@ -29,7 +29,7 @@ open class FirBodyResolveTransformer(
|
||||
phase: FirResolvePhase,
|
||||
override var implicitTypeOnly: Boolean,
|
||||
scopeSession: ScopeSession,
|
||||
val returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorWithJump(session, scopeSession)
|
||||
val returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorForFullBodyResolve()
|
||||
) : FirAbstractBodyResolveTransformer(phase) {
|
||||
private var packageFqName = FqName.ROOT
|
||||
|
||||
|
||||
+1
-22
@@ -43,27 +43,6 @@ class FirDesignatedBodyResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("It is temp", level = DeprecationLevel.WARNING, replaceWith = ReplaceWith("TODO(\"что-то нормальное\")"))
|
||||
class FirImplicitTypeBodyResolveTransformerAdapter : FirTransformer<Nothing?>() {
|
||||
private val scopeSession = ScopeSession()
|
||||
|
||||
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
||||
return element.compose()
|
||||
}
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||
val transformer = FirBodyResolveTransformer(
|
||||
file.session,
|
||||
phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE,
|
||||
implicitTypeOnly = true,
|
||||
scopeSession = scopeSession
|
||||
)
|
||||
return file.transform(transformer, ResolutionMode.ContextIndependent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Deprecated("It is temp", level = DeprecationLevel.WARNING, replaceWith = ReplaceWith("TODO(\"что-то нормальное\")"))
|
||||
class FirBodyResolveTransformerAdapter : FirTransformer<Nothing?>() {
|
||||
private val scopeSession = ScopeSession()
|
||||
@@ -81,4 +60,4 @@ class FirBodyResolveTransformerAdapter : FirTransformer<Nothing?>() {
|
||||
)
|
||||
return file.transform(transformer, ResolutionMode.ContextIndependent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-12
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.extractLambdaInfoFromFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirStatusResolveTransformer.Companion.resolveStatus
|
||||
@@ -25,7 +24,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirLocalScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirComputingImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirErrorTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
@@ -92,9 +90,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
return@withScopeCleanup property.compose()
|
||||
}
|
||||
dataFlowAnalyzer.enterProperty(property)
|
||||
if (returnTypeRef is FirImplicitTypeRef) {
|
||||
property.transformReturnTypeRef(StoreType, FirComputingImplicitTypeRef)
|
||||
}
|
||||
withFullBodyResolve {
|
||||
withScopeCleanup(localScopes) {
|
||||
localScopes.addIfNotNull(primaryConstructorParametersScope)
|
||||
@@ -167,9 +162,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
transformFunction(accessor, withExpectedType(enhancedTypeRef))
|
||||
}
|
||||
val returnTypeRef = accessor.returnTypeRef
|
||||
if (returnTypeRef is FirImplicitTypeRef && enhancedTypeRef !is FirResolvedTypeRef) {
|
||||
accessor.transformReturnTypeRef(StoreType, FirComputingImplicitTypeRef)
|
||||
}
|
||||
val expectedReturnTypeRef = if (enhancedTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) {
|
||||
enhancedTypeRef
|
||||
} else {
|
||||
@@ -318,10 +310,6 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer)
|
||||
}
|
||||
|
||||
withFullBodyResolve {
|
||||
if (returnTypeRef is FirImplicitTypeRef) {
|
||||
simpleFunction.transformReturnTypeRef(StoreType, FirComputingImplicitTypeRef)
|
||||
}
|
||||
|
||||
val receiverTypeRef = simpleFunction.receiverTypeRef
|
||||
if (receiverTypeRef != null) {
|
||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef.coneTypeUnsafe()) {
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ChainedSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorWithJump
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
@@ -82,7 +82,7 @@ class FirClassSubstitutionScope(
|
||||
}
|
||||
|
||||
private val typeCalculator =
|
||||
(scopeSession.returnTypeCalculator as ReturnTypeCalculator?) ?: ReturnTypeCalculatorWithJump(session, scopeSession)
|
||||
(scopeSession.returnTypeCalculator as ReturnTypeCalculator?) ?: ReturnTypeCalculatorForFullBodyResolve()
|
||||
|
||||
private fun ConeKotlinType.substitute(): ConeKotlinType? {
|
||||
return substitutor.substituteOrNull(this)
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.types.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
|
||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
|
||||
/*
|
||||
* This file was generated automatically
|
||||
* DO NOT MODIFY IT MANUALLY
|
||||
*/
|
||||
|
||||
object FirComputingImplicitTypeRef : FirImplicitTypeRef(), FirAbstractAnnotatedElement {
|
||||
override val source: FirSourceElement? get() = null
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotations.forEach { it.accept(visitor, data) }
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirComputingImplicitTypeRef {
|
||||
annotations.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
}
|
||||
-5
@@ -514,11 +514,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
defaultEmptyList("annotations")
|
||||
}
|
||||
|
||||
impl(implicitTypeRef, "FirComputingImplicitTypeRef") {
|
||||
kind = Object
|
||||
defaultNull("source", withGetter = true)
|
||||
}
|
||||
|
||||
impl(reference, "FirStubReference") {
|
||||
default("source") {
|
||||
value = "null"
|
||||
|
||||
Reference in New Issue
Block a user