From 32d1fbacbfcb152df3b32ee9e5dbe71e9b79650d Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Thu, 23 Mar 2023 10:06:46 +0100 Subject: [PATCH] [JS IR] De-optimize equality operator as workaround for KT-57509 --- .../EqualityAndComparisonCallsTransformer.kt | 5 +++-- .../kotlin/js/test/BoxJsTestGenerated.java | 6 ++++++ .../js/test/fir/FirJsBoxTestGenerated.java | 6 ++++++ .../js/test/ir/IrBoxJsES6TestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrBoxJsTestGenerated.java | 6 ++++++ .../box/dynamic/lambdaParameterInlining.kt | 17 +++++++++++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/EqualityAndComparisonCallsTransformer.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/EqualityAndComparisonCallsTransformer.kt index 0a4cb3d08650a..8aee58d71c541 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/EqualityAndComparisonCallsTransformer.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/calls/EqualityAndComparisonCallsTransformer.kt @@ -84,8 +84,9 @@ class EqualityAndComparisonCallsTransformer(context: JsIrBackendContext) : Calls val equalsMethod = lhs.type.findEqualsMethod() return when { - lhs.type is IrDynamicType -> - irCall(call, intrinsics.jsEqeq) +// Temporarily de-optimize dynamic equality due to KT-57509 +// lhs.type is IrDynamicType -> +// irCall(call, intrinsics.jsEqeq) // Special optimization for " == null" lhs.isNullConst() || rhs.isNullConst() -> diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java index 93cd8793d4d03..074b391153765 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java @@ -1664,6 +1664,12 @@ public void testIterator() throws Exception { runTest("js/js.translator/testData/box/dynamic/iterator.kt"); } + @Test + @TestMetadata("lambdaParameterInlining.kt") + public void testLambdaParameterInlining() throws Exception { + runTest("js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt"); + } + @Test @TestMetadata("nameClashing.kt") public void testNameClashing() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index 1ded5fc71b198..b826b7c968efe 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -1728,6 +1728,12 @@ public void testIterator() throws Exception { runTest("js/js.translator/testData/box/dynamic/iterator.kt"); } + @Test + @TestMetadata("lambdaParameterInlining.kt") + public void testLambdaParameterInlining() throws Exception { + runTest("js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt"); + } + @Test @TestMetadata("operationsWithAssignment.kt") public void testOperationsWithAssignment() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java index cf492125cdf44..c085ffbd166f4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java @@ -1728,6 +1728,12 @@ public void testIterator() throws Exception { runTest("js/js.translator/testData/box/dynamic/iterator.kt"); } + @Test + @TestMetadata("lambdaParameterInlining.kt") + public void testLambdaParameterInlining() throws Exception { + runTest("js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt"); + } + @Test @TestMetadata("operationsWithAssignment.kt") public void testOperationsWithAssignment() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index c0df910ec4c0d..9bed7cb60223a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -1728,6 +1728,12 @@ public void testIterator() throws Exception { runTest("js/js.translator/testData/box/dynamic/iterator.kt"); } + @Test + @TestMetadata("lambdaParameterInlining.kt") + public void testLambdaParameterInlining() throws Exception { + runTest("js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt"); + } + @Test @TestMetadata("operationsWithAssignment.kt") public void testOperationsWithAssignment() throws Exception { diff --git a/js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt b/js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt new file mode 100644 index 0000000000000..54e9bed70346b --- /dev/null +++ b/js/js.translator/testData/box/dynamic/lambdaParameterInlining.kt @@ -0,0 +1,17 @@ +// WITH_STDLIB + +fun demo(x: dynamic, a: Array): Boolean? { + return a.any { y: Any -> + val newX: Any = x.unsafeCast() + y == newX + } +} + +data class X(val x: Int) + +fun box(): String { + + if (demo(X(1), arrayOf(X(1))) != true) return "fail" + + return "OK" +} \ No newline at end of file