For most targets, if I call `irIs(argument, type)`...
# compiler
d
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
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
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
Yes
d
Makes sense. Thank you!