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
araqnid
05/07/2020, 3:24 PM
I believe those methods are intrinsic — i.e. provided by the compiler itself. At least on JVM, they are specific bytecodes iirc.
☝️ 3
o
Ofir Bar
05/07/2020, 5:24 PM
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
araqnid
05/07/2020, 5:28 PM
“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
Ofir Bar
05/07/2020, 5:38 PM
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
Zach Klippenstein (he/him) [MOD]
05/07/2020, 7:06 PM
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
gildor
05/08/2020, 6:53 AM
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