From 41a69ad388abbe8667301376b4e0ebbc4b9490af Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Fri, 17 Sep 2021 11:57:38 +0200 Subject: [PATCH] [WASM] Add receiver capturing to callable references --- .../lower/WasmCallableReferenceLowering.kt | 64 +++++----- .../adaptedVarargFunImportedFromObject.kt | 3 +- .../adaptedReferences/inlineBound.kt | 3 +- .../innerConstructorWithVararg.kt | 3 +- .../noNameClashForReferencesToSameFunction.kt | 3 +- .../codegen/box/callableReference/arrayOf.kt | 2 - .../box/callableReference/bound/adapted.kt | 3 +- .../bound/arrayConstructorArgument.kt | 3 +- .../bound/arrayGetIntrinsic.kt | 3 +- .../boundReferenceToOverloadedFunction.kt | 3 +- .../callableReference/bound/coercionToUnit.kt | 3 +- .../bound/companionObjectReceiver.kt | 3 +- .../bound/dontShareReceiver.kt | 3 +- .../box/callableReference/bound/emptyLHS.kt | 2 +- .../bound/enumEntryMember.kt | 2 +- .../bound/equals/nullableReceiverInEquals.kt | 2 +- .../bound/equals/receiverInEquals.kt | 2 +- .../genericBoundPropertyAsCrossinline.kt | 2 +- .../bound/genericValOnLHS.kt | 2 +- .../bound/kCallableNameIntrinsic.kt | 2 +- .../box/callableReference/bound/kt12738.kt | 3 +- .../box/callableReference/bound/kt15446.kt | 3 +- .../box/callableReference/bound/multiCase.kt | 2 +- .../callableReference/bound/objectReceiver.kt | 3 +- .../bound/primitiveReceiver.kt | 3 +- .../bound/receiverEvaluatedOnce.kt | 3 +- .../callableReference/bound/simpleFunction.kt | 3 +- .../function/argumentTypesNoinline.kt | 3 +- .../innerClassConstructorWithTwoReceivers.kt | 3 +- .../box/callableReference/function/kt47741.kt | 1 - .../function/referenceToCompanionMember.kt | 2 +- .../genericConstructorReference.kt | 3 +- .../genericLocalClassConstructorReference.kt | 3 +- .../property/localClassVar.kt | 32 +++-- ...entTypeDuringStarProjectionSubstitution.kt | 3 +- .../boundInnerContructorRef.kt | 1 - .../boundMemberRef.kt | 1 - .../box/enum/kt7257_boundReference1.kt | 3 +- .../testData/codegen/box/functions/kt47449.kt | 1 - .../kt46597_method.kt | 2 - .../adaptedReferences/inlineBound.kt | 3 +- .../IrCodegenBoxWasmTestGenerated.java | 120 ++++++++++++++++++ 42 files changed, 204 insertions(+), 110 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmCallableReferenceLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmCallableReferenceLowering.kt index 71cd754ec96..f241f0e6ff8 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmCallableReferenceLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmCallableReferenceLowering.kt @@ -15,12 +15,8 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.wasm.WasmBackendContext import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.Modality -import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.builders.* -import org.jetbrains.kotlin.ir.builders.declarations.addConstructor -import org.jetbrains.kotlin.ir.builders.declarations.addFunction -import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter -import org.jetbrains.kotlin.ir.builders.declarations.buildClass +import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl @@ -40,7 +36,8 @@ val IrStatementOrigin?.isLambda: Boolean get() = this == IrStatementOrigin.LAMBDA || this == IrStatementOrigin.ANONYMOUS_FUNCTION // Originally copied from K/Native -internal class WasmCallableReferenceLowering(private val context: WasmBackendContext) : FileLoweringPass, IrElementTransformerVoidWithContext() { +internal class WasmCallableReferenceLowering(private val context: WasmBackendContext) : FileLoweringPass, + IrElementTransformerVoidWithContext() { // This pass ignores suspend function references and function references used in inline arguments to inline functions. private val ignoredFunctionReferences = mutableSetOf() @@ -110,6 +107,7 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon // The type of the reference is KFunction private val parameterTypes = (irFunctionReference.type as IrSimpleType).arguments.map { (it as IrTypeProjection).type } private val argumentTypes = parameterTypes.dropLast(1) + private val referenceReturnType = parameterTypes.last() private val typeArgumentsMap = irFunctionReference.typeSubstitutionMap @@ -147,6 +145,7 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon if (isLambda) { this.metadata = irFunctionReference.symbol.owner.metadata } + addField("receiver", context.irBuiltIns.anyNType) } // WASM(TODO) @@ -227,6 +226,13 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon // } } +IrInstanceInitializerCallImpl(startOffset, endOffset, functionReferenceClass.symbol, context.irBuiltIns.unitType) + if (samSuperType == null && boundReceiver != null) { + +irSetField( + irGet(functionReferenceClass.thisReceiver!!), + functionReferenceClass.fields.first(), + irGet(valueParameters.first()) + ) + } } } @@ -260,11 +266,11 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon } } - body = context.createIrBuilder(symbol).run { + body = context.createIrBuilder(symbol, startOffset, endOffset).run { var unboundIndex = 0 - irExprBody(irCall(callee).apply { - for ((typeParameter, typeArgument) in typeArgumentsMap) { - putTypeArgument(typeParameter.owner.index, typeArgument) + val call = irCall(callee.symbol, referenceReturnType).apply { + for (typeParameter in irFunctionReference.symbol.owner.allTypeParameters) { + putTypeArgument(typeParameter.index, typeArgumentsMap[typeParameter.symbol]) } for (parameter in callee.explicitParameters) { @@ -273,30 +279,16 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon // Bound receiver parameter. For function references, this is stored in a field of the superclass. // For sam references, we just capture the value in a local variable and LocalDeclarationsLowering // will put it into a field. -// if (samSuperType == null) -// irImplicitCast( -// irGetField(irGet(dispatchReceiverParameter!!), fakeOverrideReceiverField), -// boundReceiver.second.type -// ) -// else - irGet(receiver ?: error("Binding receivers is not supported yet")) - - // If a vararg parameter corresponds to exactly one KFunction argument, which is an array, that array - // is forwarded as is. - // - // fun f(x: (Int, Array) -> String) = x(0, arrayOf("OK", "FAIL")) - // fun h(i: Int, vararg xs: String) = xs[i] - // f(::h) - // - parameter.isVararg && unboundIndex < argumentTypes.size && parameter.type == valueParameters[unboundIndex].type -> - irGet(valueParameters[unboundIndex++]) - // In all other cases, excess arguments are packed into a new array. - // - // fun g(x: (Int, String, String) -> String) = x(0, "OK", "FAIL") - // f(::h) == g(::h) - // - parameter.isVararg && (unboundIndex < argumentTypes.size || !parameter.hasDefaultValue()) -> - TODO() + if (samSuperType == null) + irImplicitCast( + irGetField( + irGet(dispatchReceiverParameter!!), + functionReferenceClass.fields.first(), + ), + boundReceiver.second.type + ) + else + irGet(receiver!!) unboundIndex >= argumentTypes.size -> // Default value argument (this pass doesn't handle suspend functions, otherwise @@ -307,7 +299,9 @@ internal class WasmCallableReferenceLowering(private val context: WasmBackendCon irGet(valueParameters[unboundIndex++]) }?.let { putArgument(callee, parameter, it) } } - }) + } + + irExprBody(call) } } } diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt index 6a61b65f2cf..5ff2a5a1f04 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + import Host.foo diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/inlineBound.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/inlineBound.kt index 37ea82ef9d5..f816ba9fdaa 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/inlineBound.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/inlineBound.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + inline fun foo(x: () -> Unit): String { x() diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt index 3b81bddcfd8..c44b0def730 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType class Outer(val o: String) { diff --git a/compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt b/compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt index 00bdd943452..868697204c4 100644 --- a/compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt +++ b/compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + var result = "" class C(val token: String) { diff --git a/compiler/testData/codegen/box/callableReference/arrayOf.kt b/compiler/testData/codegen/box/callableReference/arrayOf.kt index a425f272421..639fdd97178 100644 --- a/compiler/testData/codegen/box/callableReference/arrayOf.kt +++ b/compiler/testData/codegen/box/callableReference/arrayOf.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM - fun use(fn: (Array) -> Array) = fn(arrayOf("OK")) diff --git a/compiler/testData/codegen/box/callableReference/bound/adapted.kt b/compiler/testData/codegen/box/callableReference/bound/adapted.kt index 51836aecdd1..7bea0adfe0f 100644 --- a/compiler/testData/codegen/box/callableReference/bound/adapted.kt +++ b/compiler/testData/codegen/box/callableReference/bound/adapted.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + class C { fun ffff(i: Int, s: String = "OK") = s } diff --git a/compiler/testData/codegen/box/callableReference/bound/arrayConstructorArgument.kt b/compiler/testData/codegen/box/callableReference/bound/arrayConstructorArgument.kt index 14a744bb7de..02953c875bb 100644 --- a/compiler/testData/codegen/box/callableReference/bound/arrayConstructorArgument.kt +++ b/compiler/testData/codegen/box/callableReference/bound/arrayConstructorArgument.kt @@ -1,6 +1,5 @@ // WITH_RUNTIME -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + class C(val x: String) { fun foo(i: Int): Char = x[i] } diff --git a/compiler/testData/codegen/box/callableReference/bound/arrayGetIntrinsic.kt b/compiler/testData/codegen/box/callableReference/bound/arrayGetIntrinsic.kt index d2b65908df7..2e367377469 100644 --- a/compiler/testData/codegen/box/callableReference/bound/arrayGetIntrinsic.kt +++ b/compiler/testData/codegen/box/callableReference/bound/arrayGetIntrinsic.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun box(): String { return if ((arrayOf(1, 2, 3)::get)(1) == 2) "OK" else "Fail" } diff --git a/compiler/testData/codegen/box/callableReference/bound/boundReferenceToOverloadedFunction.kt b/compiler/testData/codegen/box/callableReference/bound/boundReferenceToOverloadedFunction.kt index cfa74463e72..7a832aa9cc7 100644 --- a/compiler/testData/codegen/box/callableReference/bound/boundReferenceToOverloadedFunction.kt +++ b/compiler/testData/codegen/box/callableReference/bound/boundReferenceToOverloadedFunction.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // !LANGUAGE: +NewInference interface JsonParser diff --git a/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt b/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt index 0a65921290b..ff8e680118e 100644 --- a/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt +++ b/compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // KJS_WITH_FULL_RUNTIME // !LANGUAGE: +NewInference // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt b/compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt index 0881f432f0a..de6f3e28552 100644 --- a/compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt +++ b/compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + class A { companion object { fun ok() = "OK" diff --git a/compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt b/compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt index 894e9b1d080..5c132e699e2 100644 --- a/compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt +++ b/compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun box(): String { var state = 0 diff --git a/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt b/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt index 5ce879ab6de..574504af81c 100644 --- a/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt +++ b/compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES var result = "" class A { diff --git a/compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt b/compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt index adb11ae577c..3a8b7a555d8 100644 --- a/compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt +++ b/compiler/testData/codegen/box/callableReference/bound/enumEntryMember.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: FUNCTION_REFERENCES // IGNORE_BACKEND: JS, JS_IR // IGNORE_BACKEND: JS_IR_ES6 enum class E { diff --git a/compiler/testData/codegen/box/callableReference/bound/equals/nullableReceiverInEquals.kt b/compiler/testData/codegen/box/callableReference/bound/equals/nullableReceiverInEquals.kt index 660a7feb821..c10403daed2 100644 --- a/compiler/testData/codegen/box/callableReference/bound/equals/nullableReceiverInEquals.kt +++ b/compiler/testData/codegen/box/callableReference/bound/equals/nullableReceiverInEquals.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/callableReference/bound/equals/receiverInEquals.kt b/compiler/testData/codegen/box/callableReference/bound/equals/receiverInEquals.kt index 717e5c0822e..5b7dc8a6737 100644 --- a/compiler/testData/codegen/box/callableReference/bound/equals/receiverInEquals.kt +++ b/compiler/testData/codegen/box/callableReference/bound/equals/receiverInEquals.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: FUNCTION_REFERENCES // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/callableReference/bound/genericBoundPropertyAsCrossinline.kt b/compiler/testData/codegen/box/callableReference/bound/genericBoundPropertyAsCrossinline.kt index 7598cc36e16..687d2dae3e8 100644 --- a/compiler/testData/codegen/box/callableReference/bound/genericBoundPropertyAsCrossinline.kt +++ b/compiler/testData/codegen/box/callableReference/bound/genericBoundPropertyAsCrossinline.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES // KT-30629 abstract class BaseFragment { diff --git a/compiler/testData/codegen/box/callableReference/bound/genericValOnLHS.kt b/compiler/testData/codegen/box/callableReference/bound/genericValOnLHS.kt index 50d169f3c97..87359c44f22 100644 --- a/compiler/testData/codegen/box/callableReference/bound/genericValOnLHS.kt +++ b/compiler/testData/codegen/box/callableReference/bound/genericValOnLHS.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES class Generic

