https://kotlinlang.org logo
#compiler
Title
# compiler
d

Drew Hamilton

12/14/2023, 10:16 PM
For most targets, if I call
irIs(argument, type)
, then I can subsequently make an
irCall
treating
argument
as
type
– I guess the compiler is generating a smartcast for me. But for the
wasmJs
target, I need to generate the smartcast manually with
irImplicitCast(argument, type)
or I’ll get a compile error when trying to use
argument
as
type
. Is either of these behaviors a bug that I should file on YouTrack?
p

Pavel Kunyavskiy [JB]

12/15/2023, 9:00 AM
Only compiler frontend is able to create smartcasts, when code resolution happens. So in plugin you need to do it yourself. Sometimes compiler backends are able to compile slightly inconsistent IR (like missing implicit casts in simple cases). But no guarantees are given on that. Also it can sometimes work not exactly as you expected. For example, this can lead to virtual call to function from higher class in hierarchy, which is fine, but can be slower on native, or provide less binary compatibility guarantees on jvm.
d

Drew Hamilton

12/15/2023, 5:03 PM
Got it. So, I was getting lucky that it worked before, and adding the
irImplicitCast
is more correct.
Also it can sometimes work not exactly as you expected.
By “it” here, you mean compiling slightly inconsistent IR as I was before?
p

Pavel Kunyavskiy [JB]

12/15/2023, 5:14 PM
Yes
d

Drew Hamilton

12/15/2023, 5:36 PM
Makes sense. Thank you!
3 Views