From a4cb70af31550696145c9a7a127a94a98ac73445 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Fri, 9 Apr 2021 13:27:34 +0300 Subject: [PATCH] JS IR: gather statement origins in one place Preparing to serialize lowered IR --- .../lower/DefaultArgumentStubGenerator.kt | 6 ++--- .../common/lower/InitializersLowering.kt | 4 +-- .../common/lower/LocalDeclarationsLowering.kt | 5 +--- .../kotlin/backend/common/lower/Origins.kt | 14 ++++++++++ .../ir/backend/js/DeclarationOrigins.kt | 1 - .../kotlin/ir/backend/js/ir/IrBuilder.kt | 26 ++++++++++--------- .../js/lower/CallableReferenceLowering.kt | 20 ++++++++------ .../lower/InteropCallableReferenceLowering.kt | 14 ++++------ .../lower/JsDefaultArgumentStubGenerator.kt | 11 ++++---- .../lower/calls/ReflectionCallsTransformer.kt | 4 +-- .../AbstractSuspendFunctionsLowering.kt | 1 - .../coroutines/JsSuspendFunctionsLowering.kt | 7 ++--- .../lower/coroutines/SuspendLoweringUtils.kt | 3 --- .../js/transformers/irToJs/jsAstUtils.kt | 4 +-- .../backend/jvm/codegen/ExpressionCodegen.kt | 4 +-- .../kotlin/ir/backend/js/StatementOrigins.kt | 21 +++++++++++++++ 16 files changed, 85 insertions(+), 60 deletions(-) create mode 100644 compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/Origins.kt create mode 100644 compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/StatementOrigins.kt diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt index 3596e83b2dd..980220244b9 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt @@ -281,8 +281,6 @@ private fun IrFunction.findBaseFunctionWithDefaultArguments(skipInlineMethods: B return dfsImpl() } -val DEFAULT_DISPATCH_CALL = object : IrStatementOriginImpl("DEFAULT_DISPATCH_CALL") {} - open class DefaultParameterInjector( open val context: CommonBackendContext, private val skipInline: Boolean = true, @@ -338,7 +336,7 @@ open class DefaultParameterInjector( expression.transformChildrenVoid() return visitFunctionAccessExpression(expression) { with(expression) { - IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, it as IrConstructorSymbol, DEFAULT_DISPATCH_CALL) + IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, it as IrConstructorSymbol, LoweredStatementOrigins.DEFAULT_DISPATCH_CALL) } } } @@ -364,7 +362,7 @@ open class DefaultParameterInjector( startOffset, endOffset, type, it as IrSimpleFunctionSymbol, typeArgumentsCount = typeArgumentsCount, valueArgumentsCount = it.owner.valueParameters.size, - origin = DEFAULT_DISPATCH_CALL, + origin = LoweredStatementOrigins.DEFAULT_DISPATCH_CALL, superQualifierSymbol = superQualifierSymbol ) } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InitializersLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InitializersLowering.kt index cb4ac075bd8..76dd4ddc75d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InitializersLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InitializersLowering.kt @@ -23,8 +23,6 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid -object SYNTHESIZED_INIT_BLOCK : IrStatementOriginImpl("SYNTHESIZED_INIT_BLOCK") - class InitializersLowering(context: CommonBackendContext) : InitializersLoweringBase(context), BodyLoweringPass { override fun lower(irFile: IrFile) { runOnFilePostfix(irFile, true) @@ -88,7 +86,7 @@ abstract class InitializersLoweringBase(open val context: CommonBackendContext) private fun handleAnonymousInitializer(declaration: IrAnonymousInitializer): IrStatement = with(declaration) { - IrBlockImpl(startOffset, endOffset, context.irBuiltIns.unitType, SYNTHESIZED_INIT_BLOCK, body.statements) + IrBlockImpl(startOffset, endOffset, context.irBuiltIns.unitType, LoweredStatementOrigins.SYNTHESIZED_INIT_BLOCK, body.statements) } } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt index 1d2e219acac..d985b7bc24e 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt @@ -90,9 +90,6 @@ class LocalDeclarationsLowering( object DECLARATION_ORIGIN_FIELD_FOR_CROSSINLINE_CAPTURED_VALUE : IrDeclarationOriginImpl("FIELD_FOR_CROSSINLINE_CAPTURED_VALUE", isSynthetic = true) - private object STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE : - IrStatementOriginImpl("INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE") - override fun lower(irBody: IrBody, container: IrDeclaration) { LocalDeclarationsTransformer(irBody, container, null).lowerLocalDeclarations() } @@ -490,7 +487,7 @@ class LocalDeclarationsLowering( IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irClass.thisReceiver!!.symbol), constructorContext.irGet(UNDEFINED_OFFSET, UNDEFINED_OFFSET, capturedValue)!!, context.irBuiltIns.unitType, - STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE + LoweredStatementOrigins.STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE ) } ) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/Origins.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/Origins.kt new file mode 100644 index 00000000000..ceeb8d579f5 --- /dev/null +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/Origins.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2021 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.backend.common.lower + +import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl + +interface LoweredStatementOrigins { + object STATEMENT_ORIGIN_INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE : IrStatementOriginImpl("INITIALIZER_OF_FIELD_FOR_CAPTURED_VALUE") + object SYNTHESIZED_INIT_BLOCK : IrStatementOriginImpl("SYNTHESIZED_INIT_BLOCK") + object DEFAULT_DISPATCH_CALL : IrStatementOriginImpl("DEFAULT_DISPATCH_CALL") +} \ No newline at end of file diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt index 2f25ae96ec0..40a538fcbb6 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/DeclarationOrigins.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl object JsLoweredDeclarationOrigin : IrDeclarationOrigin { object JS_INTRINSICS_STUB : IrDeclarationOriginImpl("JS_INTRINSICS_STUB") - object JS_CLOSURE_BOX_CLASS : IrStatementOriginImpl("JS_CLOSURE_BOX_CLASS") object JS_CLOSURE_BOX_CLASS_DECLARATION : IrDeclarationOriginImpl("JS_CLOSURE_BOX_CLASS_DECLARATION") object BRIDGE_WITH_STABLE_NAME : IrDeclarationOriginImpl("BRIDGE_WITH_STABLE_NAME") object BRIDGE_WITHOUT_STABLE_NAME : IrDeclarationOriginImpl("BRIDGE_WITHOUT_STABLE_NAME") diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt index 21b3509d7af..be0eedac161 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/ir/IrBuilder.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.ir.backend.js.ir +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter @@ -18,14 +19,14 @@ import org.jetbrains.kotlin.name.Name object JsIrBuilder { - object SYNTHESIZED_STATEMENT : IrStatementOriginImpl("SYNTHESIZED_STATEMENT") + object SYNTHESIZED_DECLARATION : IrDeclarationOriginImpl("SYNTHESIZED_DECLARATION") fun buildCall( target: IrSimpleFunctionSymbol, type: IrType? = null, typeArguments: List? = null, - origin: IrStatementOrigin = SYNTHESIZED_STATEMENT + origin: IrStatementOrigin = JsStatementOrigins.SYNTHESIZED_STATEMENT ): IrCall { val owner = target.owner return IrCallImpl( @@ -61,10 +62,10 @@ object JsIrBuilder { IrGetObjectValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, classSymbol) fun buildGetValue(symbol: IrValueSymbol) = - IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, symbol.owner.type, symbol, SYNTHESIZED_STATEMENT) + IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, symbol.owner.type, symbol, JsStatementOrigins.SYNTHESIZED_STATEMENT) fun buildSetVariable(symbol: IrVariableSymbol, value: IrExpression, type: IrType) = - IrSetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, symbol, value, SYNTHESIZED_STATEMENT) + IrSetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, symbol, value, JsStatementOrigins.SYNTHESIZED_STATEMENT) fun buildGetField(symbol: IrFieldSymbol, receiver: IrExpression?, superQualifierSymbol: IrClassSymbol? = null, type: IrType? = null) = IrGetFieldImpl( @@ -73,7 +74,7 @@ object JsIrBuilder { symbol, type ?: symbol.owner.type, receiver, - SYNTHESIZED_STATEMENT, + JsStatementOrigins.SYNTHESIZED_STATEMENT, superQualifierSymbol ) @@ -84,17 +85,18 @@ object JsIrBuilder { type: IrType, superQualifierSymbol: IrClassSymbol? = null ) = - IrSetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, symbol, receiver, value, type, SYNTHESIZED_STATEMENT, superQualifierSymbol) + IrSetFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, symbol, receiver, value, type, + JsStatementOrigins.SYNTHESIZED_STATEMENT, superQualifierSymbol) - fun buildBlock(type: IrType) = IrBlockImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, SYNTHESIZED_STATEMENT) + fun buildBlock(type: IrType) = IrBlockImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, JsStatementOrigins.SYNTHESIZED_STATEMENT) fun buildBlock(type: IrType, statements: List) = - IrBlockImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, SYNTHESIZED_STATEMENT, statements) + IrBlockImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, JsStatementOrigins.SYNTHESIZED_STATEMENT, statements) fun buildComposite(type: IrType, statements: List = emptyList()) = - IrCompositeImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, SYNTHESIZED_STATEMENT, statements) + IrCompositeImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, JsStatementOrigins.SYNTHESIZED_STATEMENT, statements) fun buildFunctionExpression(type: IrType, function: IrSimpleFunction) = - IrFunctionExpressionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, function, SYNTHESIZED_STATEMENT) + IrFunctionExpressionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, function, JsStatementOrigins.SYNTHESIZED_STATEMENT) fun buildVar( type: IrType, @@ -122,7 +124,7 @@ object JsIrBuilder { fun buildContinue(type: IrType, loop: IrLoop) = IrContinueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop) fun buildIfElse(type: IrType, cond: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression? = null): IrWhen = buildIfElse( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, cond, thenBranch, elseBranch, SYNTHESIZED_STATEMENT + UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, cond, thenBranch, elseBranch, JsStatementOrigins.SYNTHESIZED_STATEMENT ) fun buildIfElse( @@ -144,7 +146,7 @@ object JsIrBuilder { return element } - fun buildWhen(type: IrType, branches: List, origin: IrStatementOrigin = SYNTHESIZED_STATEMENT) = + fun buildWhen(type: IrType, branches: List, origin: IrStatementOrigin = JsStatementOrigins.SYNTHESIZED_STATEMENT) = IrWhenImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, origin, branches) fun buildTypeOperator(type: IrType, operator: IrTypeOperator, argument: IrExpression, toType: IrType) = diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt index a1db9b40b11..2feac29f5fe 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/CallableReferenceLowering.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor import org.jetbrains.kotlin.backend.common.ir.moveBodyTo +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.runOnFilePostfix import org.jetbrains.kotlin.descriptors.DescriptorVisibilities @@ -59,7 +60,10 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod return expression.run { val vpCount = if (function.isSuspend) 1 else 0 val ctorCall = - IrConstructorCallImpl(startOffset, endOffset, type, ctor.symbol, 0 /*TODO: properly set type arguments*/, 0, vpCount, CALLABLE_REFERENCE_CREATE).apply { + IrConstructorCallImpl( + startOffset, endOffset, type, ctor.symbol, 0 /*TODO: properly set type arguments*/, 0, vpCount, + JsStatementOrigins.CALLABLE_REFERENCE_CREATE + ).apply { if (function.isSuspend) { putValueArgument(0, IrConstImpl.constNull(startOffset, endOffset, context.irBuiltIns.nothingNType)) } @@ -81,7 +85,8 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod val ctorCall = IrConstructorCallImpl( startOffset, endOffset, type, ctor.symbol, 0 /*TODO: properly set type arguments*/, 0, - vpCount, CALLABLE_REFERENCE_CREATE).apply { + vpCount, JsStatementOrigins.CALLABLE_REFERENCE_CREATE + ).apply { boundReceiver?.let { putValueArgument(0, it) } @@ -215,7 +220,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod } fun getValue(d: IrValueDeclaration): IrGetValue = - IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, d.type, d.symbol, CALLABLE_REFERENCE_INVOKE) + IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, d.type, d.symbol, JsStatementOrigins.CALLABLE_REFERENCE_INVOKE) /** inner class IN { @@ -252,7 +257,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod callee.countContextTypeParameters(), callee.typeParameters.size, callee.valueParameters.size, - CALLABLE_REFERENCE_INVOKE + JsStatementOrigins.CALLABLE_REFERENCE_INVOKE ) is IrSimpleFunction -> IrCallImpl( @@ -262,7 +267,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod callee.symbol, callee.typeParameters.size, callee.valueParameters.size, - CALLABLE_REFERENCE_INVOKE + JsStatementOrigins.CALLABLE_REFERENCE_INVOKE ) else -> error("unknown function kind: ${callee.render()}") @@ -299,7 +304,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod boundReceiverField.symbol, boundReceiverField.type, thisValue, - CALLABLE_REFERENCE_INVOKE + JsStatementOrigins.CALLABLE_REFERENCE_INVOKE ) if (funRef.dispatchReceiver != null) irCall.dispatchReceiver = value @@ -396,8 +401,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod object FUNCTION_REFERENCE_IMPL : IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL") object GENERATED_MEMBER_IN_CALLABLE_REFERENCE : IrDeclarationOriginImpl("GENERATED_MEMBER_IN_CALLABLE_REFERENCE") - object CALLABLE_REFERENCE_CREATE : IrStatementOriginImpl("CALLABLE_REFERENCE_CREATE") - object CALLABLE_REFERENCE_INVOKE : IrStatementOriginImpl("CALLABLE_REFERENCE_INVOKE") + val THIS_NAME = Name.special("") val BOUND_RECEIVER_NAME = Name.identifier("\$boundThis") diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/InteropCallableReferenceLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/InteropCallableReferenceLowering.kt index 846a9bed6d8..937c8ac184b 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/InteropCallableReferenceLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/InteropCallableReferenceLowering.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower import org.jetbrains.kotlin.backend.common.BodyLoweringPass import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.backend.common.ir.copyToWithoutSuperTypes +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET @@ -39,7 +40,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo inner class CallableReferenceLowerTransformer : IrElementTransformerVoid() { override fun visitConstructorCall(expression: IrConstructorCall): IrExpression { expression.transformChildrenVoid(this) - if (expression.origin === CallableReferenceLowering.Companion.CALLABLE_REFERENCE_CREATE) { + if (expression.origin === JsStatementOrigins.CALLABLE_REFERENCE_CREATE) { return transformToJavaScriptFunction(expression) } return expression @@ -76,7 +77,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo invokeFun.symbol, 0, invokeFun.valueParameters.size, - EXPLICIT_INVOKE, + JsStatementOrigins.EXPLICIT_INVOKE, null ) @@ -162,7 +163,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo nameGetter.symbol, 0, 0, - CallableReferenceLowering.Companion.CALLABLE_REFERENCE_INVOKE + JsStatementOrigins.CALLABLE_REFERENCE_INVOKE ).apply { dispatchReceiver = JsIrBuilder.buildGetValue(instanceVal.symbol) } @@ -204,7 +205,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo visibility = lambdaClass.visibility returnType = expression.type name = factoryName - origin = FACTORY_ORIGIN + origin = JsStatementOrigins.FACTORY_ORIGIN } factoryDeclaration.parent = implicitDeclarationFile @@ -229,9 +230,4 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo arguments += value } } - - companion object { - object EXPLICIT_INVOKE : IrStatementOriginImpl("EXPLICIT_INVOKE") - object FACTORY_ORIGIN : IrDeclarationOriginImpl("FACTORY_ORIGIN") - } } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsDefaultArgumentStubGenerator.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsDefaultArgumentStubGenerator.kt index 9d1af0b0a5f..b18d560222d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsDefaultArgumentStubGenerator.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsDefaultArgumentStubGenerator.kt @@ -10,7 +10,8 @@ import org.jetbrains.kotlin.backend.common.deepCopyWithVariables import org.jetbrains.kotlin.backend.common.ir.copyAnnotationsWhen import org.jetbrains.kotlin.backend.common.ir.isOverridableOrOverrides import org.jetbrains.kotlin.backend.common.lower.DefaultArgumentStubGenerator -import org.jetbrains.kotlin.backend.common.lower.DEFAULT_DISPATCH_CALL +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins +import org.jetbrains.kotlin.backend.common.lower.LoweredStatementOrigins import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.utils.JsAnnotations import org.jetbrains.kotlin.ir.builders.IrBlockBodyBuilder @@ -67,14 +68,12 @@ class JsDefaultArgumentStubGenerator(override val context: JsIrBackendContext) : } } -val BIND_CALL = object : IrStatementOriginImpl("BIND_CALL") {} - class JsDefaultCallbackGenerator(val context: JsIrBackendContext): BodyLoweringPass { override fun lower(irBody: IrBody, container: IrDeclaration) { irBody.transformChildrenVoid(object : IrElementTransformerVoid() { override fun visitCall(expression: IrCall): IrExpression { super.visitCall(expression) - if (expression.origin != DEFAULT_DISPATCH_CALL || expression.superQualifierSymbol == null) return expression + if (expression.origin != LoweredStatementOrigins.DEFAULT_DISPATCH_CALL || expression.superQualifierSymbol == null) return expression val binding = buildBoundSuperCall(expression) @@ -98,7 +97,7 @@ class JsDefaultCallbackGenerator(val context: JsIrBackendContext): BodyLoweringP typeArgumentsCount = 0, valueArgumentsCount = originalFunction.valueParameters.size, reflectionTarget = originalFunction.symbol, - origin = BIND_CALL + origin = JsStatementOrigins.BIND_CALL ) } @@ -110,7 +109,7 @@ class JsDefaultCallbackGenerator(val context: JsIrBackendContext): BodyLoweringP context.intrinsics.jsBind, valueArgumentsCount = 2, typeArgumentsCount = 0, - origin = BIND_CALL, + origin = JsStatementOrigins.BIND_CALL, superQualifierSymbol = superQualifierSymbol ) }.apply { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/ReflectionCallsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/ReflectionCallsTransformer.kt index 7dc196c89b0..e242b0ae20b 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/ReflectionCallsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/ReflectionCallsTransformer.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.ir.backend.js.lower.calls +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext -import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering import org.jetbrains.kotlin.ir.backend.js.utils.Namer import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrDynamicMemberExpressionImpl @@ -35,7 +35,7 @@ class ReflectionCallsTransformer(private val context: JsIrBackendContext) : Call addWithPredicate( Name.special(Namer.KCALLABLE_GET_NAME), { call -> - call.origin != CallableReferenceLowering.Companion.CALLABLE_REFERENCE_INVOKE && + call.origin != JsStatementOrigins.CALLABLE_REFERENCE_INVOKE && call.symbol.owner.dispatchReceiverParameter?.run { type.isSubtypeOfClass(context.irBuiltIns.kCallableClass) } ?: false }, { call -> diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt index 10cd43be21a..fd0e3916c67 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt @@ -37,7 +37,6 @@ abstract class AbstractSuspendFunctionsLowering(val co private var IrFunction.coroutineConstructor by context.mapping.suspendFunctionToCoroutineConstructor - protected object STATEMENT_ORIGIN_COROUTINE_IMPL : IrStatementOriginImpl("COROUTINE_IMPL") protected object DECLARATION_ORIGIN_COROUTINE_IMPL : IrDeclarationOriginImpl("COROUTINE_IMPL") protected abstract val stateMachineMethodName: Name diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt index 20b8c77661c..c28e902a7a9 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/JsSuspendFunctionsLowering.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js.lower.coroutines import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName import org.jetbrains.kotlin.backend.common.ir.isSuspend import org.jetbrains.kotlin.backend.common.lower.FinallyBlocksLowering +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.backend.common.lower.ReturnableBlockTransformer import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder @@ -62,7 +63,7 @@ class JsSuspendFunctionsLowering(ctx: JsIrBackendContext) : AbstractSuspendFunct simplifiedFunction.startOffset, simplifiedFunction.endOffset, context.irBuiltIns.unitType, - STATEMENT_ORIGIN_COROUTINE_IMPL, + JsStatementOrigins.STATEMENT_ORIGIN_COROUTINE_IMPL, originalBody.statements ) @@ -81,7 +82,7 @@ class JsSuspendFunctionsLowering(ctx: JsIrBackendContext) : AbstractSuspendFunct val unit = context.irBuiltIns.unitType - val switch = IrWhenImpl(body.startOffset, body.endOffset, unit, COROUTINE_SWITCH) + val switch = IrWhenImpl(body.startOffset, body.endOffset, unit, JsStatementOrigins.COROUTINE_SWITCH) val stateVar = JsIrBuilder.buildVar(context.irBuiltIns.intType, stateMachineFunction) val switchBlock = IrBlockImpl(switch.startOffset, switch.endOffset, switch.type).apply { statements += stateVar @@ -92,7 +93,7 @@ class JsSuspendFunctionsLowering(ctx: JsIrBackendContext) : AbstractSuspendFunct body.startOffset, body.endOffset, unit, - COROUTINE_ROOT_LOOP, + JsStatementOrigins.COROUTINE_ROOT_LOOP, ).also { it.condition = JsIrBuilder.buildBoolean(context.irBuiltIns.booleanType, true) it.body = rootTry diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt index 10b5c24d95c..10fe01f50d9 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/SuspendLoweringUtils.kt @@ -20,9 +20,6 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.isUnit import org.jetbrains.kotlin.ir.visitors.* -object COROUTINE_ROOT_LOOP : IrStatementOriginImpl("COROUTINE_ROOT_LOOP") -object COROUTINE_SWITCH : IrStatementOriginImpl("COROUTINE_SWITCH") - open class SuspendableNodesCollector(private val suspendableNodes: MutableSet) : IrElementVisitorVoid { private var hasSuspendableChildren = false diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt index d0947108e68..325a36f628c 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/jsAstUtils.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs import org.jetbrains.kotlin.backend.common.ir.isElseBranch import org.jetbrains.kotlin.backend.common.ir.isSuspend -import org.jetbrains.kotlin.ir.backend.js.lower.InteropCallableReferenceLowering +import org.jetbrains.kotlin.ir.backend.js.JsStatementOrigins import org.jetbrains.kotlin.ir.backend.js.utils.* import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction @@ -86,7 +86,7 @@ private fun isFunctionTypeInvoke(receiver: JsExpression?, call: IrCall): Boolean val simpleFunction = call.symbol.owner as? IrSimpleFunction ?: return false val receiverType = simpleFunction.dispatchReceiverParameter?.type ?: return false - if (call.origin === InteropCallableReferenceLowering.Companion.EXPLICIT_INVOKE) return false + if (call.origin === JsStatementOrigins.EXPLICIT_INVOKE) return false return simpleFunction.name == OperatorNameConventions.INVOKE && receiverType.isFunctionTypeOrSubtype() } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index f9bc604834e..562926ff256 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -6,7 +6,7 @@ package org.jetbrains.kotlin.backend.jvm.codegen import org.jetbrains.kotlin.backend.common.lower.BOUND_RECEIVER_PARAMETER -import org.jetbrains.kotlin.backend.common.lower.SYNTHESIZED_INIT_BLOCK +import org.jetbrains.kotlin.backend.common.lower.LoweredStatementOrigins import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods @@ -369,7 +369,7 @@ class ExpressionCodegen( override fun visitBlock(expression: IrBlock, data: BlockInfo): PromisedValue { assert(expression !is IrReturnableBlock) { "unlowered returnable block: ${expression.dump()}" } - val isSynthesizedInitBlock = expression.origin == SYNTHESIZED_INIT_BLOCK + val isSynthesizedInitBlock = expression.origin == LoweredStatementOrigins.SYNTHESIZED_INIT_BLOCK if (isSynthesizedInitBlock) { expression.markLineNumber(startOffset = true) mv.nop() diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/StatementOrigins.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/StatementOrigins.kt new file mode 100644 index 00000000000..0da49c5ddda --- /dev/null +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/StatementOrigins.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2021 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.ir.backend.js + +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl +import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl + +interface JsStatementOrigins { + object BIND_CALL : IrStatementOriginImpl("BIND_CALL") + object STATEMENT_ORIGIN_COROUTINE_IMPL : IrStatementOriginImpl("COROUTINE_IMPL") + object SYNTHESIZED_STATEMENT : IrStatementOriginImpl("SYNTHESIZED_STATEMENT") + object CALLABLE_REFERENCE_CREATE : IrStatementOriginImpl("CALLABLE_REFERENCE_CREATE") + object CALLABLE_REFERENCE_INVOKE : IrStatementOriginImpl("CALLABLE_REFERENCE_INVOKE") + object EXPLICIT_INVOKE : IrStatementOriginImpl("EXPLICIT_INVOKE") + object FACTORY_ORIGIN : IrDeclarationOriginImpl("FACTORY_ORIGIN") + object COROUTINE_ROOT_LOOP : IrStatementOriginImpl("COROUTINE_ROOT_LOOP") + object COROUTINE_SWITCH : IrStatementOriginImpl("COROUTINE_SWITCH") +} \ No newline at end of file