(val p: P) class Host { diff --git a/compiler/testData/codegen/box/callableReference/bound/kCallableNameIntrinsic.kt b/compiler/testData/codegen/box/callableReference/bound/kCallableNameIntrinsic.kt index 99a03fc6984..c5a7b0132db 100644 --- a/compiler/testData/codegen/box/callableReference/bound/kCallableNameIntrinsic.kt +++ b/compiler/testData/codegen/box/callableReference/bound/kCallableNameIntrinsic.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES // SKIP_SOURCEMAP_REMAPPING fun box(): String { diff --git a/compiler/testData/codegen/box/callableReference/bound/kt12738.kt b/compiler/testData/codegen/box/callableReference/bound/kt12738.kt index 4a489ea9a34..2099e109715 100644 --- a/compiler/testData/codegen/box/callableReference/bound/kt12738.kt +++ b/compiler/testData/codegen/box/callableReference/bound/kt12738.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun get(t: T): () -> String { return t::toString } diff --git a/compiler/testData/codegen/box/callableReference/bound/kt15446.kt b/compiler/testData/codegen/box/callableReference/bound/kt15446.kt index eb21954874e..9e329576325 100644 --- a/compiler/testData/codegen/box/callableReference/bound/kt15446.kt +++ b/compiler/testData/codegen/box/callableReference/bound/kt15446.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // KJS_WITH_FULL_RUNTIME //WITH_RUNTIME fun box(): String { diff --git a/compiler/testData/codegen/box/callableReference/bound/multiCase.kt b/compiler/testData/codegen/box/callableReference/bound/multiCase.kt index dabb7b760c1..68fb7689e03 100644 --- a/compiler/testData/codegen/box/callableReference/bound/multiCase.kt +++ b/compiler/testData/codegen/box/callableReference/bound/multiCase.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: PROPERTY_REFERENCES // IGNORE_BACKEND: NATIVE class A(var v: Int) { fun f(x: Int) = x * v diff --git a/compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt b/compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt index 3e2ff238c41..4595a7aab50 100644 --- a/compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt +++ b/compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + object Singleton { fun ok() = "OK" } diff --git a/compiler/testData/codegen/box/callableReference/bound/primitiveReceiver.kt b/compiler/testData/codegen/box/callableReference/bound/primitiveReceiver.kt index 6b4db84d300..e30703ed526 100644 --- a/compiler/testData/codegen/box/callableReference/bound/primitiveReceiver.kt +++ b/compiler/testData/codegen/box/callableReference/bound/primitiveReceiver.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun Boolean.foo() = 1 fun Byte.foo() = 2 fun Short.foo() = 3 diff --git a/compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt b/compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt index ac1a19eda60..91093ff0e35 100644 --- a/compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt +++ b/compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + var x = 0 class A { diff --git a/compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt b/compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt index 418549b9ec8..c9741362c17 100644 --- a/compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt +++ b/compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun box(): String { val f = "KOTLIN"::get return "${f(1)}${f(0)}" diff --git a/compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt b/compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt index 757bc97d72d..3dda272008d 100644 --- a/compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt +++ b/compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + fun id(x: T): T = x fun String.extId(x: T): T = x diff --git a/compiler/testData/codegen/box/callableReference/function/innerClassConstructorWithTwoReceivers.kt b/compiler/testData/codegen/box/callableReference/function/innerClassConstructorWithTwoReceivers.kt index 1726532fc58..102c6ffcec7 100644 --- a/compiler/testData/codegen/box/callableReference/function/innerClassConstructorWithTwoReceivers.kt +++ b/compiler/testData/codegen/box/callableReference/function/innerClassConstructorWithTwoReceivers.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + abstract class A { inner class InnerInA { fun returnOk() = "OK" diff --git a/compiler/testData/codegen/box/callableReference/function/kt47741.kt b/compiler/testData/codegen/box/callableReference/function/kt47741.kt index a245c1ffb37..6603f6e3ec4 100644 --- a/compiler/testData/codegen/box/callableReference/function/kt47741.kt +++ b/compiler/testData/codegen/box/callableReference/function/kt47741.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: WASM fun box(): String { val generateId = (1 .. Int.MAX_VALUE).iterator()::next diff --git a/compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt b/compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt index 3be2c51a9dd..89d769e5440 100644 --- a/compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt +++ b/compiler/testData/codegen/box/callableReference/function/referenceToCompanionMember.kt @@ -1,5 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS +// WASM_MUTE_REASON: FUNCTION_REFERENCES // WITH_RUNTIME // IGNORE_BACKEND: JS diff --git a/compiler/testData/codegen/box/callableReference/genericConstructorReference.kt b/compiler/testData/codegen/box/callableReference/genericConstructorReference.kt index 2e014bfe5a8..aa560fde43c 100644 --- a/compiler/testData/codegen/box/callableReference/genericConstructorReference.kt +++ b/compiler/testData/codegen/box/callableReference/genericConstructorReference.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // KT-42025 open class L(val ll: LL) diff --git a/compiler/testData/codegen/box/callableReference/genericLocalClassConstructorReference.kt b/compiler/testData/codegen/box/callableReference/genericLocalClassConstructorReference.kt index 1b656b0ba80..3da01ec7497 100644 --- a/compiler/testData/codegen/box/callableReference/genericLocalClassConstructorReference.kt +++ b/compiler/testData/codegen/box/callableReference/genericLocalClassConstructorReference.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // KT-42025 open class L(val ll: LL) diff --git a/compiler/testData/codegen/box/callableReference/property/localClassVar.kt b/compiler/testData/codegen/box/callableReference/property/localClassVar.kt index e7c0cf06ccc..4c8ab93f604 100644 --- a/compiler/testData/codegen/box/callableReference/property/localClassVar.kt +++ b/compiler/testData/codegen/box/callableReference/property/localClassVar.kt @@ -1,11 +1,23 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: PROPERTY_REFERENCES -fun box(): String { - class Local { - var result = "Fail" - } - - val l = Local() - (Local::result).set(l, "OK") - return (Local::result).get(l) +class X(val ok: String) { + fun y(): String = ok } + +fun box(): String { + val x = X("OK") + val y = x::y + return y() +} + +//fun y(): String = "OK" +// +//fun box(): String { +// val y = ::y +// return y.invoke() +//} + +//val x = "OK" +// +//fun box(): String { +// val x = ::x +// return x.get() +//} \ No newline at end of file diff --git a/compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt b/compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt index ea126baa467..df78dbc33bf 100644 --- a/compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt +++ b/compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + interface I interface Foo diff --git a/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt index 79f36cc3295..de6c7f4db9d 100644 --- a/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt +++ b/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: WASM // CHECK_BYTECODE_TEXT // JVM_IR_TEMPLATES // 0 Function(^.)*.invoke diff --git a/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt index bbf17dbbd9f..0c0ffe939a6 100644 --- a/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt +++ b/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: WASM // CHECK_BYTECODE_TEXT // JVM_IR_TEMPLATES // 0 Function(^.)*.invoke diff --git a/compiler/testData/codegen/box/enum/kt7257_boundReference1.kt b/compiler/testData/codegen/box/enum/kt7257_boundReference1.kt index 27df4dc34ee..071d5fef979 100644 --- a/compiler/testData/codegen/box/enum/kt7257_boundReference1.kt +++ b/compiler/testData/codegen/box/enum/kt7257_boundReference1.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + enum class X { B { val k = "K" diff --git a/compiler/testData/codegen/box/functions/kt47449.kt b/compiler/testData/codegen/box/functions/kt47449.kt index 0cfeb255fb6..40823efe1a6 100644 --- a/compiler/testData/codegen/box/functions/kt47449.kt +++ b/compiler/testData/codegen/box/functions/kt47449.kt @@ -1,5 +1,4 @@ // IGNORE_BACKEND: JS -// IGNORE_BACKEND: WASM typealias EmptyFunctionResult = () -> T diff --git a/compiler/testData/codegen/box/syntheticAccessors/protectedMemberReferenceAccessor/kt46597_method.kt b/compiler/testData/codegen/box/syntheticAccessors/protectedMemberReferenceAccessor/kt46597_method.kt index ba47e6aed6a..a705956786d 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/protectedMemberReferenceAccessor/kt46597_method.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/protectedMemberReferenceAccessor/kt46597_method.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM - // FILE: a.kt package a diff --git a/compiler/testData/codegen/boxInline/callableReference/adaptedReferences/inlineBound.kt b/compiler/testData/codegen/boxInline/callableReference/adaptedReferences/inlineBound.kt index f381f4f6c99..826baa88d75 100644 --- a/compiler/testData/codegen/boxInline/callableReference/adaptedReferences/inlineBound.kt +++ b/compiler/testData/codegen/boxInline/callableReference/adaptedReferences/inlineBound.kt @@ -1,5 +1,4 @@ -// DONT_TARGET_EXACT_BACKEND: WASM -// WASM_MUTE_REASON: BINDING_RECEIVERS + // FILE: 1.kt package test diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 698c179459e..d903482665d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -1401,6 +1401,16 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/charArrayOf.kt"); } + @TestMetadata("genericConstructorReference.kt") + public void testGenericConstructorReference() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/genericConstructorReference.kt"); + } + + @TestMetadata("genericLocalClassConstructorReference.kt") + public void testGenericLocalClassConstructorReference() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/genericLocalClassConstructorReference.kt"); + } + @TestMetadata("inlineArrayConstructors.kt") public void testInlineArrayConstructors() throws Exception { runTest("compiler/testData/codegen/box/callableReference/inlineArrayConstructors.kt"); @@ -1434,6 +1444,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); } + @TestMetadata("adaptedVarargFunImportedFromObject.kt") + public void testAdaptedVarargFunImportedFromObject() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/adaptedVarargFunImportedFromObject.kt"); + } + public void testAllFilesPresentInAdaptedReferences() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/adaptedReferences"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } @@ -1443,6 +1458,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/defaultWithGenericExpectedType.kt"); } + @TestMetadata("inlineBound.kt") + public void testInlineBound() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/inlineBound.kt"); + } + @TestMetadata("inlineVarargAndDefault.kt") public void testInlineVarargAndDefault() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/inlineVarargAndDefault.kt"); @@ -1453,6 +1473,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/inlineVarargInts.kt"); } + @TestMetadata("innerConstructorWithVararg.kt") + public void testInnerConstructorWithVararg() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/innerConstructorWithVararg.kt"); + } + @TestMetadata("localFunctionWithDefault.kt") public void testLocalFunctionWithDefault() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/localFunctionWithDefault.kt"); @@ -1463,6 +1488,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/manyDefaultsAndVararg.kt"); } + @TestMetadata("noNameClashForReferencesToSameFunction.kt") + public void testNoNameClashForReferencesToSameFunction() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt"); + } + @TestMetadata("referenceToVarargWithDefaults.kt") public void testReferenceToVarargWithDefaults() throws Exception { runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/referenceToVarargWithDefaults.kt"); @@ -1525,10 +1555,30 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); } + @TestMetadata("adapted.kt") + public void testAdapted() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/adapted.kt"); + } + public void testAllFilesPresentInBound() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/bound"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("arrayConstructorArgument.kt") + public void testArrayConstructorArgument() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/arrayConstructorArgument.kt"); + } + + @TestMetadata("arrayGetIntrinsic.kt") + public void testArrayGetIntrinsic() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/arrayGetIntrinsic.kt"); + } + + @TestMetadata("boundReferenceToOverloadedFunction.kt") + public void testBoundReferenceToOverloadedFunction() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/boundReferenceToOverloadedFunction.kt"); + } + @TestMetadata("captureVarInInitBlock.kt") public void testCaptureVarInInitBlock() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/captureVarInInitBlock.kt"); @@ -1539,6 +1589,51 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/bound/captureVarInPropertyInit.kt"); } + @TestMetadata("coercionToUnit.kt") + public void testCoercionToUnit() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/coercionToUnit.kt"); + } + + @TestMetadata("companionObjectReceiver.kt") + public void testCompanionObjectReceiver() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt"); + } + + @TestMetadata("dontShareReceiver.kt") + public void testDontShareReceiver() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt"); + } + + @TestMetadata("kt12738.kt") + public void testKt12738() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/kt12738.kt"); + } + + @TestMetadata("kt15446.kt") + public void testKt15446() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/kt15446.kt"); + } + + @TestMetadata("objectReceiver.kt") + public void testObjectReceiver() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/objectReceiver.kt"); + } + + @TestMetadata("primitiveReceiver.kt") + public void testPrimitiveReceiver() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/primitiveReceiver.kt"); + } + + @TestMetadata("receiverEvaluatedOnce.kt") + public void testReceiverEvaluatedOnce() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/receiverEvaluatedOnce.kt"); + } + + @TestMetadata("simpleFunction.kt") + public void testSimpleFunction() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/bound/simpleFunction.kt"); + } + @TestMetadata("smartCastForExtensionReceiver.kt") public void testSmartCastForExtensionReceiver() throws Exception { runTest("compiler/testData/codegen/box/callableReference/bound/smartCastForExtensionReceiver.kt"); @@ -1608,6 +1703,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt"); } + @TestMetadata("argumentTypesNoinline.kt") + public void testArgumentTypesNoinline() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt"); + } + @TestMetadata("booleanNotIntrinsic.kt") public void testBooleanNotIntrinsic() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/booleanNotIntrinsic.kt"); @@ -1703,6 +1803,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/callableReference/function/genericMember.kt"); } + @TestMetadata("innerClassConstructorWithTwoReceivers.kt") + public void testInnerClassConstructorWithTwoReceivers() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/function/innerClassConstructorWithTwoReceivers.kt"); + } + @TestMetadata("innerConstructorFromClass.kt") public void testInnerConstructorFromClass() throws Exception { runTest("compiler/testData/codegen/box/callableReference/function/innerConstructorFromClass.kt"); @@ -1923,6 +2028,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testAllFilesPresentInProperty() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference/property"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + + @TestMetadata("localClassVar.kt") + public void testLocalClassVar() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/property/localClassVar.kt"); + } } @TestMetadata("compiler/testData/codegen/box/callableReference/serializability") @@ -1971,6 +2081,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/casts/castGenericNull.kt"); } + @TestMetadata("dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt") + public void testDontCreateInconsistentTypeDuringStarProjectionSubstitution() throws Exception { + runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt"); + } + @TestMetadata("intersectionTypeMultipleBounds.kt") public void testIntersectionTypeMultipleBounds() throws Exception { runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt"); @@ -5590,6 +5705,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/enum/kt7257_anonObjectMethod.kt"); } + @TestMetadata("kt7257_boundReference1.kt") + public void testKt7257_boundReference1() throws Exception { + runTest("compiler/testData/codegen/box/enum/kt7257_boundReference1.kt"); + } + @TestMetadata("kt7257_explicitReceiver.kt") public void testKt7257_explicitReceiver() throws Exception { runTest("compiler/testData/codegen/box/enum/kt7257_explicitReceiver.kt");