question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intrinsics for serializer() function

See original GitHub issue

Currently, our format API can be used in two ways: with explicit serializer, and with inferred from the type parameters, for exaple:

// Explicit
val jsonString = Json.decodeToString(MyClass.serializer(), MyClass(...))
val data = Json.encodeFromString(MyClass.serializer(), jsonString)

// Implicit
val jsonString = Json.decodeToString(MyClass(...)) // Inferred type-parameter T
val data = Json.encodeFromString<MyClass>(jsonString) // Or data: MyClass = Json.encodeFromString(sonString)

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 using KType.

Unfortunately, it has two downsides:

Proposal

Introduce the notion of intrinsic to the serialization plugin. serializer() and serializerOfNull are going to be evaluated in the compile-time. Additionally, this evaluation will happen transitively through all reified inline functions that leverage serializer<T>.

To properly resolve context-specific serializers, more compact contextualOrDefault(defaultSerializer) function will be used instead.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:36
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
sandwwraithcommented, Feb 3, 2022

@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

6reactions
qwwdfsadcommented, Dec 5, 2022

It’s already implemented in the not-yet-released Kotlin 1.8.0, stay tuned!

Read more comments on GitHub >

github_iconTop Results From Across the Web

_serialize - Intel
Description. Serialize instruction execution, ensuring all modifications to flags, registers, and memory by previous instructions are completed ...
Read more >
Extending LLVM: Adding instructions, intrinsics, types, etc.
Adding an intrinsic function is far easier than adding an instruction, ... modify void ModuleBitcodeWriter::writeTypeTable() to serialize your type.
Read more >
How to use CPUID as a serializing instruction? - Stack Overflow
Is there a reason you're not using the fence operations? If the goal is to serialize a section of code you can do...
Read more >
DriveWorks SDK Reference: Sensors Serialization
When new data is available, the serializer calls the function provided in onData ... dwSensorSerializer_serializeDataAsync() // for generalized sensor data.
Read more >
Serializers in PySpark on waitingforcode.com
An intrinsic actor of this overhead are Python serializers that will be the ... PySpark uses it for creating RDDs built from binaryFiles(), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found