Fix code review
Minor fixes Fix JVM IR BE Fix NATIVE
This commit is contained in:
+4
-1
@@ -221,7 +221,7 @@ open class WrappedSimpleFunctionDescriptor(
|
||||
|
||||
val extensionReceiver by lazy {
|
||||
owner.extensionReceiverParameter?.let {
|
||||
ReceiverParameterDescriptorImpl(this, ExtensionReceiver(it.descriptor, it.type.toKotlinType(), null))
|
||||
ReceiverParameterDescriptorImpl(this, ExtensionReceiver(it.descriptor, it.type.toKotlinType(), null), Annotations.EMPTY)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,6 +294,9 @@ open class WrappedClassConstructorDescriptor(
|
||||
) : ClassConstructorDescriptor, WrappedCallableDescriptor<IrConstructor>(annotations, sourceElement) {
|
||||
override fun getContainingDeclaration() = (owner.parent as IrClass).descriptor
|
||||
|
||||
override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run {
|
||||
(containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter
|
||||
}
|
||||
override fun getTypeParameters() = owner.typeParameters.map { it.descriptor }
|
||||
override fun getValueParameters() = owner.valueParameters.asSequence()
|
||||
.mapNotNull { it.descriptor as? ValueParameterDescriptor }
|
||||
|
||||
@@ -158,6 +158,7 @@ fun IrValueParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrValuePara
|
||||
}
|
||||
|
||||
fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParameter {
|
||||
// TODO: Copy IrTypeParameter with type remapping
|
||||
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
||||
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
||||
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also {
|
||||
@@ -168,7 +169,12 @@ fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParame
|
||||
|
||||
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
||||
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.copyTo(this)
|
||||
// TODO: should dispatch receiver be copied?
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
||||
IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also {
|
||||
it.parent = this
|
||||
}
|
||||
}
|
||||
extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this)
|
||||
|
||||
val shift = valueParameters.size
|
||||
|
||||
+13
-12
@@ -15,17 +15,16 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDesc
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
|
||||
import org.jetbrains.kotlin.backend.common.ir.copyTo
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
@@ -142,9 +141,9 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
|
||||
}
|
||||
}
|
||||
// Remove default argument initializers.
|
||||
// irFunction.valueParameters.forEach {
|
||||
// it.defaultValue = null
|
||||
// }
|
||||
irFunction.valueParameters.forEach {
|
||||
it.defaultValue = IrExpressionBodyImpl(IrErrorExpressionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, it.type, "Default Stub"))
|
||||
}
|
||||
|
||||
return listOf(irFunction, newIrFunction)
|
||||
}
|
||||
@@ -377,7 +376,9 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex
|
||||
val newTypeParameters = typeParameters.map { it.copyTo(newFunction) }
|
||||
|
||||
newFunction.returnType = returnType
|
||||
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(newFunction)
|
||||
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.run {
|
||||
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also { it.parent = newFunction }
|
||||
}
|
||||
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
|
||||
newFunction.valueParameters += newValueParameters
|
||||
newFunction.typeParameters += newTypeParameters
|
||||
@@ -399,7 +400,7 @@ private fun buildFunctionDeclaration(irFunction: IrFunction): IrFunction {
|
||||
irFunction.name,
|
||||
irFunction.visibility,
|
||||
irFunction.isInline,
|
||||
irFunction.isExternal,
|
||||
false,
|
||||
false
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
@@ -417,10 +418,10 @@ private fun buildFunctionDeclaration(irFunction: IrFunction): IrFunction {
|
||||
IrSimpleFunctionSymbolImpl(descriptor),
|
||||
name,
|
||||
irFunction.visibility,
|
||||
irFunction.modality,
|
||||
Modality.FINAL,
|
||||
irFunction.isInline,
|
||||
irFunction.isExternal,
|
||||
irFunction.isTailrec,
|
||||
false,
|
||||
false,
|
||||
irFunction.isSuspend
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
|
||||
+6
-4
@@ -55,7 +55,7 @@ class LocalDeclarationsLowering(
|
||||
val context: BackendContext,
|
||||
val localNameProvider: LocalNameProvider = LocalNameProvider.DEFAULT,
|
||||
val loweredConstructorVisibility: Visibility = Visibilities.PRIVATE,
|
||||
private val isJVM: Boolean = false
|
||||
private val isJVM: Boolean = false // TODO: remove this workaround
|
||||
) :
|
||||
DeclarationContainerLoweringPass {
|
||||
|
||||
@@ -350,7 +350,7 @@ class LocalDeclarationsLowering(
|
||||
override fun visitReturn(expression: IrReturn): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
val oldReturnTarget = expression.returnTargetSymbol.owner as IrFunction
|
||||
val oldReturnTarget = expression.returnTargetSymbol.owner as? IrFunction ?: return expression
|
||||
val newReturnTarget = oldReturnTarget.transformed ?: return expression
|
||||
|
||||
return IrReturnImpl(
|
||||
@@ -503,7 +503,7 @@ class LocalDeclarationsLowering(
|
||||
newSymbol,
|
||||
newName,
|
||||
// TODO: change to PRIVATE when issue with CallableReferenceLowering in Jvm BE is fixed
|
||||
Visibilities.PUBLIC,
|
||||
if (isJVM) Visibilities.PUBLIC else Visibilities.PRIVATE,
|
||||
Modality.FINAL,
|
||||
oldDeclaration.isInline,
|
||||
oldDeclaration.isExternal,
|
||||
@@ -596,8 +596,10 @@ class LocalDeclarationsLowering(
|
||||
|
||||
newDeclaration.parent = localClassContext.declaration
|
||||
newDeclaration.returnType = oldDeclaration.returnType
|
||||
// TODO: should dispatch receiver be copied?
|
||||
newDeclaration.dispatchReceiverParameter = oldDeclaration.dispatchReceiverParameter?.run {
|
||||
copyTo(newDeclaration).also {
|
||||
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also {
|
||||
it.parent = newDeclaration
|
||||
newParameterToOld.putAbsentOrSame(it, this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ class VariableRemapper(val mapping: Map<IrValueParameter, IrValueParameter>) : A
|
||||
mapping[value]
|
||||
}
|
||||
|
||||
class VariableRemapperDesc(val mapping: Map<ValueDescriptor, IrValueParameter>) : AbstractVariableRemapper() {
|
||||
override fun remapVariable(value: IrValueDeclaration): IrValueParameter? =
|
||||
mapping[value.descriptor]
|
||||
}
|
||||
|
||||
fun BackendContext.createIrBuilder(
|
||||
symbol: IrSymbol,
|
||||
startOffset: Int = UNDEFINED_OFFSET,
|
||||
|
||||
+3
-1
@@ -133,7 +133,9 @@ class JsSharedVariablesManager(val builtIns: IrBuiltIns, val implicitDeclaration
|
||||
declaration.parent = implicitDeclarationsFile
|
||||
closureBoxType = IrSimpleTypeImpl(declaration.symbol, false, emptyList(), emptyList())
|
||||
declaration.thisReceiver =
|
||||
JsIrBuilder.buildValueParameter(Name.special("<this>"), -1, closureBoxType, IrDeclarationOrigin.INSTANCE_RECEIVER)
|
||||
JsIrBuilder.buildValueParameter(Name.special("<this>"), -1, closureBoxType, IrDeclarationOrigin.INSTANCE_RECEIVER).apply {
|
||||
parent = declaration
|
||||
}
|
||||
implicitDeclarationsFile.declarations += declaration
|
||||
|
||||
return declaration
|
||||
|
||||
@@ -176,6 +176,7 @@ object JsIrBuilder {
|
||||
|
||||
fun buildVar(
|
||||
type: IrType,
|
||||
parent: IrDeclarationParent,
|
||||
name: String = "tmp",
|
||||
isVar: Boolean = false,
|
||||
isConst: Boolean = false,
|
||||
@@ -196,6 +197,7 @@ object JsIrBuilder {
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.initializer = initializer
|
||||
it.parent = parent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.transformFlat
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
@@ -101,7 +100,7 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
|
||||
}
|
||||
|
||||
private fun makeTempVar(type: IrType, init: IrExpression? = null) =
|
||||
JsIrBuilder.buildVar(type, initializer = init, isVar = true).also { it.parent = function }
|
||||
JsIrBuilder.buildVar(type, function, initializer = init, isVar = true)
|
||||
|
||||
private fun makeLoopLabel() = "\$l\$${tmpVarCounter++}"
|
||||
|
||||
@@ -538,8 +537,8 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
|
||||
private fun wrap(expression: IrExpression) =
|
||||
expression as? IrBlock ?: expression.let { IrBlockImpl(it.startOffset, it.endOffset, it.type, null, listOf(it)) }
|
||||
|
||||
private fun wrap(expression: IrExpression, variable: IrVariableSymbol) =
|
||||
wrap(JsIrBuilder.buildSetVariable(variable, expression, unitType))
|
||||
private fun wrap(expression: IrExpression, variable: IrVariable) =
|
||||
wrap(JsIrBuilder.buildSetVariable(variable.symbol, expression, unitType))
|
||||
|
||||
// try {
|
||||
// try_block {}
|
||||
@@ -561,9 +560,9 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
|
||||
override fun visitTry(aTry: IrTry): IrExpression {
|
||||
val irVar = makeTempVar(aTry.type)
|
||||
|
||||
val newTryResult = wrap(aTry.tryResult, irVar.symbol)
|
||||
val newTryResult = wrap(aTry.tryResult, irVar)
|
||||
val newCatches = aTry.catches.map {
|
||||
val newCatchBody = wrap(it.result, irVar.symbol)
|
||||
val newCatchBody = wrap(it.result, irVar)
|
||||
IrCatchImpl(it.startOffset, it.endOffset, it.catchParameter, newCatchBody)
|
||||
}
|
||||
|
||||
@@ -610,7 +609,7 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
|
||||
val irVar = makeTempVar(expression.type)
|
||||
|
||||
val newBranches = decomposedResults.map { (branch, condition, result) ->
|
||||
val newResult = wrap(result, irVar.symbol)
|
||||
val newResult = wrap(result, irVar)
|
||||
when (branch) {
|
||||
is IrElseBranch -> IrElseBranchImpl(branch.startOffset, branch.endOffset, condition, newResult)
|
||||
else /* IrBranch */ -> IrBranchImpl(branch.startOffset, branch.endOffset, condition, newResult)
|
||||
|
||||
+8
-5
@@ -30,14 +30,15 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.isStatic
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.ir.util.isReal
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
@@ -121,7 +122,10 @@ class BridgesConstruction(val context: JsIrBackendContext) : ClassLoweringPass {
|
||||
IrDeclarationOrigin.BRIDGE
|
||||
).apply {
|
||||
|
||||
dispatchReceiverParameter = bridge.dispatchReceiverParameter?.copyTo(this)
|
||||
// TODO: should dispatch receiver be copied?
|
||||
dispatchReceiverParameter = bridge.dispatchReceiverParameter?.run {
|
||||
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also { it.parent = this@apply }
|
||||
}
|
||||
extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this)
|
||||
typeParameters += bridge.typeParameters
|
||||
valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) }
|
||||
@@ -185,9 +189,8 @@ class FunctionAndSignature(val function: IrSimpleFunction) {
|
||||
|
||||
private val signature = Signature(
|
||||
function.name,
|
||||
// TODO: should kotlinTypes be used here?
|
||||
function.extensionReceiverParameter?.type?.toKotlinType()?.toString(),
|
||||
function.valueParameters.map { it.type.toKotlinType().toString() }
|
||||
function.extensionReceiverParameter?.type?.render(),
|
||||
function.valueParameters.map { it.type.render() }
|
||||
)
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
|
||||
+4
-8
@@ -210,9 +210,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
|
||||
val additionalDeclarations = generateGetterBodyWithGuard(refGetFunction) {
|
||||
val irClosureReference = JsIrBuilder.buildFunctionReference(functionReference.type, refClosureFunction.symbol)
|
||||
|
||||
val irVar = JsIrBuilder.buildVar(irClosureReference.type, initializer = irClosureReference).also {
|
||||
it.parent = refGetFunction
|
||||
}
|
||||
val irVar = JsIrBuilder.buildVar(irClosureReference.type, refGetFunction, initializer = irClosureReference)
|
||||
|
||||
// TODO: fill other fields of callable reference (returnType, parameters, isFinal, etc.)
|
||||
val irSetName = JsIrBuilder.buildCall(context.intrinsics.jsSetJSField.symbol).apply {
|
||||
@@ -261,7 +259,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
|
||||
val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1)
|
||||
val type = getterFunctionType.toIrType(symbolTable = context.symbolTable)
|
||||
val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol)
|
||||
val irVar = JsIrBuilder.buildVar(type, initializer = irGetReference).also { it.parent = refGetFunction }
|
||||
val irVar = JsIrBuilder.buildVar(type, refGetFunction, initializer = irGetReference)
|
||||
|
||||
statements += irVar
|
||||
|
||||
@@ -331,7 +329,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
|
||||
val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1)
|
||||
val type = getterFunctionType.toIrType(symbolTable = context.symbolTable)
|
||||
val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol)
|
||||
val irVar = JsIrBuilder.buildVar(type = type, initializer = irGetReference).also { it.parent = refGetFunction }
|
||||
val irVar = JsIrBuilder.buildVar(type, refGetFunction, initializer = irGetReference)
|
||||
val irVarSymbol = irVar.symbol
|
||||
|
||||
statements += irVar
|
||||
@@ -374,9 +372,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
|
||||
val cacheName = "${getterFunction.name}_${Namer.KCALLABLE_CACHE_SUFFIX}"
|
||||
val type = getterFunction.returnType
|
||||
val irNull = JsIrBuilder.buildNull(context.irBuiltIns.nothingNType)
|
||||
val cacheVar = JsIrBuilder.buildVar(type, cacheName, true, initializer = irNull).also {
|
||||
it.parent = getterFunction.parent
|
||||
}
|
||||
val cacheVar = JsIrBuilder.buildVar(type, getterFunction.parent, cacheName, true, initializer = irNull)
|
||||
|
||||
val irCacheValue = JsIrBuilder.buildGetValue(cacheVar.symbol)
|
||||
val irIfCondition = JsIrBuilder.buildCall(context.irBuiltIns.eqeqSymbol).apply {
|
||||
|
||||
+3
-3
@@ -317,7 +317,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
|
||||
val symbol = call.symbol
|
||||
val declaration = symbol.owner
|
||||
|
||||
if (declaration.isDynamic || declaration.isEffectivelyExternal()) {
|
||||
if (declaration.isDynamic() || declaration.isEffectivelyExternal()) {
|
||||
when (call.origin) {
|
||||
IrStatementOrigin.GET_PROPERTY -> {
|
||||
val fieldSymbol = context.symbolTable.lazyWrapper.referenceField(
|
||||
@@ -340,7 +340,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration.isDynamic) {
|
||||
if (declaration.isDynamic()) {
|
||||
dynamicCallOriginToIrFunction[call.origin]?.let {
|
||||
return irCall(call, it.symbol, dispatchReceiverAsFirstArgument = true)
|
||||
}
|
||||
@@ -416,7 +416,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
|
||||
it.name == Name.identifier("equals")
|
||||
&& it.valueParameters.size == 1
|
||||
&& rhs.isSubtypeOf(it.valueParameters[0].type)
|
||||
&& !it./*descriptor.*/isFakeOverriddenFromAny()
|
||||
&& !it.isFakeOverriddenFromAny()
|
||||
}
|
||||
.maxWith( // Find the most specific function
|
||||
Comparator { f1, f2 ->
|
||||
|
||||
+1
-1
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.inline.addChild
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass {
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ class MultipleCatchesLowering(val context: JsIrBackendContext) : FileLoweringPas
|
||||
|
||||
val commonType = mergeTypes(aTry.catches.map { it.catchParameter.type })
|
||||
|
||||
val pendingExceptionDeclaration = JsIrBuilder.buildVar(commonType, "\$p").apply { parent = data }
|
||||
val pendingExceptionDeclaration = JsIrBuilder.buildVar(commonType, data, "\$p")
|
||||
val pendingException = JsIrBuilder.buildGetValue(pendingExceptionDeclaration.symbol)
|
||||
|
||||
val branches = mutableListOf<IrBranch>()
|
||||
|
||||
+1
-1
@@ -257,7 +257,7 @@ class SecondaryCtorLowering(val context: JsIrBackendContext) {
|
||||
newTarget: IrSimpleFunctionSymbol
|
||||
) = IrCallImpl(call.startOffset, call.endOffset, call.type, newTarget).apply {
|
||||
|
||||
copyTypeArgumentsFrom(call)
|
||||
// copyTypeArgumentsFrom(call)
|
||||
|
||||
for (i in 0 until call.valueArgumentsCount) {
|
||||
putValueArgument(i, call.getValueArgument(i))
|
||||
|
||||
+3
-2
@@ -6,7 +6,8 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.utils.*
|
||||
import org.jetbrains.kotlin.backend.common.utils.getPrimitiveArrayElementType
|
||||
import org.jetbrains.kotlin.backend.common.utils.isPrimitiveArray
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrArithBuilder
|
||||
@@ -178,7 +179,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
newStatements: MutableList<IrStatement>,
|
||||
declaration: IrDeclarationParent
|
||||
): IrExpression {
|
||||
val varDeclaration = JsIrBuilder.buildVar(value.type, initializer = value).apply { parent = declaration }
|
||||
val varDeclaration = JsIrBuilder.buildVar(value.type, declaration, initializer = value)
|
||||
newStatements += varDeclaration
|
||||
return JsIrBuilder.buildGetValue(varDeclaration.symbol)
|
||||
}
|
||||
|
||||
+2
-2
@@ -75,7 +75,7 @@ class StateMachineBuilder(
|
||||
|
||||
val entryState = SuspendState(unit)
|
||||
val rootExceptionTrap = buildExceptionTrapState()
|
||||
private val globalExceptionVar = JsIrBuilder.buildVar(exceptionSymbol.owner.type, "e").also { it.parent = function.owner }
|
||||
private val globalExceptionVar = JsIrBuilder.buildVar(exceptionSymbol.owner.type, function.owner, "e")
|
||||
lateinit var globalCatch: IrCatch
|
||||
|
||||
fun finalizeStateMachine() {
|
||||
@@ -719,5 +719,5 @@ class StateMachineBuilder(
|
||||
)
|
||||
|
||||
private fun tempVar(type: IrType, name: String = "tmp") =
|
||||
JsIrBuilder.buildVar(type, name).also { it.parent = function.owner }
|
||||
JsIrBuilder.buildVar(type, function.owner, name)
|
||||
}
|
||||
+8
-7
@@ -789,14 +789,15 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
|
||||
dataArgument = function.valueParameters[0]
|
||||
exceptionArgument = function.valueParameters[1]
|
||||
suspendResult = JsIrBuilder.buildVar(context.irBuiltIns.anyNType, "suspendResult", true).also {
|
||||
it.parent = function
|
||||
it.initializer = JsIrBuilder.buildGetValue(dataArgument.symbol)
|
||||
}
|
||||
suspendResult = JsIrBuilder.buildVar(
|
||||
context.irBuiltIns.anyNType,
|
||||
function,
|
||||
"suspendResult",
|
||||
true,
|
||||
initializer = JsIrBuilder.buildGetValue(dataArgument.symbol)
|
||||
)
|
||||
|
||||
suspendState = JsIrBuilder.buildVar(coroutineImplLabelFieldSymbol.owner.type, "suspendState", true).also {
|
||||
it.parent = function
|
||||
}
|
||||
suspendState = JsIrBuilder.buildVar(coroutineImplLabelFieldSymbol.owner.type, function, "suspendState", true)
|
||||
|
||||
val body =
|
||||
(originalBody as IrBlockBody).run {
|
||||
|
||||
+1
-2
@@ -102,8 +102,7 @@ private class ReturnableBlockTransformer(
|
||||
if (expression !is IrReturnableBlock) return super.visitContainerExpression(expression, data)
|
||||
|
||||
val variable by lazy {
|
||||
JsIrBuilder.buildVar(expression.type, "tmp\$ret\$${data.labelCnt++}", true)
|
||||
.also { it.parent = data.containingDeclaration }
|
||||
JsIrBuilder.buildVar(expression.type, data.containingDeclaration, "tmp\$ret\$${data.labelCnt++}", true)
|
||||
}
|
||||
|
||||
val loop by lazy {
|
||||
|
||||
-1
@@ -46,7 +46,6 @@ class JsGenerationContext {
|
||||
|
||||
fun getNameForSymbol(symbol: IrSymbol): JsName = staticContext.getNameForSymbol(symbol, this)
|
||||
fun getNameForType(type: IrType): JsName = staticContext.getNameForType(type, this)
|
||||
// fun getNameForReceiver(symbol: IrValueSymbol, isExt: Boolean): JsName = staticContext.getNameForReceiver(symbol, isExt, this)
|
||||
fun getNameForLoop(loop: IrLoop): JsName? = staticContext.getNameForLoop(loop, this)
|
||||
|
||||
val continuation
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ class SimpleNameGenerator : NameGenerator {
|
||||
|
||||
val descriptor = declaration.descriptor
|
||||
|
||||
if (declaration.isDynamic) {
|
||||
if (declaration.isDynamic()) {
|
||||
return@getOrPut nameDeclarator(declaration.descriptor.name.asString())
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -178,8 +178,8 @@ class JvmSharedVariablesManager(
|
||||
)
|
||||
return IrVariableImpl(
|
||||
originalDeclaration.startOffset, originalDeclaration.endOffset, originalDeclaration.origin,
|
||||
sharedVariableSymbol, sharedVariableDescriptor.type.toIrType()!!, refConstructorCall
|
||||
)
|
||||
sharedVariableSymbol, sharedVariableDescriptor.type.toIrType()!!
|
||||
).apply { initializer = refConstructorCall }
|
||||
}
|
||||
|
||||
override fun defineSharedValue(
|
||||
|
||||
+19
-41
@@ -8,52 +8,46 @@ package org.jetbrains.kotlin.backend.jvm.lower
|
||||
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER
|
||||
import org.jetbrains.kotlin.backend.common.lower.InitializersLowering.Companion.clinitName
|
||||
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.backend.common.lower.VariableRemapperDesc
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.createParameterDeclarations
|
||||
import org.jetbrains.kotlin.ir.util.isInterface
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
|
||||
class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid(), ClassLoweringPass {
|
||||
class InterfaceLowering(val context: JvmBackendContext) : IrElementTransformerVoid(), ClassLoweringPass {
|
||||
|
||||
val state = context.state
|
||||
|
||||
override fun lower(irClass: IrClass) {
|
||||
if (!irClass.isInterface) return
|
||||
|
||||
val interfaceDescriptor = irClass.descriptor
|
||||
val defaultImplsDescriptor = createDefaultImplsClassDescriptor(interfaceDescriptor)
|
||||
val defaultImplsIrClass =
|
||||
IrClassImpl(irClass.startOffset, irClass.endOffset, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS, defaultImplsDescriptor)
|
||||
val defaultImplsIrClass = context.declarationFactory.getDefaultImplsClass(irClass)
|
||||
irClass.declarations.add(defaultImplsIrClass)
|
||||
|
||||
val members = defaultImplsIrClass.declarations
|
||||
|
||||
irClass.declarations.filterIsInstance<IrFunction>().forEach {
|
||||
val descriptor = it.descriptor
|
||||
if (it.origin == DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER) {
|
||||
members.add(it) //just copy $default to DefaultImpls
|
||||
} else if (descriptor.modality != Modality.ABSTRACT) {
|
||||
val functionDescriptorImpl =
|
||||
createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper)
|
||||
members.add(functionDescriptorImpl.createFunctionAndMapVariables(it, it.visibility))
|
||||
} else if (descriptor.modality != Modality.ABSTRACT && it.origin != IrDeclarationOrigin.FAKE_OVERRIDE) {
|
||||
val element = context.declarationFactory.getDefaultImplsFunction(it)
|
||||
members.add(element)
|
||||
element.body = it.body
|
||||
it.body = null
|
||||
//TODO reset modality to abstract
|
||||
}
|
||||
@@ -76,24 +70,6 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
|
||||
irClass.declarations.removeAll(privateToRemove)
|
||||
irClass.declarations.removeAll(defaultBodies)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun createDefaultImplsClassDescriptor(interfaceDescriptor: ClassDescriptor): DefaultImplsClassDescriptorImpl {
|
||||
return DefaultImplsClassDescriptorImpl(
|
||||
Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME), interfaceDescriptor, interfaceDescriptor.source
|
||||
)
|
||||
}
|
||||
|
||||
fun createDefaultImplFunDescriptor(
|
||||
defaultImplsDescriptor: DefaultImplsClassDescriptorImpl,
|
||||
descriptor: FunctionDescriptor,
|
||||
interfaceDescriptor: ClassDescriptor, typeMapper: KotlinTypeMapper
|
||||
): SimpleFunctionDescriptorImpl {
|
||||
val name = Name.identifier(typeMapper.mapAsmMethod(descriptor).name)
|
||||
return createStaticFunctionWithReceivers(defaultImplsDescriptor, name, descriptor, interfaceDescriptor.defaultType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,18 +111,20 @@ internal fun createStaticFunctionWithReceivers(
|
||||
|
||||
internal fun FunctionDescriptor.createFunctionAndMapVariables(
|
||||
oldFunction: IrFunction,
|
||||
visibility: Visibility
|
||||
visibility: Visibility = oldFunction.visibility,
|
||||
origin: IrDeclarationOrigin = oldFunction.origin
|
||||
) =
|
||||
IrFunctionImpl(
|
||||
oldFunction.startOffset, oldFunction.endOffset, oldFunction.origin, IrSimpleFunctionSymbolImpl(this),
|
||||
oldFunction.startOffset, oldFunction.endOffset, origin, IrSimpleFunctionSymbolImpl(this),
|
||||
visibility = visibility
|
||||
).apply {
|
||||
body = oldFunction.body
|
||||
returnType = oldFunction.returnType
|
||||
createParameterDeclarations()
|
||||
val mapping: Map<IrValueParameter, IrValueParameter> =
|
||||
(listOfNotNull(oldFunction.dispatchReceiverParameter!!, oldFunction.extensionReceiverParameter) + oldFunction.valueParameters)
|
||||
.zip(valueParameters).toMap()
|
||||
// TODO: do we really need descriptor here? This workaround is about coping `dispatchReceiver` descriptor
|
||||
val mapping: Map<ValueDescriptor, IrValueParameter> =
|
||||
(listOfNotNull(oldFunction.dispatchReceiverParameter!!.descriptor, oldFunction.extensionReceiverParameter?.descriptor) + oldFunction.valueParameters.map { it.descriptor })
|
||||
.zip(valueParameters).toMap()
|
||||
|
||||
body?.transform(VariableRemapper(mapping), null)
|
||||
body?.transform(VariableRemapperDesc(mapping), null)
|
||||
}
|
||||
|
||||
@@ -242,7 +242,6 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
ktConstructorElement.pureStartOffset, ktConstructorElement.pureEndOffset, IrDeclarationOrigin.DEFINED,
|
||||
constructorDescriptor
|
||||
).buildWithScope { irConstructor ->
|
||||
declarationGenerator.generateScopedTypeParameterDeclarations(irConstructor, constructorDescriptor.typeParameters)
|
||||
generateValueParameterDeclarations(irConstructor, ktParametersElement, null)
|
||||
irConstructor.body = createBodyGenerator(irConstructor.symbol).generateBody()
|
||||
irConstructor.returnType = constructorDescriptor.returnType.toIrType()
|
||||
|
||||
@@ -55,24 +55,6 @@ 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,
|
||||
@@ -81,7 +63,6 @@ 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,
|
||||
|
||||
+2
-7
@@ -5,14 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.declarations.lazy
|
||||
|
||||
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.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
|
||||
|
||||
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
|
||||
|
||||
@@ -158,7 +158,6 @@ 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) {
|
||||
@@ -331,7 +330,6 @@ fun IrCall.isSuperToAny() = superQualifier?.let { this.symbol.owner.isFakeOverri
|
||||
|
||||
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()
|
||||
@@ -339,7 +337,7 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
val IrDeclaration.isDynamic get() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType
|
||||
fun IrDeclaration.isDynamic() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType
|
||||
|
||||
fun IrValueParameter.copy(newDescriptor: ParameterDescriptor): IrValueParameter {
|
||||
assert(this.descriptor.type == newDescriptor.type)
|
||||
|
||||
Reference in New Issue
Block a user