Clean up backend.common.ir.IrUtils.kt
This commit is contained in:
+9
-4
@@ -14,10 +14,12 @@ import org.jetbrains.kotlin.ir.types.toKotlinType
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope
|
import org.jetbrains.kotlin.resolve.scopes.TypeIntersectionScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
|
|
||||||
|
|
||||||
@@ -168,15 +170,18 @@ open class WrappedTypeParameterDescriptor(
|
|||||||
private val _defaultType: SimpleType by lazy {
|
private val _defaultType: SimpleType by lazy {
|
||||||
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope(
|
||||||
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
Annotations.EMPTY, typeConstructor, emptyList(), false,
|
||||||
TypeIntersectionScope.create(
|
LazyScopeAdapter(LockBasedStorageManager.NO_LOCKS.createLazyValue {
|
||||||
"Scope for type parameter " + name.asString(),
|
TypeIntersectionScope.create(
|
||||||
upperBounds
|
"Scope for type parameter " + name.asString(),
|
||||||
)
|
upperBounds
|
||||||
|
)
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDefaultType() = _defaultType
|
override fun getDefaultType() = _defaultType
|
||||||
|
|
||||||
|
|
||||||
override fun getContainingDeclaration() = (owner.parent as IrDeclaration).descriptor
|
override fun getContainingDeclaration() = (owner.parent as IrDeclaration).descriptor
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R =
|
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R =
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ 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.ClassConstructorDescriptorImpl
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
||||||
@@ -160,7 +159,7 @@ fun IrValueParameter.copyTo(
|
|||||||
endOffset: Int = this.endOffset,
|
endOffset: Int = this.endOffset,
|
||||||
origin: IrDeclarationOrigin = this.origin,
|
origin: IrDeclarationOrigin = this.origin,
|
||||||
name: Name = this.name,
|
name: Name = this.name,
|
||||||
type: IrType = this.type.maybeReplace(this.parent as IrTypeParametersContainer, irFunction),
|
type: IrType = this.type.remapTypeParameters(this.parent as IrTypeParametersContainer, irFunction),
|
||||||
varargElementType: IrType? = this.varargElementType
|
varargElementType: IrType? = this.varargElementType
|
||||||
): IrValueParameter {
|
): IrValueParameter {
|
||||||
val descriptor = WrappedValueParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
val descriptor = WrappedValueParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
||||||
@@ -174,17 +173,23 @@ fun IrValueParameter.copyTo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParameter {
|
fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||||
// TODO: Copy IrTypeParameter with type remapping
|
target: IrTypeParametersContainer,
|
||||||
|
shift: Int = 0,
|
||||||
|
origin: IrDeclarationOrigin = this.origin
|
||||||
|
): IrTypeParameter {
|
||||||
|
val source = parent as IrTypeParametersContainer
|
||||||
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
||||||
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
||||||
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also {
|
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also { copied ->
|
||||||
descriptor.bind(it)
|
descriptor.bind(copied)
|
||||||
it.parent = irFunction
|
copied.parent = target
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||||
|
assert(typeParameters.isEmpty())
|
||||||
|
copyTypeParametersFrom(from)
|
||||||
|
|
||||||
// TODO: should dispatch receiver be copied?
|
// TODO: should dispatch receiver be copied?
|
||||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
||||||
@@ -196,39 +201,32 @@ fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
|||||||
|
|
||||||
val shift = valueParameters.size
|
val shift = valueParameters.size
|
||||||
valueParameters += from.valueParameters.map { it.copyTo(this, shift) }
|
valueParameters += from.valueParameters.map { it.copyTo(this, shift) }
|
||||||
|
|
||||||
assert(typeParameters.isEmpty())
|
|
||||||
from.typeParameters.mapTo(typeParameters) { it.copyTo(this) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
||||||
source: IrTypeParametersContainer,
|
source: IrTypeParametersContainer,
|
||||||
origin: IrDeclarationOrigin
|
origin: IrDeclarationOrigin? = null
|
||||||
) {
|
) {
|
||||||
val target = this
|
val target = this
|
||||||
assert(target.typeParameters.isEmpty())
|
val shift = target.typeParameters.size
|
||||||
|
// Any type parameter can figure in a boundary type for any other parameter.
|
||||||
|
// Therefore, we first copy the parameters themselves, then set up their supertypes.
|
||||||
source.typeParameters.forEachIndexed { i, sourceParameter ->
|
source.typeParameters.forEachIndexed { i, sourceParameter ->
|
||||||
assert(sourceParameter.index == i)
|
assert(sourceParameter.index == i)
|
||||||
val tpDescriptor = WrappedTypeParameterDescriptor()
|
target.typeParameters.add(sourceParameter.copyToWithoutSuperTypes(target, shift = shift, origin = origin ?: sourceParameter.origin))
|
||||||
target.typeParameters.add(
|
}
|
||||||
IrTypeParameterImpl(
|
source.typeParameters.zip(target.typeParameters.drop(shift)).forEach { (srcParameter, dstParameter) ->
|
||||||
UNDEFINED_OFFSET,
|
dstParameter.copySuperTypesFrom(srcParameter)
|
||||||
UNDEFINED_OFFSET,
|
}
|
||||||
origin,
|
}
|
||||||
IrTypeParameterSymbolImpl(tpDescriptor),
|
|
||||||
sourceParameter.name,
|
private fun IrTypeParameter.copySuperTypesFrom(source: IrTypeParameter) {
|
||||||
sourceParameter.index,
|
val target = this
|
||||||
sourceParameter.isReified,
|
val sourceParent = source.parent as IrTypeParametersContainer
|
||||||
sourceParameter.variance
|
val targetParent = target.parent as IrTypeParametersContainer
|
||||||
).apply {
|
val shift = target.index - source.index
|
||||||
tpDescriptor.bind(this)
|
source.superTypes.forEach {
|
||||||
parent = target
|
target.superTypes.add(it.remapTypeParameters(sourceParent, targetParent, shift))
|
||||||
sourceParameter.superTypes.forEach {
|
|
||||||
// Using the already copied portion of target.typeParameters.
|
|
||||||
superTypes.add(it.maybeReplace(source, target))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,13 +273,14 @@ fun IrFunction.copyValueParametersToStatic(
|
|||||||
Type parameters should correspond to the function where they are defined.
|
Type parameters should correspond to the function where they are defined.
|
||||||
`source` is where the type is originally taken from.
|
`source` is where the type is originally taken from.
|
||||||
*/
|
*/
|
||||||
fun IrType.maybeReplace(source: IrTypeParametersContainer, target: IrTypeParametersContainer): IrType =
|
fun IrType.remapTypeParameters(source: IrTypeParametersContainer, target: IrTypeParametersContainer, shift: Int = 0): IrType =
|
||||||
when (this) {
|
when (this) {
|
||||||
is IrSimpleType -> {
|
is IrSimpleType -> {
|
||||||
val classifier = classifier.owner
|
val classifier = classifier.owner
|
||||||
when {
|
when {
|
||||||
classifier is IrTypeParameter && classifier.parent == source ->
|
classifier is IrTypeParameter && classifier.parent == source ->
|
||||||
target.typeParameters[classifier.index].defaultType
|
target.typeParameters[classifier.index + shift].defaultType
|
||||||
|
|
||||||
classifier is IrClass ->
|
classifier is IrClass ->
|
||||||
IrSimpleTypeImpl(
|
IrSimpleTypeImpl(
|
||||||
classifier.symbol,
|
classifier.symbol,
|
||||||
@@ -289,7 +288,7 @@ fun IrType.maybeReplace(source: IrTypeParametersContainer, target: IrTypeParamet
|
|||||||
arguments.map {
|
arguments.map {
|
||||||
when (it) {
|
when (it) {
|
||||||
is IrTypeProjection -> makeTypeProjection(
|
is IrTypeProjection -> makeTypeProjection(
|
||||||
it.type.maybeReplace(source, target),
|
it.type.remapTypeParameters(source, target, shift),
|
||||||
it.variance
|
it.variance
|
||||||
)
|
)
|
||||||
else -> it
|
else -> it
|
||||||
@@ -297,8 +296,10 @@ fun IrType.maybeReplace(source: IrTypeParametersContainer, target: IrTypeParamet
|
|||||||
},
|
},
|
||||||
annotations
|
annotations
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> this
|
else -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> this
|
else -> this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDesc
|
|||||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
|
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
|
||||||
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
@@ -372,8 +373,8 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newFunction.copyTypeParametersFrom(this)
|
||||||
val newValueParameters = valueParameters.map { it.copyTo(newFunction) } + syntheticParameters
|
val newValueParameters = valueParameters.map { it.copyTo(newFunction) } + syntheticParameters
|
||||||
val newTypeParameters = typeParameters.map { it.copyTo(newFunction) }
|
|
||||||
|
|
||||||
newFunction.returnType = returnType
|
newFunction.returnType = returnType
|
||||||
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.run {
|
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.run {
|
||||||
@@ -381,7 +382,6 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex
|
|||||||
}
|
}
|
||||||
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
|
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
|
||||||
newFunction.valueParameters += newValueParameters
|
newFunction.valueParameters += newValueParameters
|
||||||
newFunction.typeParameters += newTypeParameters
|
|
||||||
|
|
||||||
annotations.mapTo(newFunction.annotations) { it.deepCopyWithSymbols() }
|
annotations.mapTo(newFunction.annotations) { it.deepCopyWithSymbols() }
|
||||||
|
|
||||||
|
|||||||
+4
-7
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.BackendContext
|
|||||||
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
import org.jetbrains.kotlin.backend.common.descriptors.*
|
||||||
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
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.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
@@ -516,15 +517,13 @@ class LocalDeclarationsLowering(
|
|||||||
|
|
||||||
newDeclaration.parent = memberOwner
|
newDeclaration.parent = memberOwner
|
||||||
newDeclaration.returnType = oldDeclaration.returnType
|
newDeclaration.returnType = oldDeclaration.returnType
|
||||||
|
newDeclaration.copyTypeParametersFrom(oldDeclaration)
|
||||||
newDeclaration.dispatchReceiverParameter = newDispatchReceiverParameter
|
newDeclaration.dispatchReceiverParameter = newDispatchReceiverParameter
|
||||||
newDeclaration.extensionReceiverParameter = oldDeclaration.extensionReceiverParameter?.run {
|
newDeclaration.extensionReceiverParameter = oldDeclaration.extensionReceiverParameter?.run {
|
||||||
copyTo(newDeclaration).also {
|
copyTo(newDeclaration).also {
|
||||||
newParameterToOld.putAbsentOrSame(it, this)
|
newParameterToOld.putAbsentOrSame(it, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldDeclaration.typeParameters.mapTo(newDeclaration.typeParameters) {
|
|
||||||
it.copyTo(newDeclaration).also { p -> p.superTypes += it.superTypes }
|
|
||||||
}
|
|
||||||
|
|
||||||
newDeclaration.valueParameters += createTransformedValueParameters(capturedValues, oldDeclaration, newDeclaration)
|
newDeclaration.valueParameters += createTransformedValueParameters(capturedValues, oldDeclaration, newDeclaration)
|
||||||
newDeclaration.recordTransformedValueParameters(localFunctionContext)
|
newDeclaration.recordTransformedValueParameters(localFunctionContext)
|
||||||
@@ -596,6 +595,8 @@ class LocalDeclarationsLowering(
|
|||||||
|
|
||||||
newDeclaration.parent = localClassContext.declaration
|
newDeclaration.parent = localClassContext.declaration
|
||||||
newDeclaration.returnType = oldDeclaration.returnType
|
newDeclaration.returnType = oldDeclaration.returnType
|
||||||
|
newDeclaration.copyTypeParametersFrom(oldDeclaration)
|
||||||
|
|
||||||
// TODO: should dispatch receiver be copied?
|
// TODO: should dispatch receiver be copied?
|
||||||
newDeclaration.dispatchReceiverParameter = oldDeclaration.dispatchReceiverParameter?.run {
|
newDeclaration.dispatchReceiverParameter = oldDeclaration.dispatchReceiverParameter?.run {
|
||||||
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also {
|
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also {
|
||||||
@@ -607,10 +608,6 @@ class LocalDeclarationsLowering(
|
|||||||
throw AssertionError("constructors can't have extension receiver")
|
throw AssertionError("constructors can't have extension receiver")
|
||||||
}
|
}
|
||||||
|
|
||||||
oldDeclaration.typeParameters.mapTo(newDeclaration.typeParameters) {
|
|
||||||
it.copyTo(newDeclaration).also { p -> p.superTypes += it.superTypes }
|
|
||||||
}
|
|
||||||
|
|
||||||
newDeclaration.valueParameters += createTransformedValueParameters(capturedValues, oldDeclaration, newDeclaration)
|
newDeclaration.valueParameters += createTransformedValueParameters(capturedValues, oldDeclaration, newDeclaration)
|
||||||
newDeclaration.recordTransformedValueParameters(constructorContext)
|
newDeclaration.recordTransformedValueParameters(constructorContext)
|
||||||
transformedDeclarations[oldDeclaration] = newDeclaration
|
transformedDeclarations[oldDeclaration] = newDeclaration
|
||||||
|
|||||||
+3
-4
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedClassConstructorDe
|
|||||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedPropertyDescriptor
|
import org.jetbrains.kotlin.backend.common.descriptors.WrappedPropertyDescriptor
|
||||||
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.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
@@ -103,6 +104,8 @@ class JsDeclarationFactory : DeclarationFactory {
|
|||||||
it.returnType = oldConstructor.returnType
|
it.returnType = oldConstructor.returnType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newConstructor.copyTypeParametersFrom(oldConstructor)
|
||||||
|
|
||||||
val outerThisValueParameter =
|
val outerThisValueParameter =
|
||||||
JsIrBuilder.buildValueParameter(Namer.OUTER_NAME, 0, outerThisType).also { it.parent = newConstructor }
|
JsIrBuilder.buildValueParameter(Namer.OUTER_NAME, 0, outerThisType).also { it.parent = newConstructor }
|
||||||
|
|
||||||
@@ -112,10 +115,6 @@ class JsDeclarationFactory : DeclarationFactory {
|
|||||||
newValueParameters += p.copyTo(newConstructor, 1)
|
newValueParameters += p.copyTo(newConstructor, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (p in oldConstructor.typeParameters) {
|
|
||||||
newConstructor.typeParameters += p.copyTo(newConstructor)
|
|
||||||
}
|
|
||||||
|
|
||||||
newConstructor.valueParameters += newValueParameters
|
newConstructor.valueParameters += newValueParameters
|
||||||
|
|
||||||
return newConstructor
|
return newConstructor
|
||||||
|
|||||||
+4
-4
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
||||||
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
@@ -153,12 +154,11 @@ class SecondaryCtorLowering(val context: JsIrBackendContext) {
|
|||||||
val retStmt = JsIrBuilder.buildReturn(it.symbol, JsIrBuilder.buildGetValue(thisParam.symbol), context.irBuiltIns.nothingType)
|
val retStmt = JsIrBuilder.buildReturn(it.symbol, JsIrBuilder.buildGetValue(thisParam.symbol), context.irBuiltIns.nothingType)
|
||||||
val statements = (declaration.body!!.deepCopyWithSymbols(it) as IrStatementContainer).statements
|
val statements = (declaration.body!!.deepCopyWithSymbols(it) as IrStatementContainer).statements
|
||||||
|
|
||||||
|
it.copyTypeParametersFrom(declaration)
|
||||||
|
|
||||||
val newValueParameters = declaration.valueParameters.map { p -> p.copyTo(it) }
|
val newValueParameters = declaration.valueParameters.map { p -> p.copyTo(it) }
|
||||||
|
|
||||||
it.valueParameters += (newValueParameters + thisParam)
|
it.valueParameters += (newValueParameters + thisParam)
|
||||||
|
|
||||||
it.typeParameters += declaration.typeParameters.map { p -> p.copyTo(it) }
|
|
||||||
|
|
||||||
it.returnType = type
|
it.returnType = type
|
||||||
it.parent = declaration.parent
|
it.parent = declaration.parent
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ class SecondaryCtorLowering(val context: JsIrBackendContext) {
|
|||||||
declaration.isInline,
|
declaration.isInline,
|
||||||
declaration.isExternal
|
declaration.isExternal
|
||||||
).also {
|
).also {
|
||||||
|
it.copyTypeParametersFrom(declaration)
|
||||||
it.valueParameters += declaration.valueParameters.map { p -> p.copyTo(it) }
|
it.valueParameters += declaration.valueParameters.map { p -> p.copyTo(it) }
|
||||||
it.typeParameters += declaration.typeParameters.map { p -> p.copyTo(it) }
|
|
||||||
it.parent = declaration.parent
|
it.parent = declaration.parent
|
||||||
|
|
||||||
it.returnType = type
|
it.returnType = type
|
||||||
|
|||||||
+2
-1
@@ -447,13 +447,14 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
|||||||
irFunction.isSuspend,
|
irFunction.isSuspend,
|
||||||
IrDeclarationOrigin.FAKE_OVERRIDE
|
IrDeclarationOrigin.FAKE_OVERRIDE
|
||||||
).apply {
|
).apply {
|
||||||
|
parent = this@setSuperSymbolsAndAddFakeOverrides
|
||||||
returnType = irFunction.returnType
|
returnType = irFunction.returnType
|
||||||
overriddenSymbols += irFunction.symbol
|
overriddenSymbols += irFunction.symbol
|
||||||
copyParameterDeclarationsFrom(irFunction)
|
copyParameterDeclarationsFrom(irFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sm in unoverriddenSuperMembers) {
|
for (sm in unoverriddenSuperMembers) {
|
||||||
val fakeOverride = createFakeOverride(sm).also { it.parent = this }
|
val fakeOverride = createFakeOverride(sm)
|
||||||
declarations += fakeOverride
|
declarations += fakeOverride
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -110,7 +110,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
|||||||
|
|
||||||
accessor.copyTypeParametersFrom(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
accessor.copyTypeParametersFrom(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||||
accessor.copyValueParametersToStatic(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
accessor.copyValueParametersToStatic(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||||
accessor.returnType = source.returnType.maybeReplace(source, accessor)
|
accessor.returnType = source.returnType.remapTypeParameters(source, accessor)
|
||||||
|
|
||||||
val markerParameterDescriptor = WrappedValueParameterDescriptor()
|
val markerParameterDescriptor = WrappedValueParameterDescriptor()
|
||||||
val markerParameter = IrValueParameterImpl(
|
val markerParameter = IrValueParameterImpl(
|
||||||
@@ -166,7 +166,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
|||||||
|
|
||||||
accessor.copyTypeParametersFrom(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
accessor.copyTypeParametersFrom(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||||
accessor.copyValueParametersToStatic(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
accessor.copyValueParametersToStatic(source, JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR)
|
||||||
accessor.returnType = source.returnType.maybeReplace(source, accessor)
|
accessor.returnType = source.returnType.remapTypeParameters(source, accessor)
|
||||||
|
|
||||||
accessor.body = IrExpressionBodyImpl(
|
accessor.body = IrExpressionBodyImpl(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
|
|||||||
+5
-3
@@ -36,18 +36,20 @@ abstract class IrLazyFunctionBase(
|
|||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? by lazyVar {
|
override var dispatchReceiverParameter: IrValueParameter? by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
descriptor.dispatchReceiverParameter?.generateReceiverParameterStub()
|
descriptor.dispatchReceiverParameter?.generateReceiverParameterStub()?.also { it.parent = this@IrLazyFunctionBase }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override var extensionReceiverParameter: IrValueParameter? by lazyVar {
|
override var extensionReceiverParameter: IrValueParameter? by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
descriptor.extensionReceiverParameter?.generateReceiverParameterStub()
|
descriptor.extensionReceiverParameter?.generateReceiverParameterStub()?.also { it.parent = this@IrLazyFunctionBase }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val valueParameters: MutableList<IrValueParameter> by lazy {
|
override val valueParameters: MutableList<IrValueParameter> by lazy {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
descriptor.valueParameters.mapTo(arrayListOf()) { stubGenerator.generateValueParameterStub(it) }
|
descriptor.valueParameters.mapTo(arrayListOf()) {
|
||||||
|
stubGenerator.generateValueParameterStub(it).apply { parent = this@IrLazyFunctionBase }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,13 @@ fun ClassifierDescriptor.toIrType(hasQuestionMark: Boolean = false, symbolTable:
|
|||||||
return IrSimpleTypeImpl(defaultType, symbol, hasQuestionMark, listOf(), listOf())
|
return IrSimpleTypeImpl(defaultType, symbol, hasQuestionMark, listOf(), listOf())
|
||||||
}
|
}
|
||||||
|
|
||||||
val IrTypeParameter.defaultType: IrType get() = symbol.owner.defaultType
|
val IrTypeParameter.defaultType: IrType
|
||||||
|
get() = IrSimpleTypeImpl(
|
||||||
|
symbol,
|
||||||
|
hasQuestionMark = false,
|
||||||
|
arguments = emptyList(),
|
||||||
|
annotations = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
fun IrClassifierSymbol.typeWith(vararg arguments: IrType): IrSimpleType = typeWith(arguments.toList())
|
fun IrClassifierSymbol.typeWith(vararg arguments: IrType): IrSimpleType = typeWith(arguments.toList())
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
package a
|
package a
|
||||||
|
|||||||
Reference in New Issue
Block a user