Skip to content

Commit

Permalink
Rewrite obsolete forgotten intrinsic test (#2647)
Browse files Browse the repository at this point in the history
that should be part of da020f9 (#2642) commit. See that commit message for reasoning.
  • Loading branch information
sandwwraith committed May 6, 2024
1 parent 251bca7 commit 84a2171
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 17 additions & 0 deletions core/jvmTest/src/kotlinx/serialization/CachingTest.kt
Expand Up @@ -60,4 +60,21 @@ class CachingTest {
val ser3 = serializer(typeOf<Target>())
assertTrue(SERIALIZERS_CACHE.isStored(Target::class), "Serializer should be stored in cache after typeOf-based lookup")
}

@Serializable
class Target2

inline fun <reified T : Any> indirect(): KSerializer<T> = serializer<T>()

@Test
fun testJvmIntrinsicsIndirect() {
val ser1 = Target2.serializer()
assertFalse(SERIALIZERS_CACHE.isStored(Target2::class), "Cache shouldn't have values before call to serializer<T>()")
val ser2 = indirect<Target2>()
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<Target2> was not intrinsified." +
"Check that compiler plugin intrinsics are enabled and working correctly."
)
}
}
Expand Up @@ -275,18 +275,4 @@ class SerializerByTypeTest {
serializer(typeTokenOf<Array<NonSerializable>>())
}
}

@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")
}
}

0 comments on commit 84a2171

Please sign in to comment.