Open mkustermann opened 6 years ago
/cc @mraleph
The text f.{core::Object::==}(null)
suggests that you actually call the ==
method of f
with a null
argument. Is this the case?
If so, it is a bug. The ==
operator syntax is specified to never call the ==
method on the receiver if either operand is the null
value. It must handle that locally (by checking whether the other operand is also null
).
@lrhn checking locally is too much of a size overhead. Instead this is handled by backends, e.g. VM injects check for null
into prologue of every operator ==
definition (which is not observable).
That makes sense. It does require every backend to know that calls to operator==
are different from other method calls (but "every backend" isn't that many, so it's just unrelated people like me who gets confused). Thank you for the explanation.
@lrhn dart2js also injects a null check in every operator ==
definition in order to keep call sites small.
dart2js recognizes x == null
and lowers it to an instruction form of identical(x, null)
in the optimizer.
If the size overhead is a concern for this frequent check, Kernel could add a special 'is-null' node.
I would use such an operation only for checks inserted by lowering, and not user code, otherwise we lose the source location of the arguments to operator==
, making it difficult to generate accurate sourcemaps.
Is there any updates on this?
@peter-ahe-google
No. This isn't really on our radar.
Currently fasta lowers comparisons with
null
, e.g. into
It should perform this lowering by using
identical(<foo>, null)
instead!One advantage of this is that it is not valid to use the
==
operator on non-primitive constants, but it is valid to useidentical(<constant>, null)
.