[Wasm] Boolean boxed instances are the same

Fixed #KT-65411
This commit is contained in:
Igor Yakovlev
2024-02-09 17:01:12 +01:00
committed by Space Team
parent a171f774be
commit a5ef668e3c
28 changed files with 190 additions and 7 deletions
@@ -2494,6 +2494,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2494,6 +2494,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -224,6 +224,8 @@ class WasmSymbols(
symbolTable.descriptorExtension.referenceSimpleFunction(it)
}
val getBoxedBoolean: IrSimpleFunctionSymbol = getInternalFunction("getBoxedBoolean")
val boxBoolean: IrSimpleFunctionSymbol = getInternalFunction("boxBoolean")
val boxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("boxIntrinsic")
val unboxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("unboxIntrinsic")
@@ -78,12 +78,23 @@ internal class WasmUsefulDeclarationProcessor(
context.wasmSymbols.wasmTypeId,
context.wasmSymbols.refCastNull,
context.wasmSymbols.refTest,
context.wasmSymbols.boxIntrinsic,
context.wasmSymbols.wasmArrayCopy -> {
call.getTypeArgument(0)?.enqueueRuntimeClassOrAny(from, "intrinsic ${call.symbol.owner.name}")
true
}
context.wasmSymbols.boxIntrinsic -> {
val type = call.getTypeArgument(0)!!
if (type == context.irBuiltIns.booleanType) {
context.wasmSymbols.getBoxedBoolean.owner.enqueue(from, "intrinsic boxIntrinsic")
} else {
type.enqueueRuntimeClassOrAny(from, "intrinsic boxIntrinsic")
}
true
}
context.wasmSymbols.boxBoolean -> {
context.irBuiltIns.booleanType.enqueueRuntimeClassOrAny(from, "intrinsic boxBoolean")
true
}
else -> false
}
@@ -377,8 +377,18 @@ class BodyGenerator(
// Box intrinsic has an additional klass ID argument.
// Processing it separately
if (call.symbol == wasmSymbols.boxBoolean) {
generateBox(call.getValueArgument(0)!!, irBuiltIns.booleanType)
return
}
if (call.symbol == wasmSymbols.boxIntrinsic) {
generateBox(call.getValueArgument(0)!!, call.getTypeArgument(0)!!)
val type = call.getTypeArgument(0)!!
if (type == irBuiltIns.booleanType) {
generateExpression(call.getValueArgument(0)!!)
body.buildCall(context.referenceFunction(context.backendContext.wasmSymbols.getBoxedBoolean), location)
} else {
generateBox(call.getValueArgument(0)!!, type)
}
return
}
@@ -0,0 +1,13 @@
fun boxBoolean(b: Boolean): Any = b
fun box(): String {
if (boxBoolean(true) !== boxBoolean(true)) return "FAIL1"
if (boxBoolean(false) !== boxBoolean(false)) return "FAIL2"
if (boxBoolean(true) === boxBoolean(false)) return "FAIL3"
if (boxBoolean(false) === boxBoolean(true)) return "FAIL4"
if (boxBoolean(true) != boxBoolean(true)) return "FAIL5"
if (boxBoolean(false) != boxBoolean(false)) return "FAIL6"
if (boxBoolean(true) == boxBoolean(false)) return "FAIL7"
if (boxBoolean(false) == boxBoolean(true)) return "FAIL8"
return "OK"
}
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: WASM
fun box(): String {
fun a(a: Any) = a === 1.1 is Double
return if (a(true)) "OK" else "Fail"
+12 -2
View File
@@ -39,9 +39,19 @@ fun f(block: () -> Unit) {
// EXPECTATIONS WASM
// test.kt:1 $box
// test.kt:4 $box (12, 4)
// test.kt:4 $box (12, 12, 4)
// Runtime.kt:70 $kotlin.wasm.internal.getBoxedBoolean (8, 8)
// Runtime.kt:73 $kotlin.wasm.internal.getBoxedBoolean (8, 35)
// Standard.kt:71 $kotlin.wasm.internal.getBoxedBoolean (0, 0, 0, 0)
// Standard.kt:95 $kotlin.wasm.internal.getBoxedBoolean (4, 4)
// Standard.kt:98 $kotlin.wasm.internal.getBoxedBoolean (4, 10, 4, 4, 10, 4)
// Standard.kt:74 $kotlin.wasm.internal.getBoxedBoolean (15, 7)
// Standard.kt:99 $kotlin.wasm.internal.getBoxedBoolean (11, 4, 11, 4)
// Runtime.kt:74 $kotlin.wasm.internal.getBoxedBoolean (5, 5)
// test.kt:5 $box (6, 6, 4)
// test.kt:11 $f
// test.kt:6 $box$lambda.invoke (8, 12, 12, 12, 12, 8, 16)
// test.kt:6 $box$lambda.invoke (8, 12, 8, 16)
// Runtime.kt:71 $kotlin.wasm.internal.getBoxedBoolean (8, 33)
// Standard.kt:68 $kotlin.wasm.internal.getBoxedBoolean (25, 25, 25, 25, 45, 38)
// test.kt:12 $f
// test.kt:8 $box
@@ -2489,6 +2489,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2297,6 +2297,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2489,6 +2489,12 @@ public class FirBlackBoxCodegenTestWithInlineScopesGenerated extends AbstractFir
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -2186,6 +2186,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedIntegersCmp.kt");
@@ -1643,6 +1643,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1643,6 +1643,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1643,6 +1643,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1643,6 +1643,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -63,6 +63,20 @@ internal fun nullableDoubleIeee754Equals(lhs: Double?, rhs: Double?): Boolean {
return wasm_f64_eq(lhs, rhs)
}
private var TRUE: Boolean? = null
private var FALSE: Boolean? = null
internal fun getBoxedBoolean(x: Boolean): Boolean? =
if (x) {
TRUE ?: boxBoolean(true).also { TRUE = it }
} else {
FALSE ?: boxBoolean(false).also { FALSE = it }
}
@ExcludedFromCodegen
internal fun boxBoolean(x: Boolean): Boolean? =
implementedAsIntrinsic
@ExcludedFromCodegen
internal fun <T, R> boxIntrinsic(x: T): R =
implementedAsIntrinsic
@@ -1723,6 +1723,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1771,6 +1771,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1675,6 +1675,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1724,6 +1724,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1643,6 +1643,12 @@ public class FirWasmJsCodegenBoxTestGenerated extends AbstractFirWasmJsCodegenBo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {
@@ -1643,6 +1643,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/boxingOptimization"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@Test
@TestMetadata("boxedBooleanIdentity.kt")
public void testBoxedBooleanIdentity() {
runTest("compiler/testData/codegen/box/boxingOptimization/boxedBooleanIdentity.kt");
}
@Test
@TestMetadata("boxedIntegersCmp.kt")
public void testBoxedIntegersCmp() {