From 84a21717f2f30b896783f273119e7f14231a2556 Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Mon, 6 May 2024 18:24:16 +0200 Subject: [PATCH] Rewrite obsolete forgotten intrinsic test (#2647) that should be part of da020f9730ffbac18b380ef25f9a9a3e09745946 (#2642) commit. See that commit message for reasoning. --- .../src/kotlinx/serialization/CachingTest.kt | 17 +++++++++++++++++ .../features/SerializerByTypeTest.kt | 14 -------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/jvmTest/src/kotlinx/serialization/CachingTest.kt b/core/jvmTest/src/kotlinx/serialization/CachingTest.kt index 686ac473a..634fb0071 100644 --- a/core/jvmTest/src/kotlinx/serialization/CachingTest.kt +++ b/core/jvmTest/src/kotlinx/serialization/CachingTest.kt @@ -60,4 +60,21 @@ class CachingTest { val ser3 = serializer(typeOf()) assertTrue(SERIALIZERS_CACHE.isStored(Target::class), "Serializer should be stored in cache after typeOf-based lookup") } + + @Serializable + class Target2 + + inline fun indirect(): KSerializer = serializer() + + @Test + fun testJvmIntrinsicsIndirect() { + val ser1 = Target2.serializer() + assertFalse(SERIALIZERS_CACHE.isStored(Target2::class), "Cache shouldn't have values before call to serializer()") + val ser2 = indirect() + assertFalse( + SERIALIZERS_CACHE.isStored(Target2::class), + "Serializer for Target2::class is stored in the cache, which means that runtime lookup was performed and call to serializer was not intrinsified." + + "Check that compiler plugin intrinsics are enabled and working correctly." + ) + } } diff --git a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt index a600b9d71..94a83fda8 100644 --- a/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt +++ b/formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt @@ -275,18 +275,4 @@ class SerializerByTypeTest { serializer(typeTokenOf>()) } } - - @OptIn(ExperimentalTime::class) - @Test - fun testSerializersAreIntrinsified() { - val direct = measureTime { - Json.encodeToString(IntData.serializer(), IntData(10)) - } - val directMs = direct.inWholeMicroseconds - val indirect = measureTime { - Json.encodeToString(IntData(10)) - } - val indirectMs = indirect.inWholeMicroseconds - if (indirectMs > directMs + (directMs / 4)) error("Direct ($directMs) and indirect ($indirectMs) times are too far apart") - } }