remove descriptors from createInnerClassConstructorWithOuterThisParameter
This commit is contained in:
@@ -38,7 +38,7 @@ class JvmBackendContext(
|
|||||||
irModuleFragment: IrModuleFragment, symbolTable: SymbolTable
|
irModuleFragment: IrModuleFragment, symbolTable: SymbolTable
|
||||||
) : CommonBackendContext {
|
) : CommonBackendContext {
|
||||||
override val builtIns = state.module.builtIns
|
override val builtIns = state.module.builtIns
|
||||||
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(state, symbolTable)
|
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(state)
|
||||||
override val sharedVariablesManager = JvmSharedVariablesManager(builtIns, irBuiltIns)
|
override val sharedVariablesManager = JvmSharedVariablesManager(builtIns, irBuiltIns)
|
||||||
|
|
||||||
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
||||||
|
|||||||
+39
-57
@@ -5,8 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.descriptors
|
package org.jetbrains.kotlin.backend.jvm.descriptors
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.common.deepCopyWithWrappedDescriptors
|
||||||
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedClassDescriptor
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.backend.common.ir.DeclarationFactory
|
import org.jetbrains.kotlin.backend.common.ir.DeclarationFactory
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.createStaticFunctionWithReceivers
|
import org.jetbrains.kotlin.backend.jvm.lower.createStaticFunctionWithReceivers
|
||||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping.isMappedIntrinsicCompanionObject
|
import org.jetbrains.kotlin.builtins.CompanionObjectMapping.isMappedIntrinsicCompanionObject
|
||||||
@@ -14,7 +20,6 @@ import org.jetbrains.kotlin.codegen.OwnerKind
|
|||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
@@ -27,7 +32,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.toIrType
|
|
||||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||||
@@ -37,8 +41,7 @@ import org.jetbrains.org.objectweb.asm.Opcodes
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class JvmDeclarationFactory(
|
class JvmDeclarationFactory(
|
||||||
private val state: GenerationState,
|
private val state: GenerationState
|
||||||
private val symbolTable: SymbolTable
|
|
||||||
) : DeclarationFactory {
|
) : DeclarationFactory {
|
||||||
private val singletonFieldDeclarations = HashMap<IrSymbolOwner, IrField>()
|
private val singletonFieldDeclarations = HashMap<IrSymbolOwner, IrField>()
|
||||||
private val outerThisDeclarations = HashMap<IrClass, IrField>()
|
private val outerThisDeclarations = HashMap<IrClass, IrField>()
|
||||||
@@ -63,7 +66,7 @@ class JvmDeclarationFactory(
|
|||||||
if (!innerClass.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
if (!innerClass.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
||||||
else outerThisDeclarations.getOrPut(innerClass) {
|
else outerThisDeclarations.getOrPut(innerClass) {
|
||||||
val outerClass = innerClass.parent as? IrClass
|
val outerClass = innerClass.parent as? IrClass
|
||||||
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
||||||
|
|
||||||
val symbol = IrFieldSymbolImpl(
|
val symbol = IrFieldSymbolImpl(
|
||||||
JvmPropertyDescriptorImpl.createFinalField(
|
JvmPropertyDescriptorImpl.createFinalField(
|
||||||
@@ -86,60 +89,38 @@ class JvmDeclarationFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor {
|
private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor {
|
||||||
val oldDescriptor = oldConstructor.descriptor
|
val newDescriptor = WrappedClassConstructorDescriptor(oldConstructor.descriptor.annotations)
|
||||||
val classDescriptor = oldDescriptor.containingDeclaration
|
|
||||||
val outerThisType = (classDescriptor.containingDeclaration as ClassDescriptor).defaultType
|
|
||||||
|
|
||||||
val newDescriptor = ClassConstructorDescriptorImpl.createSynthesized(
|
|
||||||
classDescriptor, oldDescriptor.annotations, oldDescriptor.isPrimary, oldDescriptor.source
|
|
||||||
)
|
|
||||||
|
|
||||||
val outerThisValueParameter = newDescriptor.createValueParameter(0, "\$outer", outerThisType)
|
|
||||||
|
|
||||||
val newValueParameters =
|
|
||||||
listOf(outerThisValueParameter) +
|
|
||||||
oldDescriptor.valueParameters.map { it.copy(newDescriptor, it.name, it.index + 1) }
|
|
||||||
// Call the long version of `initialize()`, because otherwise default implementation inserts
|
|
||||||
// an unwanted `dispatchReceiverParameter`
|
|
||||||
newDescriptor.initialize(
|
|
||||||
oldDescriptor.extensionReceiverParameter?.copy(newDescriptor),
|
|
||||||
null,
|
|
||||||
oldDescriptor.typeParameters,
|
|
||||||
newValueParameters,
|
|
||||||
oldDescriptor.returnType,
|
|
||||||
oldDescriptor.modality,
|
|
||||||
oldDescriptor.visibility
|
|
||||||
)
|
|
||||||
val symbol = IrConstructorSymbolImpl(newDescriptor)
|
|
||||||
return IrConstructorImpl(
|
return IrConstructorImpl(
|
||||||
oldConstructor.startOffset,
|
oldConstructor.startOffset, oldConstructor.endOffset, oldConstructor.origin,
|
||||||
oldConstructor.endOffset,
|
IrConstructorSymbolImpl(newDescriptor),
|
||||||
oldConstructor.origin,
|
oldConstructor.name, oldConstructor.visibility, oldConstructor.returnType,
|
||||||
symbol,
|
oldConstructor.isInline, oldConstructor.isExternal, oldConstructor.isPrimary
|
||||||
oldConstructor.returnType
|
).apply {
|
||||||
).also { constructor ->
|
newDescriptor.bind(this)
|
||||||
newValueParameters.mapIndexedTo(constructor.valueParameters) { i, v ->
|
annotations.addAll(oldConstructor.annotations.map { it.deepCopyWithWrappedDescriptors(this) })
|
||||||
constructor.parent = oldConstructor.parent
|
parent = oldConstructor.parent
|
||||||
if (i == 0) {
|
returnType = oldConstructor.returnType
|
||||||
IrValueParameterImpl(
|
copyTypeParametersFrom(oldConstructor)
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
|
||||||
JvmLoweredDeclarationOrigin.FIELD_FOR_OUTER_THIS,
|
|
||||||
IrValueParameterSymbolImpl(v),
|
|
||||||
outerThisType.toIrType(symbolTable)!!,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val oldParameter = oldConstructor.valueParameters[i - 1]
|
|
||||||
IrValueParameterImpl(
|
|
||||||
oldParameter.startOffset, oldParameter.endOffset, oldParameter.origin,
|
|
||||||
IrValueParameterSymbolImpl(v), oldParameter.type, oldParameter.varargElementType
|
|
||||||
).also {
|
|
||||||
it.defaultValue = oldParameter.defaultValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor.metadata = oldConstructor.metadata
|
val outerThisType = oldConstructor.parentAsClass.parentAsClass.defaultType
|
||||||
|
val outerThisDescriptor = WrappedValueParameterDescriptor()
|
||||||
|
val outerThisValueParameter = IrValueParameterImpl(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.FIELD_FOR_OUTER_THIS,
|
||||||
|
IrValueParameterSymbolImpl(outerThisDescriptor),
|
||||||
|
Name.identifier("\$outer"),
|
||||||
|
0,
|
||||||
|
type = outerThisType,
|
||||||
|
varargElementType = null,
|
||||||
|
isCrossinline = false,
|
||||||
|
isNoinline = false
|
||||||
|
).also {
|
||||||
|
outerThisDescriptor.bind(it)
|
||||||
|
it.parent = this
|
||||||
|
}
|
||||||
|
valueParameters.add(outerThisValueParameter)
|
||||||
|
|
||||||
|
oldConstructor.valueParameters.mapTo(valueParameters) { it.copyTo(this, index = it.index + 1) }
|
||||||
|
metadata = oldConstructor.metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +204,7 @@ class JvmDeclarationFactory(
|
|||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
parent = interfaceClass
|
parent = interfaceClass
|
||||||
|
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user