Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite obsolete forgotten intrinsic test #2647

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/jvmTest/src/kotlinx/serialization/CachingTest.kt
Original file line number Diff line number Diff line change
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."
)
}
}
Original file line number Diff line number Diff line change
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")
}
}