Skip to content

Commit 84a2171

Browse files
authored
Rewrite obsolete forgotten intrinsic test (#2647)
that should be part of da020f9 (#2642) commit. See that commit message for reasoning.
1 parent 251bca7 commit 84a2171

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

core/jvmTest/src/kotlinx/serialization/CachingTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,21 @@ class CachingTest {
6060
val ser3 = serializer(typeOf<Target>())
6161
assertTrue(SERIALIZERS_CACHE.isStored(Target::class), "Serializer should be stored in cache after typeOf-based lookup")
6262
}
63+
64+
@Serializable
65+
class Target2
66+
67+
inline fun <reified T : Any> indirect(): KSerializer<T> = serializer<T>()
68+
69+
@Test
70+
fun testJvmIntrinsicsIndirect() {
71+
val ser1 = Target2.serializer()
72+
assertFalse(SERIALIZERS_CACHE.isStored(Target2::class), "Cache shouldn't have values before call to serializer<T>()")
73+
val ser2 = indirect<Target2>()
74+
assertFalse(
75+
SERIALIZERS_CACHE.isStored(Target2::class),
76+
"Serializer for Target2::class is stored in the cache, which means that runtime lookup was performed and call to serializer<Target2> was not intrinsified." +
77+
"Check that compiler plugin intrinsics are enabled and working correctly."
78+
)
79+
}
6380
}

formats/json-tests/jvmTest/src/kotlinx/serialization/features/SerializerByTypeTest.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,4 @@ class SerializerByTypeTest {
275275
serializer(typeTokenOf<Array<NonSerializable>>())
276276
}
277277
}
278-
279-
@OptIn(ExperimentalTime::class)
280-
@Test
281-
fun testSerializersAreIntrinsified() {
282-
val direct = measureTime {
283-
Json.encodeToString(IntData.serializer(), IntData(10))
284-
}
285-
val directMs = direct.inWholeMicroseconds
286-
val indirect = measureTime {
287-
Json.encodeToString(IntData(10))
288-
}
289-
val indirectMs = indirect.inWholeMicroseconds
290-
if (indirectMs > directMs + (directMs / 4)) error("Direct ($directMs) and indirect ($indirectMs) times are too far apart")
291-
}
292278
}

0 commit comments

Comments
 (0)