FIR general refactoring: get rid of ConeSymbols

This commit is contained in:
Mikhail Glukhikh
2019-09-13 10:06:37 +03:00
parent c1c46daa01
commit 20c45a8382
87 changed files with 384 additions and 419 deletions
@@ -14,7 +14,7 @@ interface FirBackingFieldReference : FirResolvedCallableReference {
override val name: Name
get() = NAME
override val coneSymbol: FirBackingFieldSymbol
override val resolvedSymbol: FirBackingFieldSymbol
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R {
return visitor.visitBackingFieldReference(this, data)
@@ -14,7 +14,7 @@ interface FirDelegateFieldReference : FirResolvedCallableReference {
override val name: Name
get() = NAME
override val coneSymbol: FirDelegateFieldSymbol<*>
override val resolvedSymbol: FirDelegateFieldSymbol<*>
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitDelegateFieldReference(this, data)
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.visitors.FirVisitor
import org.jetbrains.kotlin.name.Name
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.name.Name
interface FirNamedReference : FirReference {
val name: Name
val candidateSymbol: ConeSymbol? get() = null
val candidateSymbol: AbstractFirBasedSymbol<*>? get() = null
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitNamedReference(this, data)
@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.*
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.types.*
@@ -752,12 +754,12 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
print("*")
}
private fun ConeSymbol.render(): String {
if (this is ConeCallableSymbol)
return callableId.toString()
else if (this is ConeClassLikeSymbol)
return classId.toString()
return "?"
private fun AbstractFirBasedSymbol<*>.render(): String {
return when (this) {
is FirCallableSymbol<*> -> callableId.toString()
is FirClassLikeSymbol<*> -> classId.toString()
else -> "?"
}
}
override fun visitNamedReference(namedReference: FirNamedReference) {
@@ -773,24 +775,24 @@ class FirRenderer(builder: StringBuilder) : FirVisitorVoid() {
override fun visitBackingFieldReference(backingFieldReference: FirBackingFieldReference) {
print("F|")
print(backingFieldReference.coneSymbol.callableId)
print(backingFieldReference.resolvedSymbol.callableId)
print("|")
}
override fun visitDelegateFieldReference(delegateFieldReference: FirDelegateFieldReference) {
print("D|")
print(delegateFieldReference.coneSymbol.callableId)
print(delegateFieldReference.resolvedSymbol.callableId)
print("|")
}
override fun visitResolvedCallableReference(resolvedCallableReference: FirResolvedCallableReference) {
print("R|")
val isFakeOverride = (resolvedCallableReference.coneSymbol as? FirNamedFunctionSymbol)?.isFakeOverride == true
val isFakeOverride = (resolvedCallableReference.resolvedSymbol as? FirNamedFunctionSymbol)?.isFakeOverride == true
if (isFakeOverride) {
print("FakeOverride<")
}
val symbol = resolvedCallableReference.coneSymbol
val symbol = resolvedCallableReference.resolvedSymbol
print(symbol.render())
if (isFakeOverride) {
when (symbol) {
@@ -5,11 +5,11 @@
package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.visitors.FirVisitor
interface FirResolvedCallableReference : FirNamedReference {
val coneSymbol: ConeSymbol
val resolvedSymbol: AbstractFirBasedSymbol<*>
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R =
visitor.visitResolvedCallableReference(this, data)
@@ -7,11 +7,8 @@ package org.jetbrains.kotlin.fir.declarations
import org.jetbrains.kotlin.fir.VisitedSupertype
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.symbols.ConeClassifierSymbol
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.visitors.FirVisitor
interface FirClassLikeDeclaration<F : FirClassLikeDeclaration<F>> :
@@ -33,9 +30,3 @@ interface FirClassLikeDeclaration<F : FirClassLikeDeclaration<F>> :
var supertypesComputationStatus: SupertypesComputationStatus
}
fun ConeClassifierSymbol.toFirClassLike(): FirClassLikeDeclaration<*>? =
when (this) {
is FirClassSymbol -> this.fir
is FirTypeAliasSymbol -> this.fir
else -> null
}
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.fir.expressions
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.fir.FirResolvedCallableReference
import org.jetbrains.kotlin.fir.expressions.impl.FirAnnotatedStatement
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.FirVisitor
@@ -33,6 +33,6 @@ fun FirExpression.toResolvedCallableReference(): FirResolvedCallableReference? {
}
fun FirExpression.toResolvedCallableSymbol(): ConeCallableSymbol? {
return toResolvedCallableReference()?.coneSymbol as ConeCallableSymbol?
fun FirExpression.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
return toResolvedCallableReference()?.resolvedSymbol as FirCallableSymbol<*>?
}
@@ -12,5 +12,5 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
class FirBackingFieldReferenceImpl(
psi: PsiElement?,
override val coneSymbol: FirBackingFieldSymbol
override val resolvedSymbol: FirBackingFieldSymbol
) : FirAbstractElement(psi), FirBackingFieldReference
@@ -12,5 +12,5 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
class FirDelegateFieldReferenceImpl(
psi: PsiElement?,
override val coneSymbol: FirDelegateFieldSymbol<*>
override val resolvedSymbol: FirDelegateFieldSymbol<*>
) : FirAbstractElement(psi), FirDelegateFieldReference
@@ -14,5 +14,5 @@ import org.jetbrains.kotlin.name.Name
class FirPropertyFromParameterCallableReference(
psi: PsiElement?,
override val name: Name,
override val coneSymbol: FirVariableSymbol<*>
override val resolvedSymbol: FirVariableSymbol<*>
) : FirAbstractElement(psi), FirResolvedCallableReference
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.fir.references
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.fir.FirAbstractElement
import org.jetbrains.kotlin.fir.FirResolvedCallableReference
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.name.Name
class FirResolvedCallableReferenceImpl(
psi: PsiElement?,
override val name: Name,
override val coneSymbol: ConeSymbol
override val resolvedSymbol: AbstractFirBasedSymbol<*>
) : FirAbstractElement(psi), FirResolvedCallableReference
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.NEXT
import org.jetbrains.kotlin.fir.scopes.ProcessorAction.STOP
import org.jetbrains.kotlin.fir.symbols.ConeClassifierSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.name.Name
@@ -20,7 +20,7 @@ abstract class FirScope {
open fun processClassifiersByName(
name: Name,
position: FirPosition,
processor: (ConeClassifierSymbol) -> Boolean
processor: (FirClassifierSymbol<*>) -> Boolean
): Boolean = true
open fun processFunctionsByName(
@@ -39,7 +39,7 @@ abstract class FirScope {
inline fun FirScope.processClassifiersByNameWithAction(
name: Name,
position: FirPosition,
crossinline processor: (ConeClassifierSymbol) -> ProcessorAction
crossinline processor: (FirClassifierSymbol<*>) -> ProcessorAction
): ProcessorAction {
val result = processClassifiersByName(name, position) {
processor(it).next()
@@ -0,0 +1,12 @@
/*
* 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.symbols
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
abstract class ConeClassifierLookupTagWithFixedSymbol : ConeClassifierLookupTag() {
abstract val symbol: FirClassifierSymbol<*>
}
@@ -0,0 +1,18 @@
/*
* 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.symbols
import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.name.Name
data class ConeTypeParameterLookupTag(val typeParameterSymbol: FirTypeParameterSymbol) : ConeClassifierLookupTagWithFixedSymbol() {
override val name: Name get() = typeParameterSymbol.name
override val symbol: FirClassifierSymbol<*>
get() = typeParameterSymbol
}
@@ -5,9 +5,10 @@
package org.jetbrains.kotlin.fir.symbols
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
interface FirBasedSymbol<E> : ConeSymbol where E : FirElement, E : FirSymbolOwner<E> {
interface FirBasedSymbol<E> : TypeConstructorMarker where E : FirDeclaration, E : FirSymbolOwner<E> {
val fir: E
fun bind(e: E)
@@ -5,8 +5,8 @@
package org.jetbrains.kotlin.fir.symbols
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
interface FirSymbolOwner<E> where E : FirElement, E : FirSymbolOwner<E> {
interface FirSymbolOwner<E> where E : FirDeclaration, E : FirSymbolOwner<E> {
val symbol: FirBasedSymbol<E>
}
@@ -0,0 +1,28 @@
/*
* 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.symbols.impl
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.name.ClassId
class ConeClassLikeLookupTagImpl(override val classId: ClassId) : ConeClassLikeLookupTag() {
var boundSymbol: Pair<*, FirClassifierSymbol<*>?>? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeClassLikeLookupTagImpl
if (classId != other.classId) return false
return true
}
override fun hashCode(): Int {
return classId.hashCode()
}
}
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.fir.symbols.impl
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.ConeCallableSymbol
import org.jetbrains.kotlin.fir.symbols.CallableId
abstract class FirCallableSymbol<D : FirCallableDeclaration<D>> : ConeCallableSymbol, AbstractFirBasedSymbol<D>()
abstract class FirCallableSymbol<D : FirCallableDeclaration<D>> : AbstractFirBasedSymbol<D>() {
abstract val callableId: CallableId
}
@@ -12,19 +12,21 @@ import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.name.ClassId
sealed class FirClassLikeSymbol<D : FirClassLikeDeclaration<D>>(
override val classId: ClassId
) : ConeClassLikeSymbol, AbstractFirBasedSymbol<D>() {
val classId: ClassId
) : FirClassifierSymbol<D>() {
abstract override fun toLookupTag(): ConeClassLikeLookupTag
override fun equals(other: Any?): Boolean =
other is FirClassLikeSymbol<*> && fir == other.fir
override fun hashCode(): Int = fir.hashCode()
}
class FirClassSymbol(classId: ClassId) : FirClassLikeSymbol<FirRegularClass>(classId), ConeClassSymbol {
class FirClassSymbol(classId: ClassId) : FirClassLikeSymbol<FirRegularClass>(classId) {
override fun toLookupTag(): ConeClassLikeLookupTag = ConeClassLikeLookupTagImpl(classId)
}
class FirTypeAliasSymbol(override val classId: ClassId) : FirClassLikeSymbol<FirTypeAlias>(classId), ConeTypeAliasSymbol {
class FirTypeAliasSymbol(classId: ClassId) : FirClassLikeSymbol<FirTypeAlias>(classId) {
override fun toLookupTag(): TypeAliasLookupTagImpl = TypeAliasLookupTagImpl(classId)
}
@@ -0,0 +1,17 @@
/*
* 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.symbols.impl
import org.jetbrains.kotlin.fir.declarations.FirNamedDeclaration
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.fir.symbols.FirSymbolOwner
import org.jetbrains.kotlin.types.model.TypeParameterMarker
abstract class FirClassifierSymbol<E> :
AbstractFirBasedSymbol<E>(), TypeParameterMarker where E : FirNamedDeclaration, E : FirSymbolOwner<E> {
abstract fun toLookupTag(): ConeClassifierLookupTag
}
@@ -8,16 +8,14 @@ package org.jetbrains.kotlin.fir.symbols.impl
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirErrorFunction
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConeFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
sealed class FirFunctionSymbol<D : FirFunction<D>>(
override val callableId: CallableId
) : ConeFunctionSymbol, FirCallableSymbol<D>() {
override val parameters: List<ConeKotlinType>
) : FirCallableSymbol<D>() {
open val parameters: List<ConeKotlinType>
get() = emptyList()
}
@@ -37,7 +35,7 @@ class FirConstructorSymbol(
class FirAccessorSymbol(
callableId: CallableId,
val accessorId: CallableId
) : ConePropertySymbol, FirFunctionSymbol<FirNamedFunction>(callableId)
) : FirFunctionSymbol<FirNamedFunction>(callableId)
// ------------------------ unnamed ------------------------
@@ -1,14 +0,0 @@
/*
* Copyright 2010-2018 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.symbols.impl
import org.jetbrains.kotlin.fir.declarations.FirTypeAlias
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeTypeAliasLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeTypeAliasSymbol
import org.jetbrains.kotlin.name.ClassId
@@ -6,12 +6,12 @@
package org.jetbrains.kotlin.fir.symbols.impl
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.symbols.*
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.name.Name
class FirTypeParameterSymbol : AbstractFirBasedSymbol<FirTypeParameter>(), ConeTypeParameterSymbol {
class FirTypeParameterSymbol : FirClassifierSymbol<FirTypeParameter>() {
override val name: Name
val name: Name
get() = fir.name
private val lookupTag = ConeTypeParameterLookupTag(this)
@@ -26,3 +26,4 @@ class FirTypeParameterSymbol : AbstractFirBasedSymbol<FirTypeParameter>(), ConeT
return fir.hashCode()
}
}
@@ -10,11 +10,9 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirVariable
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.ConePropertySymbol
import org.jetbrains.kotlin.fir.symbols.ConeVariableSymbol
import org.jetbrains.kotlin.name.Name
open class FirVariableSymbol<D : FirVariable<D>>(override val callableId: CallableId) : ConeVariableSymbol, FirCallableSymbol<D>() {
open class FirVariableSymbol<D : FirVariable<D>>(override val callableId: CallableId) : FirCallableSymbol<D>() {
@Deprecated("TODO: Better solution for local vars?")
constructor(name: Name) : this(CallableId(name)) // TODO?
@@ -25,7 +23,7 @@ open class FirPropertySymbol(
val isFakeOverride: Boolean = false,
// Actual for fake override only
val overriddenSymbol: FirPropertySymbol? = null
) : ConePropertySymbol, FirVariableSymbol<FirProperty>(callableId)
) : FirVariableSymbol<FirProperty>(callableId)
class FirBackingFieldSymbol(callableId: CallableId) : FirVariableSymbol<FirProperty>(callableId)
@@ -0,0 +1,13 @@
/*
* 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.types
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
abstract class ConeTypeParameterType : ConeLookupTagBasedType() {
abstract override val lookupTag: ConeTypeParameterLookupTag
}
@@ -0,0 +1,41 @@
/*
* 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.types.impl
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
import org.jetbrains.kotlin.fir.types.ConeNullability
import org.jetbrains.kotlin.fir.types.ConeTypeParameterType
class ConeTypeParameterTypeImpl(
override val lookupTag: ConeTypeParameterLookupTag,
isNullable: Boolean
) : ConeTypeParameterType() {
override val typeArguments: Array<out ConeKotlinTypeProjection>
get() = EMPTY_ARRAY
override val nullability: ConeNullability = ConeNullability.create(isNullable)
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ConeTypeParameterTypeImpl
if (lookupTag != other.lookupTag) return false
if (nullability != other.nullability) return false
return true
}
override fun hashCode(): Int {
var result = lookupTag.hashCode()
result = 31 * result + nullability.hashCode()
return result
}
}
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.fir.types.impl
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.fir.FirAbstractElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef