-
Notifications
You must be signed in to change notification settings - Fork 622
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
Intrinsics for serializer() function #1348
Comments
When may we expect this proposal to be implemented? |
@NorbertSandor We can't give any particular timeframe for now, but we aim to provide this before Kotlin 1.6 |
If possible we would love to get it in Kotlin 1.7 for Spring needs, especially related to GraalVM native images. |
seems like this has been bumped several times. What work needs to be done here? Is there anything the community can do to help out? |
@snowe2010 The work has to be done in the compiler plugin — currently, they can't provide intrinsics, and we have to change that. I'm working at this task at the moment, and I hope I will be able to present results soon |
@sandwwraith ah, I see. thank you for your work! good luck! |
It's been some time since the last update on this issue. Is it fair to expect this fixed some time next year? |
It's already implemented in the not-yet-released Kotlin 1.8.0, stay tuned! |
Is it expected to be fixed with |
As there are some runtime functions this functionality depends on, intrinsics should be working once 1.5.0-RC is released |
I just tested it with Ktor, kontlinx.serialization 1.5.0-RC and plugin version 1.8.10 and it is not still does not work. Serialization fails in native image without reflection and Intrinsics are not used in generated JARs. @sandwwraith Is there anything else one need to configure to make it work? |
@morki Which function do you use? 1.8.0, which is used to compile 1.5.0-RC, has some subtle bug, and as a result, the |
@sandwwraith thank you for quick response. My code is actually like this: @Resource("/login")
@Serializable
data class LoginRoute(
val state: String? = null,
)
fun Route.registerLoginRoutes() {
get<LoginRoute> {
// TODO
}
} which calls function public inline fun <reified T : Any> Route.get(
noinline body: suspend PipelineContext<Unit, ApplicationCall>.(T) -> Unit
): Route {
lateinit var builtRoute: Route
resource<T> {
builtRoute = method(HttpMethod.Get) {
handle(body)
}
}
return builtRoute
} and it calls function public inline fun <reified T : Any> Route.resource(noinline body: Route.() -> Unit): Route {
val serializer = serializer<T>()
return resource(serializer, body)
} and it calls |
@sandwwraith sorry, my fault, it is because Ktor is precompiled with Kotlin 1.7.20, when I compiled locally and pushed to Maven local, all works fine :) |
Hm. I was seeing the issue still as well, but I think it's because we're using the encode and decode methods. |
This feature is fully functional now. Requirements are Kotlin 1.8.10+ and serialization core runtime 1.5.0+. |
In an unlikely occasion of problems with replacement, inlining can be disabled with |
Ran a series of tests with |
Currently, our format API can be used in two ways: with explicit serializer, and with inferred from the type parameters, for exaple:
We always promote usages of the latter, because it has the same meaning, but in the meantime is more expressive and concise. It is based on the experimental
typeOf
function and we are able to retrieve the serializer usingKType
.Unfortunately, it has two downsides:
Proposal
Introduce the notion of intrinsic to the serialization plugin.
serializer()
andserializerOfNull
are going to be evaluated in the compile-time. Additionally, this evaluation will happen transitively through allreified inline
functions that leverageserializer<T>
.To properly resolve context-specific serializers, more compact
contextualOrDefault(defaultSerializer)
function will be used instead.The text was updated successfully, but these errors were encountered: