Fake wrapped descriptors first working draft

get rid of descriptors in Bridge and Enum lowerings
Replace property accessors function type with IrSimpleFunction because they couldn't be constructors
get rid of descriptors in Callable reference lowering
refactored descriptor factory and inner class lowering
Add isReified property to IrTypeParameter declaration
keep getting rid of descriptors
Get rid of descriptors in Shared Variable Manager
LocalDeclarationLowering also uses no descriptors
Fix psi2ir
Fix nested classes names
Fix outer reference in inner classes
Fix name generator
get rid of descriptors in coroutines - something is working
Fix name generator
Fix unbound symbols in JVM BE
Rename DeclarationFactory members
This commit is contained in:
Roman Artemev
2018-07-25 23:03:09 +03:00
committed by romanart
parent daadba0927
commit d1621b80cc
88 changed files with 3138 additions and 2716 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
@@ -30,6 +29,7 @@ interface IrTypeParameter : IrSymbolDeclaration<IrTypeParameterSymbol> {
val name: Name
val variance: Variance
val index: Int
val isReified: Boolean
val superTypes: MutableList<IrType>
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrTypeParameter
@@ -35,6 +35,7 @@ class IrTypeParameterImpl(
override val symbol: IrTypeParameterSymbol,
override val name: Name,
override val index: Int,
override val isReified: Boolean,
override val variance: Variance
) :
IrDeclarationBase(startOffset, endOffset, origin),
@@ -50,9 +51,21 @@ class IrTypeParameterImpl(
startOffset, endOffset, origin, symbol,
symbol.descriptor.name,
symbol.descriptor.index,
symbol.descriptor.isReified,
symbol.descriptor.variance
)
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrTypeParameterSymbol,
name: Name,
index: Int,
variance: Variance
) : this(startOffset, endOffset, origin, symbol, name, index, symbol.descriptor.isReified, variance)
@Deprecated("Use constructor which takes symbol instead of descriptor")
constructor(
startOffset: Int,
endOffset: Int,
@@ -55,6 +55,24 @@ class IrVariableImpl(
isLateinit = symbol.descriptor.isLateInit
)
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrVariableSymbol,
type: IrType,
initializer: IrExpression?
) : this(
startOffset, endOffset, origin, symbol,
symbol.descriptor.name, type,
isVar = symbol.descriptor.isVar,
isConst = symbol.descriptor.isConst,
isLateinit = symbol.descriptor.isLateInit
) {
this.initializer = initializer
}
@Deprecated("Use constructor which takes symbol instead of descriptor")
constructor(
startOffset: Int,
endOffset: Int,
@@ -63,6 +81,7 @@ class IrVariableImpl(
type: IrType
) : this(startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), type)
@Deprecated("Use constructor which takes symbol instead of descriptor")
constructor(
startOffset: Int,
endOffset: Int,
@@ -5,9 +5,14 @@
package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.SymbolTable
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
@@ -25,6 +25,7 @@ class IrLazyTypeParameter(
override val symbol: IrTypeParameterSymbol,
override val name: Name,
override val index: Int,
override val isReified: Boolean,
override val variance: Variance,
stubGenerator: DeclarationStubGenerator,
typeTranslator: TypeTranslator
@@ -44,6 +45,7 @@ class IrLazyTypeParameter(
startOffset, endOffset, origin, symbol,
symbol.descriptor.name,
symbol.descriptor.index,
symbol.descriptor.isReified,
symbol.descriptor.variance,
stubGenerator, TypeTranslator
)
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
interface IrCallableReference : IrMemberAccessExpression {
@@ -36,13 +37,13 @@ interface IrFunctionReference : IrCallableReference {
interface IrPropertyReference : IrCallableReference {
override val descriptor: PropertyDescriptor
val field: IrFieldSymbol?
val getter: IrFunctionSymbol?
val setter: IrFunctionSymbol?
val getter: IrSimpleFunctionSymbol?
val setter: IrSimpleFunctionSymbol?
}
interface IrLocalDelegatedPropertyReference : IrCallableReference {
override val descriptor: VariableDescriptorWithAccessors
val delegate: IrVariableSymbol
val getter: IrFunctionSymbol
val setter: IrFunctionSymbol?
val getter: IrSimpleFunctionSymbol
val setter: IrSimpleFunctionSymbol?
}
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -30,8 +30,8 @@ class IrLocalDelegatedPropertyReferenceImpl(
type: IrType,
override val descriptor: VariableDescriptorWithAccessors,
override val delegate: IrVariableSymbol,
override val getter: IrFunctionSymbol,
override val setter: IrFunctionSymbol?,
override val getter: IrSimpleFunctionSymbol,
override val setter: IrSimpleFunctionSymbol?,
origin: IrStatementOrigin? = null
) :
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, 0, origin),
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -31,8 +31,8 @@ class IrPropertyReferenceImpl(
override val descriptor: PropertyDescriptor,
typeArgumentsCount: Int,
override val field: IrFieldSymbol?,
override val getter: IrFunctionSymbol?,
override val setter: IrFunctionSymbol?,
override val getter: IrSimpleFunctionSymbol?,
override val setter: IrSimpleFunctionSymbol?,
origin: IrStatementOrigin? = null
) :
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, typeArgumentsCount, origin),
@@ -26,9 +26,9 @@ abstract class IrSymbolBase<out D : DeclarationDescriptor>(override val descript
abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolOwner>(descriptor: D) :
IrBindableSymbol<D, B>, IrSymbolBase<D>(descriptor) {
init {
assert(isOriginalDescriptor(descriptor)) {
"Substituted descriptor $descriptor for ${descriptor.original}"
}
// assert(isOriginalDescriptor(descriptor)) {
// "Substituted descriptor $descriptor for ${descriptor.original}"
// }
}
private fun isOriginalDescriptor(descriptor: DeclarationDescriptor): Boolean =
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.impl.*
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -104,8 +105,8 @@ private fun makeKotlinType(
return classifier.descriptor.defaultType.replace(newArguments = kotlinTypeArguments).makeNullableAsSpecified(hasQuestionMark)
}
fun ClassifierDescriptor.toIrType(hasQuestionMark: Boolean = false): IrType {
val symbol = getSymbol()
fun ClassifierDescriptor.toIrType(hasQuestionMark: Boolean = false, symbolTable: SymbolTable? = null): IrType {
val symbol = getSymbol(symbolTable)
return IrSimpleTypeImpl(defaultType, symbol, hasQuestionMark, listOf(), listOf())
}
@@ -123,14 +124,14 @@ fun IrClassifierSymbol.typeWith(arguments: List<IrType>): IrSimpleType =
fun IrClass.typeWith(arguments: List<IrType>) = this.symbol.typeWith(arguments)
fun KotlinType.toIrType(): IrType? {
fun KotlinType.toIrType(symbolTable: SymbolTable? = null): IrType? {
if (isDynamic()) return IrDynamicTypeImpl(this, listOf(), Variance.INVARIANT)
val symbol = constructor.declarationDescriptor?.getSymbol() ?: return null
val symbol = constructor.declarationDescriptor?.getSymbol(symbolTable) ?: return null
val arguments = this.arguments.mapIndexed { i, projection ->
val arguments = this.arguments.map { projection ->
when (projection) {
is TypeProjectionImpl -> IrTypeProjectionImpl(projection.type.toIrType()!!, projection.projectionKind)
is TypeProjectionImpl -> IrTypeProjectionImpl(projection.type.toIrType(symbolTable)!!, projection.projectionKind)
is StarProjectionImpl -> IrStarProjectionImpl
else -> error(projection)
}
@@ -142,8 +143,8 @@ fun KotlinType.toIrType(): IrType? {
}
// TODO: this function creates unbound symbol which is the great source of problems
private fun ClassifierDescriptor.getSymbol(): IrClassifierSymbol = when (this) {
is ClassDescriptor -> IrClassSymbolImpl(this)
is TypeParameterDescriptor -> IrTypeParameterSymbolImpl(this)
private fun ClassifierDescriptor.getSymbol(symbolTable: SymbolTable?): IrClassifierSymbol = when (this) {
is ClassDescriptor -> symbolTable?.referenceClass(this) ?: IrClassSymbolImpl(this)
is TypeParameterDescriptor -> /*symbolTable?.referenceTypeParameter(this) ?: */IrTypeParameterSymbolImpl(this)
else -> TODO()
}
@@ -478,8 +478,8 @@ open class DeepCopyIrTreeWithSymbols(
expression.descriptor,
expression.typeArgumentsCount,
expression.field?.let { symbolRemapper.getReferencedField(it) },
expression.getter?.let { symbolRemapper.getReferencedFunction(it) },
expression.setter?.let { symbolRemapper.getReferencedFunction(it) },
expression.getter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
expression.setter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
mapStatementOrigin(expression.origin)
).apply {
copyRemappedTypeArgumentsFrom(expression)
@@ -492,8 +492,8 @@ open class DeepCopyIrTreeWithSymbols(
expression.type.remapType(),
expression.descriptor,
symbolRemapper.getReferencedVariable(expression.delegate),
symbolRemapper.getReferencedFunction(expression.getter),
expression.setter?.let { symbolRemapper.getReferencedFunction(it) },
symbolRemapper.getReferencedSimpleFunction(expression.getter),
expression.setter?.let { symbolRemapper.getReferencedSimpleFunction(it) },
mapStatementOrigin(expression.origin)
)
@@ -157,6 +157,7 @@ open class DeepCopySymbolRemapper(
override fun getReferencedVariable(symbol: IrVariableSymbol): IrVariableSymbol = variables.getReferenced(symbol)
override fun getReferencedField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getReferenced(symbol)
override fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getReferenced(symbol)
override fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getReferenced(symbol)
override fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol =
when (symbol) {
is IrValueParameterSymbol -> valueParameters.getReferenced(symbol)
@@ -158,6 +158,7 @@ fun IrFunction.createParameterDeclarations() {
assert(valueParameters.isEmpty())
descriptor.valueParameters.mapTo(valueParameters) { it.irValueParameter() }
// valueParameters.mapTo(valueParameters) { it.descriptor.irValueParameter() }
assert(typeParameters.isEmpty())
descriptor.typeParameters.mapTo(typeParameters) {
@@ -316,6 +317,30 @@ fun IrAnnotationContainer.hasAnnotation(name: FqName) =
it.symbol.owner.parentAsClass.descriptor.fqNameSafe == name
}
val IrConstructor.constructedClassType get() = (parent as IrClass).thisReceiver?.type!!
fun IrFunction.isFakeOverriddenFromAny(): Boolean {
if (origin != IrDeclarationOrigin.FAKE_OVERRIDE) {
return (parent as? IrClass)?.thisReceiver?.type?.isAny() ?: false
}
return (this as IrSimpleFunction).overriddenSymbols.all { it.owner.isFakeOverriddenFromAny() }
}
fun IrCall.isSuperToAny() = superQualifier?.let { this.symbol.owner.isFakeOverriddenFromAny() } ?: false
fun IrDeclaration.isEffectivelyExternal(): Boolean {
return when (this) {
is IrConstructor -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrFunction -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrField -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrClass -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
else -> false
}
}
val IrDeclaration.isDynamic get() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType
fun IrValueParameter.copy(newDescriptor: ParameterDescriptor): IrValueParameter {
assert(this.descriptor.type == newDescriptor.type)
@@ -37,6 +37,7 @@ interface SymbolRemapper {
fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol
fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol
fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol
fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol
fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol
fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol
}