-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Specialize Any.{==, !=} when inlining #12157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specialize Any.{==, !=} when inlining #12157
Conversation
compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala
Outdated
Show resolved
Hide resolved
case None => tree | ||
} | ||
case _ => | ||
tree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the criteria for deciding what methods should be specialized? Is it possible to generalize the specialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The criteria is that it is an ==
or !=
on Any
sel.symbol == defn.Any_== || sel.symbol == defn.Any_!=
and that the types of the compared values are the same value class
defn.ScalaValueClasses().find { cls =>
arg1.tpe.derivesFrom(cls) && arg2.tpe.derivesFrom(cls)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might generalize it for different classes. For example Short == Int.
The other potential generalization is on Numeric
ops but that is much more complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking why even specialize ==
and !=
. This seems to related to the discussion about whether inlining should re-resolve selections. Such specialization helps very little in that perspective, I'm thinking whether it's worthwhile to complicate the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in this case it is about the partial evaluation of the operation. If we have (2: Any) == (3: Any)
we know that this will end calling 2 == 3
and return that result.
All the testing frameworks will benefit from this as the variants of assertEquals
will generate this code. That is already a large enough use case.
Their specilized versions are known to have the same semantics as the generic `==` or `!=`. Improvement related to scala#11998
6908d97
to
48f0e89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @nicolasstucki ! |
Their specialized versions are known to have the same semantics as the generic
==
or!=
.Improvement related to #11998
Fiixes #12161