Hey guys, Inside the `Primitives.kt` file, Inside...
# announcements
o
Hey guys, Inside the
Primitives.kt
file, Inside the Int primitive, there are methods to convert the Int to other primitives but I don't see any implementation. I can't figure out how this conversion works. What am I missing?
a
I believe those methods are intrinsic — i.e. provided by the compiler itself. At least on JVM, they are specific bytecodes iirc.
☝️ 3
o
Oh, i didn't even knew such option exist (that the compiler can automatically provide implementation) Say I want to read more about this, what should I do? (read about compilers?) @araqnid
a
“intrinsic” is a name used several times in Kotlin for this sort of thing — glue provided by the compiler. For example, in any suspend function you can refer to
coroutineContext
which is supplied as an intrinsic (the implementation always knows what the context is). There’s also the “Instrinsics” class that provides the implementation of null-checks etc. that the compiler emits calls to. I’m afraid I don’t know of a central location describing them all, though.
👍 1
o
I seems like "closed source code" for me (even if the compiler generates it, I would still expect to be able to read it somewhere), but you shed light on the topic Thank you
z
The compiler doesn’t necessarily generate intrinsic impls – it might be implemented in native code, or even just exist as a JVM bytecode with the implementation living inside the runtime.
g
closed source code
it’s not closed source code, source code just doesn’t exist, only bytecode/native implementation You can read it in compiler source code, which is open sourced