FIR resolution: introduce FirResolvePhase & FirAbstractPhaseTransformer
The phase determines which transformers were already applied to declaration. The transformer controls current resolve phase in phasedFir and performs additional resolve if necessary.
This commit is contained in:
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractMemberDeclaration
|
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractMemberDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableClass
|
import org.jetbrains.kotlin.fir.declarations.impl.FirModifiableClass
|
||||||
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
|
import org.jetbrains.kotlin.fir.java.JavaTypeParameterStack
|
||||||
@@ -39,6 +40,7 @@ class FirJavaClass internal constructor(
|
|||||||
status.isCompanion = false
|
status.isCompanion = false
|
||||||
status.isData = false
|
status.isData = false
|
||||||
status.isInline = false
|
status.isInline = false
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
override val superTypeRefs = mutableListOf<FirTypeRef>()
|
override val superTypeRefs = mutableListOf<FirTypeRef>()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractCallableMember
|
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractCallableMember
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirConstructorImpl.Companion.NAME
|
import org.jetbrains.kotlin.fir.declarations.impl.FirConstructorImpl.Companion.NAME
|
||||||
@@ -38,6 +39,7 @@ class FirJavaConstructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
override val delegatedConstructor: FirDelegatedConstructorCall?
|
override val delegatedConstructor: FirDelegatedConstructorCall?
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirField
|
import org.jetbrains.kotlin.fir.declarations.FirField
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractCallableMember
|
import org.jetbrains.kotlin.fir.declarations.impl.FirAbstractCallableMember
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
||||||
@@ -34,6 +35,7 @@ class FirJavaField(
|
|||||||
), FirField {
|
), FirField {
|
||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
override val delegate: FirExpression?
|
override val delegate: FirExpression?
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.java.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirMemberFunctionImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirMemberFunctionImpl
|
||||||
import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef
|
import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
@@ -32,5 +33,6 @@ class FirJavaMethod(
|
|||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
status.isStatic = isStatic
|
status.isStatic = isStatic
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+6
-1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.java.declarations
|
package org.jetbrains.kotlin.fir.java.declarations
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
|
||||||
import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef
|
import org.jetbrains.kotlin.fir.java.types.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -18,4 +19,8 @@ class FirJavaValueParameter(
|
|||||||
) : FirValueParameterImpl(
|
) : FirValueParameterImpl(
|
||||||
session, psi = null, name = name, returnTypeRef = returnTypeRef,
|
session, psi = null, name = name, returnTypeRef = returnTypeRef,
|
||||||
defaultValue = null, isCrossinline = false, isNoinline = false, isVararg = isVararg
|
defaultValue = null, isCrossinline = false, isNoinline = false, isVararg = isVararg
|
||||||
)
|
) {
|
||||||
|
init {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -175,6 +175,7 @@ class JavaClassEnhancementScope(
|
|||||||
this.name, newTypeRef,
|
this.name, newTypeRef,
|
||||||
defaultValue ?: newDefaultValue, isCrossinline, isNoinline, isVararg
|
defaultValue ?: newDefaultValue, isCrossinline, isNoinline, isVararg
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
annotations += valueParameter.annotations
|
annotations += valueParameter.annotations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,6 +198,7 @@ class JavaClassEnhancementScope(
|
|||||||
newReceiverTypeRef, newReturnTypeRef
|
newReceiverTypeRef, newReturnTypeRef
|
||||||
)
|
)
|
||||||
}.apply {
|
}.apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
this.valueParameters += newValueParameters
|
this.valueParameters += newValueParameters
|
||||||
this.typeParameters += firMethod.typeParameters
|
this.typeParameters += firMethod.typeParameters
|
||||||
}
|
}
|
||||||
@@ -207,6 +209,7 @@ class JavaClassEnhancementScope(
|
|||||||
else FirAccessorSymbol(callableId = propertyId!!, accessorId = methodId),
|
else FirAccessorSymbol(callableId = propertyId!!, accessorId = methodId),
|
||||||
name, newReceiverTypeRef, newReturnTypeRef
|
name, newReceiverTypeRef, newReturnTypeRef
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
this.valueParameters += newValueParameters
|
this.valueParameters += newValueParameters
|
||||||
this.typeParameters += firMethod.typeParameters
|
this.typeParameters += firMethod.typeParameters
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -16,6 +16,7 @@ import com.intellij.util.PathUtil
|
|||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
|
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirWrappedDelegateExpressionImpl
|
import org.jetbrains.kotlin.fir.expressions.impl.FirWrappedDelegateExpressionImpl
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
@@ -69,6 +70,9 @@ abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase(
|
|||||||
RawFirBuilder(object : FirSessionBase(null) {}, stubMode).buildFirFile(this)
|
RawFirBuilder(object : FirSessionBase(null) {}, stubMode).buildFirFile(this)
|
||||||
|
|
||||||
private fun FirElement.traverseChildren(result: MutableSet<FirElement> = hashSetOf()): MutableSet<FirElement> {
|
private fun FirElement.traverseChildren(result: MutableSet<FirElement> = hashSetOf()): MutableSet<FirElement> {
|
||||||
|
if (this is FirResolvePhase) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
if (!result.add(this)) {
|
if (!result.add(this)) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.deserialization
|
package org.jetbrains.kotlin.fir.deserialization
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirClassImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirClassImpl
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirEnumEntryImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirEnumEntryImpl
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl
|
||||||
@@ -45,7 +46,7 @@ fun deserializeClassToSymbol(
|
|||||||
Flags.IS_DATA.get(classProto.flags),
|
Flags.IS_DATA.get(classProto.flags),
|
||||||
Flags.IS_INLINE_CLASS.get(classProto.flags)
|
Flags.IS_INLINE_CLASS.get(classProto.flags)
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
val context =
|
val context =
|
||||||
parentContext?.childContext(
|
parentContext?.childContext(
|
||||||
classProto.typeParameterList,
|
classProto.typeParameterList,
|
||||||
@@ -94,6 +95,7 @@ fun deserializeClassToSymbol(
|
|||||||
|
|
||||||
val symbol = FirClassSymbol(enumEntryId)
|
val symbol = FirClassSymbol(enumEntryId)
|
||||||
FirEnumEntryImpl(session, null, symbol, enumEntryId.shortClassName).apply {
|
FirEnumEntryImpl(session, null, symbol, enumEntryId.shortClassName).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
superTypeRefs += FirResolvedTypeRefImpl(
|
superTypeRefs += FirResolvedTypeRefImpl(
|
||||||
null,
|
null,
|
||||||
ConeClassTypeImpl(ConeClassLikeLookupTagImpl(classId), emptyArray(), false),
|
ConeClassTypeImpl(ConeClassLikeLookupTagImpl(classId), emptyArray(), false),
|
||||||
|
|||||||
+4
@@ -141,6 +141,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
|||||||
emptyList() /* TODO */
|
emptyList() /* TODO */
|
||||||
)
|
)
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,6 +175,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
|||||||
initializer = null,
|
initializer = null,
|
||||||
delegate = null
|
delegate = null
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
||||||
annotations += c.annotationDeserializer.loadPropertyAnnotations(proto, local.nameResolver)
|
annotations += c.annotationDeserializer.loadPropertyAnnotations(proto, local.nameResolver)
|
||||||
getter = FirDefaultPropertyGetter(c.session, null, returnTypeRef, ProtoEnumFlags.visibility(Flags.VISIBILITY.get(getterFlags)))
|
getter = FirDefaultPropertyGetter(c.session, null, returnTypeRef, ProtoEnumFlags.visibility(Flags.VISIBILITY.get(getterFlags)))
|
||||||
@@ -218,6 +220,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
|||||||
receiverTypeRef = proto.receiverType(local.typeTable)?.toTypeRef(local),
|
receiverTypeRef = proto.receiverType(local.typeTable)?.toTypeRef(local),
|
||||||
returnTypeRef = proto.returnType(local.typeTable).toTypeRef(local)
|
returnTypeRef = proto.returnType(local.typeTable).toTypeRef(local)
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
||||||
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
||||||
annotations += local.annotationDeserializer.loadFunctionAnnotations(proto, local.nameResolver)
|
annotations += local.annotationDeserializer.loadFunctionAnnotations(proto, local.nameResolver)
|
||||||
@@ -269,6 +272,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
}.apply {
|
}.apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
this.typeParameters += typeParameters
|
this.typeParameters += typeParameters
|
||||||
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
||||||
annotations += local.annotationDeserializer.loadConstructorAnnotations(proto, local.nameResolver)
|
annotations += local.annotationDeserializer.loadConstructorAnnotations(proto, local.nameResolver)
|
||||||
|
|||||||
-12
@@ -41,16 +41,4 @@ abstract class AbstractFirSymbolProvider : FirSymbolProvider() {
|
|||||||
calculated.first
|
calculated.first
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <D> transformTopLevelClasses(transformer: FirTransformer<D>, data: D) {
|
|
||||||
val symbols = classCache.values.filterNotNullTo(mutableListOf())
|
|
||||||
// TODO: do something with new symbols which can be found during transformation of another symbols
|
|
||||||
for (symbol in symbols) {
|
|
||||||
if (symbol !is FirClassSymbol) continue
|
|
||||||
if (symbol.classId.relativeClassName.parent().isRoot) {
|
|
||||||
// Launch for top-level classes only
|
|
||||||
symbol.fir.transform<FirElement, D>(transformer, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||||
import org.jetbrains.kotlin.fir.service
|
import org.jetbrains.kotlin.fir.service
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -30,6 +31,9 @@ abstract class FirProvider : FirSymbolProvider() {
|
|||||||
|
|
||||||
abstract fun getFirClassifierContainerFile(fqName: ClassId): FirFile
|
abstract fun getFirClassifierContainerFile(fqName: ClassId): FirFile
|
||||||
|
|
||||||
|
fun getFirClassifierContainerFile(symbol: ConeClassLikeSymbol): FirFile =
|
||||||
|
getFirClassifierContainerFile(symbol.classId)
|
||||||
|
|
||||||
abstract fun getFirCallableContainerFile(symbol: ConeCallableSymbol): FirFile?
|
abstract fun getFirCallableContainerFile(symbol: ConeCallableSymbol): FirFile?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ private fun BodyResolveComponents.typeFromSymbol(symbol: ConeSymbol, makeNullabl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is ConeClassifierSymbol -> {
|
is ConeClassifierSymbol -> {
|
||||||
val fir = (symbol as? FirBasedSymbol<*>)?.fir
|
val fir = (symbol as? AbstractFirBasedSymbol<*>)?.fir
|
||||||
// TODO: unhack
|
// TODO: unhack
|
||||||
if (fir is FirEnumEntry) {
|
if (fir is FirEnumEntry) {
|
||||||
(fir.superTypeRefs.firstOrNull() as? FirResolvedTypeRef) ?: FirErrorTypeRefImpl(
|
(fir.superTypeRefs.firstOrNull() as? FirResolvedTypeRef) ?: FirErrorTypeRefImpl(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.FirFile
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
import org.jetbrains.kotlin.fir.types.FirTypeProjection
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
@@ -44,7 +44,7 @@ enum class CandidateApplicability {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Candidate(
|
class Candidate(
|
||||||
val symbol: FirBasedSymbol<*>,
|
val symbol: AbstractFirBasedSymbol<*>,
|
||||||
val dispatchReceiverValue: ClassDispatchReceiverValue?,
|
val dispatchReceiverValue: ClassDispatchReceiverValue?,
|
||||||
val implicitExtensionReceiverValue: ImplicitReceiverValue?,
|
val implicitExtensionReceiverValue: ImplicitReceiverValue?,
|
||||||
val explicitReceiverKind: ExplicitReceiverKind,
|
val explicitReceiverKind: ExplicitReceiverKind,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.calls
|
package org.jetbrains.kotlin.fir.resolve.calls
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
@@ -28,7 +29,7 @@ class CandidateFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun createCandidate(
|
fun createCandidate(
|
||||||
symbol: FirBasedSymbol<*>,
|
symbol: AbstractFirBasedSymbol<*>,
|
||||||
dispatchReceiverValue: ClassDispatchReceiverValue?,
|
dispatchReceiverValue: ClassDispatchReceiverValue?,
|
||||||
implicitExtensionReceiverValue: ImplicitReceiverValue?,
|
implicitExtensionReceiverValue: ImplicitReceiverValue?,
|
||||||
explicitReceiverKind: ExplicitReceiverKind
|
explicitReceiverKind: ExplicitReceiverKind
|
||||||
|
|||||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference
|
import org.jetbrains.kotlin.fir.references.FirSimpleNamedReference
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
@@ -15,6 +16,6 @@ class FirNamedReferenceWithCandidate(
|
|||||||
name: Name,
|
name: Name,
|
||||||
val candidate: Candidate
|
val candidate: Candidate
|
||||||
) : FirSimpleNamedReference(psi, name) {
|
) : FirSimpleNamedReference(psi, name) {
|
||||||
override val candidateSymbol: ConeSymbol
|
override val candidateSymbol: AbstractFirBasedSymbol<*>
|
||||||
get() = candidate.symbol
|
get() = candidate.symbol
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,7 @@ class FirSyntheticPropertiesScope(
|
|||||||
initializer = null,
|
initializer = null,
|
||||||
delegate = null
|
delegate = null
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = fir.resolvePhase
|
||||||
getter = FirDefaultPropertyGetter(this@FirSyntheticPropertiesScope.session, null, returnTypeRef, fir.visibility)
|
getter = FirDefaultPropertyGetter(this@FirSyntheticPropertiesScope.session, null, returnTypeRef, fir.visibility)
|
||||||
setter = FirDefaultPropertySetter(this@FirSyntheticPropertiesScope.session, null, returnTypeRef, fir.visibility)
|
setter = FirDefaultPropertySetter(this@FirSyntheticPropertiesScope.session, null, returnTypeRef, fir.visibility)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.resolve.constructClassType
|
import org.jetbrains.kotlin.fir.resolve.constructClassType
|
||||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassType
|
import org.jetbrains.kotlin.fir.types.ConeClassType
|
||||||
@@ -36,7 +36,7 @@ abstract class TowerDataConsumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class QualifiedReceiverTowerDataConsumer<T : FirBasedSymbol<*>>(
|
class QualifiedReceiverTowerDataConsumer<T : AbstractFirBasedSymbol<*>>(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
val name: Name,
|
val name: Name,
|
||||||
val token: TowerScopeLevel.Token<T>,
|
val token: TowerScopeLevel.Token<T>,
|
||||||
@@ -146,7 +146,7 @@ class AccumulatingTowerDataConsumer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExplicitReceiverTowerDataConsumer<T : FirBasedSymbol<*>>(
|
class ExplicitReceiverTowerDataConsumer<T : AbstractFirBasedSymbol<*>>(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
val name: Name,
|
val name: Name,
|
||||||
val token: TowerScopeLevel.Token<T>,
|
val token: TowerScopeLevel.Token<T>,
|
||||||
@@ -249,7 +249,7 @@ class ExplicitReceiverTowerDataConsumer<T : FirBasedSymbol<*>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoExplicitReceiverTowerDataConsumer<T : FirBasedSymbol<*>>(
|
class NoExplicitReceiverTowerDataConsumer<T : AbstractFirBasedSymbol<*>>(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
val name: Name,
|
val name: Name,
|
||||||
val token: TowerScopeLevel.Token<T>,
|
val token: TowerScopeLevel.Token<T>,
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
|||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirExplicitSimpleImportingScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirExplicitSimpleImportingScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.processClassifiersByNameWithAction
|
import org.jetbrains.kotlin.fir.scopes.processClassifiersByNameWithAction
|
||||||
import org.jetbrains.kotlin.fir.service
|
import org.jetbrains.kotlin.fir.service
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -33,14 +33,14 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
|
|||||||
|
|
||||||
interface TowerScopeLevel {
|
interface TowerScopeLevel {
|
||||||
|
|
||||||
sealed class Token<out T : FirBasedSymbol<*>> {
|
sealed class Token<out T : AbstractFirBasedSymbol<*>> {
|
||||||
object Properties : Token<FirPropertySymbol>()
|
object Properties : Token<FirPropertySymbol>()
|
||||||
|
|
||||||
object Functions : Token<FirFunctionSymbol<*>>()
|
object Functions : Token<FirFunctionSymbol<*>>()
|
||||||
object Objects : Token<FirBasedSymbol<*>>()
|
object Objects : Token<AbstractFirBasedSymbol<*>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : FirBasedSymbol<*>> processElementsByName(
|
fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
|
||||||
token: Token<T>,
|
token: Token<T>,
|
||||||
name: Name,
|
name: Name,
|
||||||
explicitReceiver: ExpressionReceiverValue?,
|
explicitReceiver: ExpressionReceiverValue?,
|
||||||
@@ -56,7 +56,7 @@ interface TowerScopeLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Empty : TowerScopeLevel {
|
object Empty : TowerScopeLevel {
|
||||||
override fun <T : FirBasedSymbol<*>> processElementsByName(
|
override fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
|
||||||
token: Token<T>,
|
token: Token<T>,
|
||||||
name: Name,
|
name: Name,
|
||||||
explicitReceiver: ExpressionReceiverValue?,
|
explicitReceiver: ExpressionReceiverValue?,
|
||||||
@@ -66,7 +66,7 @@ interface TowerScopeLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class SessionBasedTowerLevel(val session: FirSession) : TowerScopeLevel {
|
abstract class SessionBasedTowerLevel(val session: FirSession) : TowerScopeLevel {
|
||||||
protected fun FirBasedSymbol<*>.dispatchReceiverValue(): ClassDispatchReceiverValue? {
|
protected fun AbstractFirBasedSymbol<*>.dispatchReceiverValue(): ClassDispatchReceiverValue? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is FirNamedFunctionSymbol -> fir.dispatchReceiverValue(session)
|
is FirNamedFunctionSymbol -> fir.dispatchReceiverValue(session)
|
||||||
is FirClassSymbol -> ClassDispatchReceiverValue(fir.symbol)
|
is FirClassSymbol -> ClassDispatchReceiverValue(fir.symbol)
|
||||||
@@ -92,7 +92,7 @@ class MemberScopeTowerLevel(
|
|||||||
val implicitExtensionReceiver: ImplicitReceiverValue? = null,
|
val implicitExtensionReceiver: ImplicitReceiverValue? = null,
|
||||||
val scopeSession: ScopeSession
|
val scopeSession: ScopeSession
|
||||||
) : SessionBasedTowerLevel(session) {
|
) : SessionBasedTowerLevel(session) {
|
||||||
private fun <T : FirBasedSymbol<*>> processMembers(
|
private fun <T : AbstractFirBasedSymbol<*>> processMembers(
|
||||||
output: TowerScopeLevel.TowerScopeLevelProcessor<T>,
|
output: TowerScopeLevel.TowerScopeLevelProcessor<T>,
|
||||||
explicitExtensionReceiver: ExpressionReceiverValue?,
|
explicitExtensionReceiver: ExpressionReceiverValue?,
|
||||||
processScopeMembers: FirScope.(processor: (T) -> ProcessorAction) -> ProcessorAction
|
processScopeMembers: FirScope.(processor: (T) -> ProcessorAction) -> ProcessorAction
|
||||||
@@ -118,7 +118,7 @@ class MemberScopeTowerLevel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T : FirBasedSymbol<*>> processElementsByName(
|
override fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
|
||||||
token: TowerScopeLevel.Token<T>,
|
token: TowerScopeLevel.Token<T>,
|
||||||
name: Name,
|
name: Name,
|
||||||
explicitReceiver: ExpressionReceiverValue?,
|
explicitReceiver: ExpressionReceiverValue?,
|
||||||
@@ -151,7 +151,7 @@ class ScopeTowerLevel(
|
|||||||
val scope: FirScope,
|
val scope: FirScope,
|
||||||
val implicitExtensionReceiver: ImplicitReceiverValue? = null
|
val implicitExtensionReceiver: ImplicitReceiverValue? = null
|
||||||
) : SessionBasedTowerLevel(session) {
|
) : SessionBasedTowerLevel(session) {
|
||||||
override fun <T : FirBasedSymbol<*>> processElementsByName(
|
override fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
|
||||||
token: TowerScopeLevel.Token<T>,
|
token: TowerScopeLevel.Token<T>,
|
||||||
name: Name,
|
name: Name,
|
||||||
explicitReceiver: ExpressionReceiverValue?,
|
explicitReceiver: ExpressionReceiverValue?,
|
||||||
@@ -197,7 +197,7 @@ class ScopeTowerLevel(
|
|||||||
* Handles only statics and top-levels, DOES NOT handle objects/companions members
|
* Handles only statics and top-levels, DOES NOT handle objects/companions members
|
||||||
*/
|
*/
|
||||||
class QualifiedReceiverTowerLevel(session: FirSession) : SessionBasedTowerLevel(session) {
|
class QualifiedReceiverTowerLevel(session: FirSession) : SessionBasedTowerLevel(session) {
|
||||||
override fun <T : FirBasedSymbol<*>> processElementsByName(
|
override fun <T : AbstractFirBasedSymbol<*>> processElementsByName(
|
||||||
token: TowerScopeLevel.Token<T>,
|
token: TowerScopeLevel.Token<T>,
|
||||||
name: Name,
|
name: Name,
|
||||||
explicitReceiver: ExpressionReceiverValue?,
|
explicitReceiver: ExpressionReceiverValue?,
|
||||||
|
|||||||
+6
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
|||||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||||
import org.jetbrains.kotlin.fir.deserialization.FirBuiltinAnnotationDeserializer
|
import org.jetbrains.kotlin.fir.deserialization.FirBuiltinAnnotationDeserializer
|
||||||
import org.jetbrains.kotlin.fir.deserialization.FirDeserializationContext
|
import org.jetbrains.kotlin.fir.deserialization.FirDeserializationContext
|
||||||
@@ -96,7 +97,9 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider(
|
|||||||
}
|
}
|
||||||
return lookup.getOrPut(classId, { FirClassSymbol(classId) }) { symbol ->
|
return lookup.getOrPut(classId, { FirClassSymbol(classId) }) { symbol ->
|
||||||
if (shouldBeEnumEntry) {
|
if (shouldBeEnumEntry) {
|
||||||
FirEnumEntryImpl(session, null, symbol, classId.shortClassName)
|
FirEnumEntryImpl(session, null, symbol, classId.shortClassName).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val classData = classDataFinder.findClassData(classId)!!
|
val classData = classDataFinder.findClassData(classId)!!
|
||||||
val classProto = classData.classProto
|
val classProto = classData.classProto
|
||||||
@@ -180,6 +183,7 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider(
|
|||||||
isData = false,
|
isData = false,
|
||||||
isInline = false
|
isInline = false
|
||||||
).apply klass@{
|
).apply klass@{
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
typeParameters.addAll((1..arity).map {
|
typeParameters.addAll((1..arity).map {
|
||||||
FirTypeParameterImpl(
|
FirTypeParameterImpl(
|
||||||
this@FirLibrarySymbolProviderImpl.session,
|
this@FirLibrarySymbolProviderImpl.session,
|
||||||
@@ -227,6 +231,7 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
valueParameters += this@klass.typeParameters.dropLast(1).map { typeParameter ->
|
valueParameters += this@klass.typeParameters.dropLast(1).map { typeParameter ->
|
||||||
FirValueParameterImpl(
|
FirValueParameterImpl(
|
||||||
this@FirLibrarySymbolProviderImpl.session,
|
this@FirLibrarySymbolProviderImpl.session,
|
||||||
|
|||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 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.resolve.transformers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
|
import org.jetbrains.kotlin.fir.render
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
|
||||||
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
|
||||||
|
abstract class FirAbstractPhaseTransformer<D>(
|
||||||
|
protected val transformerPhase: FirResolvePhase
|
||||||
|
) : FirTransformer<D>() {
|
||||||
|
|
||||||
|
abstract val session: FirSession
|
||||||
|
|
||||||
|
init {
|
||||||
|
assert(transformerPhase != FirResolvePhase.RAW_FIR) {
|
||||||
|
"Raw FIR building shouldn't be done in phase transformer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val <D> AbstractFirBasedSymbol<D>.phasedFir: D where D : FirDeclaration, D : FirSymbolOwner<D>
|
||||||
|
get() {
|
||||||
|
val result = this.fir
|
||||||
|
val requiredPhase = transformerPhase.prev
|
||||||
|
val availablePhase = result.resolvePhase
|
||||||
|
if (availablePhase < requiredPhase) {
|
||||||
|
var resolvePhase = availablePhase.next
|
||||||
|
val provider = FirProvider.getInstance(session)
|
||||||
|
val containingFile = when (this) {
|
||||||
|
is ConeCallableSymbol -> provider.getFirCallableContainerFile(this)
|
||||||
|
is ConeClassLikeSymbol -> provider.getFirClassifierContainerFile(this)
|
||||||
|
else -> null
|
||||||
|
} ?: throw AssertionError("Cannot get container file by symbol: $this (${result.render()})")
|
||||||
|
do {
|
||||||
|
val phaseTransformer = resolvePhase.createTransformerByPhase()
|
||||||
|
containingFile.transform<FirFile, Nothing?>(phaseTransformer, null)
|
||||||
|
resolvePhase = resolvePhase.next
|
||||||
|
} while (resolvePhase <= requiredPhase)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun transformDeclaration(declaration: FirDeclaration, data: D): CompositeTransformResult<FirDeclaration> {
|
||||||
|
declaration.resolvePhase = transformerPhase
|
||||||
|
|
||||||
|
return super.transformDeclaration(declaration, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -6,11 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
|
||||||
import org.jetbrains.kotlin.fir.visitors.compose
|
import org.jetbrains.kotlin.fir.visitors.compose
|
||||||
|
|
||||||
abstract class FirAbstractTreeTransformer : FirTransformer<Nothing?>() {
|
abstract class FirAbstractTreeTransformer(phase: FirResolvePhase) : FirAbstractPhaseTransformer<Nothing?>(phase) {
|
||||||
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return (element.transformChildren(this, data) as E).compose()
|
return (element.transformChildren(this, data) as E).compose()
|
||||||
|
|||||||
+5
-1
@@ -6,10 +6,14 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberTypeParameterScope
|
||||||
|
|
||||||
abstract class FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority: Boolean) : FirAbstractTreeTransformer() {
|
abstract class FirAbstractTreeTransformerWithSuperTypes(
|
||||||
|
phase: FirResolvePhase,
|
||||||
|
reversedScopePriority: Boolean
|
||||||
|
) : FirAbstractTreeTransformer(phase) {
|
||||||
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
|
protected val towerScope = FirCompositeScope(mutableListOf(), reversedPriority = reversedScopePriority)
|
||||||
|
|
||||||
protected inline fun <T> withScopeCleanup(crossinline l: () -> T): T {
|
protected inline fun <T> withScopeCleanup(crossinline l: () -> T): T {
|
||||||
|
|||||||
+14
-7
@@ -43,9 +43,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
|
|
||||||
open class FirBodyResolveTransformer(
|
open class FirBodyResolveTransformer(
|
||||||
final override val session: FirSession,
|
final override val session: FirSession,
|
||||||
|
phase: FirResolvePhase,
|
||||||
val implicitTypeOnly: Boolean,
|
val implicitTypeOnly: Boolean,
|
||||||
val scopeSession: ScopeSession = ScopeSession()
|
val scopeSession: ScopeSession = ScopeSession()
|
||||||
) : FirTransformer<Any?>(), BodyResolveComponents {
|
) : FirAbstractPhaseTransformer<Any?>(phase), BodyResolveComponents {
|
||||||
final override val returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorWithJump(session, scopeSession)
|
final override val returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorWithJump(session, scopeSession)
|
||||||
override val labels: SetMultimap<Name, ConeKotlinType> = LinkedHashMultimap.create()
|
override val labels: SetMultimap<Name, ConeKotlinType> = LinkedHashMultimap.create()
|
||||||
override val noExpectedType = FirImplicitTypeRefImpl(null)
|
override val noExpectedType = FirImplicitTypeRefImpl(null)
|
||||||
@@ -122,7 +123,10 @@ open class FirBodyResolveTransformer(
|
|||||||
|
|
||||||
override fun transformValueParameter(valueParameter: FirValueParameter, data: Any?): CompositeTransformResult<FirDeclaration> {
|
override fun transformValueParameter(valueParameter: FirValueParameter, data: Any?): CompositeTransformResult<FirDeclaration> {
|
||||||
localScopes.lastOrNull()?.storeDeclaration(valueParameter)
|
localScopes.lastOrNull()?.storeDeclaration(valueParameter)
|
||||||
if (valueParameter.returnTypeRef is FirImplicitTypeRef) return valueParameter.compose() // TODO
|
if (valueParameter.returnTypeRef is FirImplicitTypeRef) {
|
||||||
|
valueParameter.resolvePhase = transformerPhase
|
||||||
|
return valueParameter.compose() // TODO
|
||||||
|
}
|
||||||
return super.transformValueParameter(valueParameter, valueParameter.returnTypeRef)
|
return super.transformValueParameter(valueParameter, valueParameter.returnTypeRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +208,7 @@ open class FirBodyResolveTransformer(
|
|||||||
qualifiedAccessExpression.resultType = callee.superTypeRef
|
qualifiedAccessExpression.resultType = callee.superTypeRef
|
||||||
} else {
|
} else {
|
||||||
val superTypeRef = implicitReceiverStack.filterIsInstance<ImplicitDispatchReceiverValue>().lastOrNull()
|
val superTypeRef = implicitReceiverStack.filterIsInstance<ImplicitDispatchReceiverValue>().lastOrNull()
|
||||||
?.boundSymbol?.fir?.superTypeRefs?.firstOrNull()
|
?.boundSymbol?.phasedFir?.superTypeRefs?.firstOrNull()
|
||||||
?: FirErrorTypeRefImpl(qualifiedAccessExpression.psi, "No super type")
|
?: FirErrorTypeRefImpl(qualifiedAccessExpression.psi, "No super type")
|
||||||
qualifiedAccessExpression.resultType = superTypeRef
|
qualifiedAccessExpression.resultType = superTypeRef
|
||||||
callee.replaceSuperTypeRef(superTypeRef)
|
callee.replaceSuperTypeRef(superTypeRef)
|
||||||
@@ -641,6 +645,7 @@ open class FirBodyResolveTransformer(
|
|||||||
if (variable !is FirProperty) {
|
if (variable !is FirProperty) {
|
||||||
localScopes.lastOrNull()?.storeDeclaration(variable)
|
localScopes.lastOrNull()?.storeDeclaration(variable)
|
||||||
}
|
}
|
||||||
|
variable.resolvePhase = transformerPhase
|
||||||
return variable.compose()
|
return variable.compose()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,6 +669,7 @@ open class FirBodyResolveTransformer(
|
|||||||
property.transformAccessors()
|
property.transformAccessors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
property.resolvePhase = transformerPhase
|
||||||
property.compose()
|
property.compose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,7 +693,7 @@ open class FirBodyResolveTransformer(
|
|||||||
val symbol = symbolProvider.getClassLikeSymbolByFqName(classId)!!
|
val symbol = symbolProvider.getClassLikeSymbolByFqName(classId)!!
|
||||||
// TODO: Unify logic?
|
// TODO: Unify logic?
|
||||||
symbol.constructType(
|
symbol.constructType(
|
||||||
Array(symbol.fir.typeParameters.size) {
|
Array(symbol.phasedFir.typeParameters.size) {
|
||||||
ConeStarProjection
|
ConeStarProjection
|
||||||
},
|
},
|
||||||
isNullable = false
|
isNullable = false
|
||||||
@@ -773,7 +779,7 @@ private fun inferenceComponents(session: FirSession, returnTypeCalculator: Retur
|
|||||||
|
|
||||||
|
|
||||||
class FirDesignatedBodyResolveTransformer(val designation: Iterator<FirElement>, session: FirSession, scopeSession: ScopeSession) :
|
class FirDesignatedBodyResolveTransformer(val designation: Iterator<FirElement>, session: FirSession, scopeSession: ScopeSession) :
|
||||||
FirBodyResolveTransformer(session, implicitTypeOnly = true, scopeSession = scopeSession) {
|
FirBodyResolveTransformer(session, phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, implicitTypeOnly = true, scopeSession = scopeSession) {
|
||||||
|
|
||||||
override fun <E : FirElement> transformElement(element: E, data: Any?): CompositeTransformResult<E> {
|
override fun <E : FirElement> transformElement(element: E, data: Any?): CompositeTransformResult<E> {
|
||||||
if (designation.hasNext()) {
|
if (designation.hasNext()) {
|
||||||
@@ -792,7 +798,7 @@ class FirImplicitTypeBodyResolveTransformerAdapter : FirTransformer<Nothing?>()
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
val transformer = FirBodyResolveTransformer(file.fileSession, implicitTypeOnly = true)
|
val transformer = FirBodyResolveTransformer(file.fileSession, phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, implicitTypeOnly = true)
|
||||||
return file.transform(transformer, null)
|
return file.transform(transformer, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -805,7 +811,8 @@ class FirBodyResolveTransformerAdapter : FirTransformer<Nothing?>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
val transformer = FirBodyResolveTransformer(file.fileSession, implicitTypeOnly = false)
|
// Despite of real phase is EXPRESSIONS, we state IMPLICIT_TYPES here, because DECLARATIONS previous phase is OK for us
|
||||||
|
val transformer = FirBodyResolveTransformer(file.fileSession, phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, implicitTypeOnly = false)
|
||||||
return file.transform(transformer, null)
|
return file.transform(transformer, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -6,9 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||||
@@ -28,10 +26,10 @@ import org.jetbrains.kotlin.fir.visitors.compose
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
class FirCallCompletionResultsWriterTransformer(
|
class FirCallCompletionResultsWriterTransformer(
|
||||||
val session: FirSession,
|
override val session: FirSession,
|
||||||
private val finalSubstitutor: ConeSubstitutor,
|
private val finalSubstitutor: ConeSubstitutor,
|
||||||
private val typeCalculator: ReturnTypeCalculator
|
private val typeCalculator: ReturnTypeCalculator
|
||||||
) : FirAbstractTreeTransformer() {
|
) : FirAbstractTreeTransformer(phase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) {
|
||||||
|
|
||||||
override fun transformQualifiedAccessExpression(
|
override fun transformQualifiedAccessExpression(
|
||||||
qualifiedAccessExpression: FirQualifiedAccessExpression,
|
qualifiedAccessExpression: FirQualifiedAccessExpression,
|
||||||
@@ -41,7 +39,7 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
qualifiedAccessExpression.calleeReference as? FirNamedReferenceWithCandidate ?: return qualifiedAccessExpression.compose()
|
qualifiedAccessExpression.calleeReference as? FirNamedReferenceWithCandidate ?: return qualifiedAccessExpression.compose()
|
||||||
calleeReference.candidate.substitutor
|
calleeReference.candidate.substitutor
|
||||||
|
|
||||||
val typeRef = typeCalculator.tryCalculateReturnType(calleeReference.candidateSymbol.firUnsafe())
|
val typeRef = typeCalculator.tryCalculateReturnType(calleeReference.candidateSymbol.phasedFir as FirTypedDeclaration)
|
||||||
|
|
||||||
val initialType = calleeReference.candidate.substitutor.substituteOrNull(typeRef.type)
|
val initialType = calleeReference.candidate.substitutor.substituteOrNull(typeRef.type)
|
||||||
val finalType = finalSubstitutor.substituteOrNull(initialType)
|
val finalType = finalSubstitutor.substituteOrNull(initialType)
|
||||||
@@ -80,7 +78,7 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
val functionCall = functionCall.transformArguments(this, data) as FirFunctionCall
|
val functionCall = functionCall.transformArguments(this, data) as FirFunctionCall
|
||||||
|
|
||||||
val subCandidate = calleeReference.candidate
|
val subCandidate = calleeReference.candidate
|
||||||
val declaration = subCandidate.symbol.firUnsafe<FirCallableMemberDeclaration<*>>()
|
val declaration = subCandidate.symbol.phasedFir as FirCallableMemberDeclaration<*>
|
||||||
val newTypeParameters = declaration.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }
|
val newTypeParameters = declaration.typeParameters.map { ConeTypeParameterTypeImpl(it.symbol.toLookupTag(), false) }
|
||||||
.map { subCandidate.substitutor.substituteOrSelf(it) }
|
.map { subCandidate.substitutor.substituteOrSelf(it) }
|
||||||
.map { finalSubstitutor.substituteOrSelf(it) }
|
.map { finalSubstitutor.substituteOrSelf(it) }
|
||||||
|
|||||||
+3
-2
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirElement
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirImport
|
import org.jetbrains.kotlin.fir.declarations.FirImport
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedImportImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirResolvedImportImpl
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
import org.jetbrains.kotlin.fir.resolve.FirSymbolProvider
|
||||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
@@ -16,14 +17,14 @@ import org.jetbrains.kotlin.fir.visitors.compose
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
class FirImportResolveTransformer() : FirAbstractTreeTransformer() {
|
class FirImportResolveTransformer() : FirAbstractTreeTransformer(phase = FirResolvePhase.IMPORTS) {
|
||||||
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
||||||
return element.compose()
|
return element.compose()
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var symbolProvider: FirSymbolProvider
|
private lateinit var symbolProvider: FirSymbolProvider
|
||||||
|
|
||||||
private lateinit var session: FirSession
|
override lateinit var session: FirSession
|
||||||
|
|
||||||
constructor(session: FirSession) : this() {
|
constructor(session: FirSession) : this() {
|
||||||
this.session = session
|
this.session = session
|
||||||
|
|||||||
+3
-2
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.resolve.FirTypeResolver
|
import org.jetbrains.kotlin.fir.resolve.FirTypeResolver
|
||||||
@@ -20,8 +21,8 @@ import org.jetbrains.kotlin.fir.visitors.compose
|
|||||||
class FirSpecificTypeResolverTransformer(
|
class FirSpecificTypeResolverTransformer(
|
||||||
private val towerScope: FirScope,
|
private val towerScope: FirScope,
|
||||||
private val position: FirPosition,
|
private val position: FirPosition,
|
||||||
private val session: FirSession
|
override val session: FirSession
|
||||||
) : FirAbstractTreeTransformer() {
|
) : FirAbstractTreeTransformer(phase = FirResolvePhase.SUPER_TYPES) {
|
||||||
override fun transformTypeRef(typeRef: FirTypeRef, data: Nothing?): CompositeTransformResult<FirTypeRef> {
|
override fun transformTypeRef(typeRef: FirTypeRef, data: Nothing?): CompositeTransformResult<FirTypeRef> {
|
||||||
val typeResolver = FirTypeResolver.getInstance(session)
|
val typeResolver = FirTypeResolver.getInstance(session)
|
||||||
typeRef.transformChildren(FirSpecificTypeResolverTransformer(towerScope, FirPosition.OTHER, session), null)
|
typeRef.transformChildren(FirSpecificTypeResolverTransformer(towerScope, FirPosition.OTHER, session), null)
|
||||||
|
|||||||
+9
-1
@@ -9,12 +9,13 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
import org.jetbrains.kotlin.fir.visitors.compose
|
import org.jetbrains.kotlin.fir.visitors.compose
|
||||||
|
|
||||||
class FirStatusResolveTransformer : FirAbstractTreeTransformer() {
|
class FirStatusResolveTransformer : FirAbstractTreeTransformer(phase = FirResolvePhase.STATUS) {
|
||||||
private val declarationsWithStatuses = mutableListOf<FirDeclaration>()
|
private val declarationsWithStatuses = mutableListOf<FirDeclaration>()
|
||||||
|
|
||||||
private val classes = mutableListOf<FirRegularClass>()
|
private val classes = mutableListOf<FirRegularClass>()
|
||||||
@@ -58,6 +59,13 @@ class FirStatusResolveTransformer : FirAbstractTreeTransformer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override lateinit var session: FirSession
|
||||||
|
|
||||||
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
|
session = file.fileSession
|
||||||
|
return super.transformFile(file, data)
|
||||||
|
}
|
||||||
|
|
||||||
override fun transformDeclarationStatus(
|
override fun transformDeclarationStatus(
|
||||||
declarationStatus: FirDeclarationStatus,
|
declarationStatus: FirDeclarationStatus,
|
||||||
data: Nothing?
|
data: Nothing?
|
||||||
|
|||||||
+8
-7
@@ -23,14 +23,14 @@ import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
|||||||
import org.jetbrains.kotlin.fir.visitors.compose
|
import org.jetbrains.kotlin.fir.visitors.compose
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
|
||||||
class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
class FirSupertypeResolverTransformer : FirAbstractTreeTransformer(phase = FirResolvePhase.SUPER_TYPES) {
|
||||||
private lateinit var firSession: FirSession
|
override lateinit var session: FirSession
|
||||||
private val currentlyComputing: MutableSet<ClassId> = mutableSetOf()
|
private val currentlyComputing: MutableSet<ClassId> = mutableSetOf()
|
||||||
private val fullyComputed: MutableSet<ClassId> = mutableSetOf()
|
private val fullyComputed: MutableSet<ClassId> = mutableSetOf()
|
||||||
private lateinit var file: FirFile
|
private lateinit var file: FirFile
|
||||||
|
|
||||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
firSession = file.fileSession
|
session = file.fileSession
|
||||||
this.file = file
|
this.file = file
|
||||||
return super.transformFile(file, data)
|
return super.transformFile(file, data)
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,8 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
|||||||
|
|
||||||
|
|
||||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||||
return resolveSupertypesOrExpansions(typeAlias).compose()
|
val result = resolveSupertypesOrExpansions(typeAlias)
|
||||||
|
return result.compose()
|
||||||
}
|
}
|
||||||
|
|
||||||
// This and transformProperty functions are required to forbid supertype resolving for local classes
|
// This and transformProperty functions are required to forbid supertype resolving for local classes
|
||||||
@@ -64,20 +65,20 @@ class FirSupertypeResolverTransformer : FirAbstractTreeTransformer() {
|
|||||||
|
|
||||||
if (classId in fullyComputed) return classLikeDeclaration
|
if (classId in fullyComputed) return classLikeDeclaration
|
||||||
|
|
||||||
val visitor = ResolveSuperTypesTask(firSession, classId, file, currentlyComputing, fullyComputed, classLikeDeclaration)
|
val visitor = ResolveSuperTypesTask(session, classId, file, currentlyComputing, fullyComputed, classLikeDeclaration)
|
||||||
file.accept(visitor, null).single
|
file.accept(visitor, null).single
|
||||||
|
|
||||||
return visitor.resultingClass
|
return visitor.resultingClass
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ResolveSuperTypesTask(
|
private class ResolveSuperTypesTask(
|
||||||
private val session: FirSession,
|
override val session: FirSession,
|
||||||
private val requestedClassId: ClassId,
|
private val requestedClassId: ClassId,
|
||||||
file: FirFile,
|
file: FirFile,
|
||||||
private val currentlyComputing: MutableSet<ClassId>,
|
private val currentlyComputing: MutableSet<ClassId>,
|
||||||
private val fullyComputed: MutableSet<ClassId>,
|
private val fullyComputed: MutableSet<ClassId>,
|
||||||
private val knownFirClassLikeDeclaration: FirClassLikeDeclaration<*>? = null
|
private val knownFirClassLikeDeclaration: FirClassLikeDeclaration<*>? = null
|
||||||
) : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) {
|
) : FirAbstractTreeTransformerWithSuperTypes(phase = FirResolvePhase.SUPER_TYPES, reversedScopePriority = true) {
|
||||||
|
|
||||||
lateinit var resultingClass: FirDeclaration
|
lateinit var resultingClass: FirDeclaration
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -6,18 +6,16 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
|
||||||
|
// TODO: rework, see rr/FIR/semoro-dev FirStagesTransformerFactory
|
||||||
class FirTotalResolveTransformer {
|
class FirTotalResolveTransformer {
|
||||||
|
|
||||||
val transformers: List<FirTransformer<Nothing?>> = listOf(
|
val transformers: List<FirTransformer<Nothing?>> =
|
||||||
FirImportResolveTransformer(),
|
FirResolvePhase.values()
|
||||||
FirSupertypeResolverTransformer(),
|
.drop(1) // to remove RAW_FIR phase
|
||||||
FirTypeResolveTransformer(),
|
.map { it.createTransformerByPhase() }
|
||||||
FirStatusResolveTransformer(),
|
|
||||||
FirImplicitTypeBodyResolveTransformerAdapter(),
|
|
||||||
FirBodyResolveTransformerAdapter()
|
|
||||||
)
|
|
||||||
|
|
||||||
fun processFiles(files: List<FirFile>) {
|
fun processFiles(files: List<FirFile>) {
|
||||||
for (transformer in transformers) {
|
for (transformer in transformers) {
|
||||||
|
|||||||
+11
-10
@@ -18,8 +18,11 @@ import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
|
|||||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||||
import org.jetbrains.kotlin.fir.visitors.compose
|
import org.jetbrains.kotlin.fir.visitors.compose
|
||||||
|
|
||||||
open class FirTypeResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(reversedScopePriority = true) {
|
open class FirTypeResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(
|
||||||
private lateinit var session: FirSession
|
phase = FirResolvePhase.TYPES,
|
||||||
|
reversedScopePriority = true
|
||||||
|
) {
|
||||||
|
override lateinit var session: FirSession
|
||||||
|
|
||||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirFile> {
|
||||||
session = file.fileSession
|
session = file.fileSession
|
||||||
@@ -95,20 +98,18 @@ open class FirTypeResolveTransformer : FirAbstractTreeTransformerWithSuperTypes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun transformValueParameter(valueParameter: FirValueParameter, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
override fun transformValueParameter(valueParameter: FirValueParameter, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||||
|
val result = super.transformValueParameter(valueParameter, data).single as FirValueParameter
|
||||||
val valueParameter = super.transformValueParameter(valueParameter, data).single as FirValueParameter
|
if (result.isVararg) {
|
||||||
|
val returnTypeRef = result.returnTypeRef
|
||||||
if (valueParameter.isVararg) {
|
|
||||||
val returnTypeRef = valueParameter.returnTypeRef
|
|
||||||
val returnType = returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
val returnType = returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||||
valueParameter.transformReturnTypeRef(
|
result.transformReturnTypeRef(
|
||||||
StoreType,
|
StoreType,
|
||||||
valueParameter.returnTypeRef.withReplacedConeType(
|
result.returnTypeRef.withReplacedConeType(
|
||||||
returnType.createArrayOf(session)
|
returnType.createArrayOf(session)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return valueParameter.compose()
|
return result.compose()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 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.resolve.transformers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase.*
|
||||||
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
|
|
||||||
|
// TODO: add FirSession parameter
|
||||||
|
fun FirResolvePhase.createTransformerByPhase(): FirTransformer<Nothing?> {
|
||||||
|
return when (this) {
|
||||||
|
RAW_FIR -> throw AssertionError("Raw FIR building phase does not have a transformer")
|
||||||
|
IMPORTS -> FirImportResolveTransformer()
|
||||||
|
SUPER_TYPES -> FirSupertypeResolverTransformer()
|
||||||
|
TYPES -> FirTypeResolveTransformer()
|
||||||
|
STATUS -> FirStatusResolveTransformer()
|
||||||
|
IMPLICIT_TYPES_BODY_RESOLVE -> FirImplicitTypeBodyResolveTransformerAdapter()
|
||||||
|
BODY_RESOLVE -> FirBodyResolveTransformerAdapter()
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -95,6 +95,7 @@ class FirClassSubstitutionScope(
|
|||||||
baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType),
|
baseFunction.receiverTypeRef?.withReplacedConeType(newReceiverType),
|
||||||
baseFunction.returnTypeRef.withReplacedConeType(newReturnType)
|
baseFunction.returnTypeRef.withReplacedConeType(newReturnType)
|
||||||
).apply {
|
).apply {
|
||||||
|
resolvePhase = baseFunction.resolvePhase
|
||||||
status = baseFunction.status as FirDeclarationStatusImpl
|
status = baseFunction.status as FirDeclarationStatusImpl
|
||||||
valueParameters += baseFunction.valueParameters.zip(
|
valueParameters += baseFunction.valueParameters.zip(
|
||||||
newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
|
newParameterTypes ?: List(baseFunction.valueParameters.size) { null }
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ interface FirDeclaration : FirElement {
|
|||||||
|
|
||||||
val session: FirSession
|
val session: FirSession
|
||||||
|
|
||||||
|
var resolvePhase: FirResolvePhase
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||||
visitor.visitDeclaration(this, data)
|
visitor.visitDeclaration(this, data)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 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.declarations
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
|
|
||||||
|
// TODO: remove : FirElement
|
||||||
|
enum class FirResolvePhase : FirElement {
|
||||||
|
RAW_FIR,
|
||||||
|
IMPORTS,
|
||||||
|
SUPER_TYPES,
|
||||||
|
TYPES,
|
||||||
|
STATUS,
|
||||||
|
IMPLICIT_TYPES_BODY_RESOLVE,
|
||||||
|
BODY_RESOLVE;
|
||||||
|
|
||||||
|
val prev: FirResolvePhase get() = values()[ordinal - 1]
|
||||||
|
|
||||||
|
val next: FirResolvePhase get() = values()[ordinal + 1]
|
||||||
|
|
||||||
|
override val psi: PsiElement?
|
||||||
|
get() = null
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Short-cut
|
||||||
|
val DECLARATIONS = STATUS
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -8,9 +8,12 @@ package org.jetbrains.kotlin.fir.declarations.impl
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
import org.jetbrains.kotlin.fir.expressions.impl.FirAbstractAnnotatedElement
|
||||||
|
|
||||||
abstract class FirAbstractAnnotatedDeclaration(
|
abstract class FirAbstractAnnotatedDeclaration(
|
||||||
final override val session: FirSession,
|
final override val session: FirSession,
|
||||||
psi: PsiElement?
|
psi: PsiElement?
|
||||||
) : FirAbstractAnnotatedElement(psi), FirDeclaration
|
) : FirAbstractAnnotatedElement(psi), FirDeclaration {
|
||||||
|
override var resolvePhase = FirResolvePhase.RAW_FIR
|
||||||
|
}
|
||||||
+3
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.declarations.impl
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
@@ -25,6 +26,8 @@ class FirAnonymousFunctionImpl(
|
|||||||
|
|
||||||
override var body: FirBlock? = null
|
override var body: FirBlock? = null
|
||||||
|
|
||||||
|
override var resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
||||||
returnTypeRef = returnTypeRef.transformSingle(transformer, data)
|
returnTypeRef = returnTypeRef.transformSingle(transformer, data)
|
||||||
receiverTypeRef = receiverTypeRef?.transformSingle(transformer, data)
|
receiverTypeRef = receiverTypeRef?.transformSingle(transformer, data)
|
||||||
|
|||||||
+3
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirAbstractElement
|
|||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousInitializer
|
import org.jetbrains.kotlin.fir.declarations.FirAnonymousInitializer
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||||
import org.jetbrains.kotlin.fir.transformSingle
|
import org.jetbrains.kotlin.fir.transformSingle
|
||||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||||
@@ -19,6 +20,8 @@ class FirAnonymousInitializerImpl(
|
|||||||
psi: PsiElement?,
|
psi: PsiElement?,
|
||||||
override var body: FirBlock?
|
override var body: FirBlock?
|
||||||
) : FirAnonymousInitializer, FirAbstractElement(psi) {
|
) : FirAnonymousInitializer, FirAbstractElement(psi) {
|
||||||
|
override var resolvePhase = FirResolvePhase.RAW_FIR
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
|
||||||
body = body?.transformSingle(transformer, data)
|
body = body?.transformSingle(transformer, data)
|
||||||
return this
|
return this
|
||||||
|
|||||||
+3
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||||
@@ -31,6 +32,8 @@ abstract class FirDefaultPropertyAccessor(
|
|||||||
) : FirAbstractElement(psi), FirPropertyAccessor {
|
) : FirAbstractElement(psi), FirPropertyAccessor {
|
||||||
override var status = FirDeclarationStatusImpl(visibility, Modality.FINAL)
|
override var status = FirDeclarationStatusImpl(visibility, Modality.FINAL)
|
||||||
|
|
||||||
|
override var resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||||
|
|
||||||
final override val body: FirBlock? =
|
final override val body: FirBlock? =
|
||||||
null
|
null
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ class FirEnumEntryImpl(
|
|||||||
|
|
||||||
override val arguments = mutableListOf<FirExpression>()
|
override val arguments = mutableListOf<FirExpression>()
|
||||||
|
|
||||||
|
override var resolvePhase = FirResolvePhase.RAW_FIR
|
||||||
|
|
||||||
override fun replaceSupertypes(newSupertypes: List<FirTypeRef>): FirRegularClass {
|
override fun replaceSupertypes(newSupertypes: List<FirTypeRef>): FirRegularClass {
|
||||||
superTypeRefs.clear()
|
superTypeRefs.clear()
|
||||||
superTypeRefs.addAll(newSupertypes)
|
superTypeRefs.addAll(newSupertypes)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirAbstractElement
|
|||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirErrorDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirErrorDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||||
@@ -29,6 +30,8 @@ class FirErrorFunction(
|
|||||||
override val body: FirBlock?
|
override val body: FirBlock?
|
||||||
get() = null
|
get() = null
|
||||||
|
|
||||||
|
override var resolvePhase = FirResolvePhase.BODY_RESOLVE
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
|
||||||
super<FirFunction>.accept(visitor, data)
|
super<FirFunction>.accept(visitor, data)
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
import org.jetbrains.kotlin.fir.expressions.FirVariable
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
||||||
@@ -40,6 +41,7 @@ class FirVariableImpl(
|
|||||||
init {
|
init {
|
||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
delegateFieldSymbol?.bind(this)
|
delegateFieldSymbol?.bind(this)
|
||||||
|
resolvePhase = FirResolvePhase.DECLARATIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
override val receiverTypeRef: FirTypeRef?
|
override val receiverTypeRef: FirTypeRef?
|
||||||
|
|||||||
Reference in New Issue
Block a user