-
Notifications
You must be signed in to change notification settings - Fork 21
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 vs. @inline: @specialize wins (unnecessarily) #5005
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5005?orig=1 |
@paulp said: |
@non said (edited on Feb 14, 2012 2:30:36 PM UTC): By itself this wouldn't fix your issue with Option. But using AnyRef specialization we can ensure that all uses of C2 will be rerouted to a specialized subclass (whose methods would correctly be final). I think this would fix this bug with regards to Option, although it wouldn't fix it in general. To fix it in general (IMO) would require always using AnyRef specialization (which seems like an OK plan to me) or to do a bigger change to how specialization works (maybe too big). Am I missing something? What do you think? |
@non said: One weird thing I noticed is that even when all the apply methods are marked final (and correctly inlined in m2) they are not inlined in B's (although scalac doesn't complain about this). In fact, when I looked more closely I saw that they were never inlined in the first place (in 2.9.1, or master, or my branch). I'm not sure whether Paul actually looked in B's bytecode and saw the apply calls being inlined, or if it was the absence of a warning which made him assuming it was happening. But I don't see any evidence that they were ever inlined in 2.9.1. |
@non said: I will open a new issue for that particular problem. |
@ijuma said: Have you checked that the verifier does not complain? |
@non said: So... apologies, this actually doesn't work. I must have been running the wrong code. I just double-checked and indeed the JVM notices this and complains. So I will need to refine the patch a bit. Thanks. |
@paulp said: |
@non said: I have a new patch which is less-completely-broken. It should fix the handling of final/@inline (i.e. letting classes like C2$mcZ$sp keep final on apply and apply$mcZ$sp) as well as removing @inline when removing final (to prevent annoying warnings). Unfortunately, there are two other things that your example hits:
Anyway, I think the patch should be ok, but didn't want you to think that I had "fixed" this whole issue. What do you see as the scope of #5005 anyway? It encompasses (at least) 3 separate bugs in specialization, IMO. |
@VladUreche said:
A test case one could use here is: class C2[@specialized(Boolean) U]() {
@inline final def apply(x: U): U = x
}
class B {
(new C2[Boolean]())(true)
} |
@paulp said: |
@magarciaEPFL said: |
@gkossakowski said: class SimpleCol[A](x: A) {
@inline
final def filter(p: A => Boolean): SimpleCol[A] = if (p(x)) this else null
def isEmpty: Boolean = ???
}
class A(xs: SimpleCol[A], val a: Int) {
@inline
final def filter(p: A => Boolean): A =
if (!xs.filter(p).isEmpty) this else
if (p(this)) this
else null
def foo() = filter(x => x.a > 0)
} I you compile it with |
@VladUreche said: |
@magarciaEPFL said: For the snippet in [comment-58618 | https://issues.scala-lang.org/browse/SI-5005?focusedCommentId=58618&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-58618] , the following non-inlined callsite keeps the closure alive (ie instantiated)
using In turn, the following suggests no ICode is loaded for that closure method (although type-flow gets right the most specific type of the closure,
The condition that fails for loading said ICode is
To recap, for inlining of an specialized apply method to happen, it's a necessary condition that |
@magarciaEPFL said:
|
@magarciaEPFL said:
Given that it's just a forwarder, for the closure to be eliminated the target method in
Alone the resulting code size (if inlining handles forwarding methods as any other) would make the heuristics stop inlining sometime before getting there. |
@magarciaEPFL said:
as above, then Rather, what
The question then is whether ICode can be loaded for
In the case at hand, an attempt is made to load ICode for |
@gkossakowski said: I spent the evening with Alex on the problem I mentioned in my comment and it turns out to be problem with specialization, specialized bridge generation and separate compilation. Basically, we do not preserve enough information between compiler runs (in pickler) and specialization gets very confused. I'll create another ticket with our findings tomorrow. |
@axel22 said: |
@gkossakowski said: |
@gkossakowski said: Conclusions are the following:
|
@non said: My findings are:
So, I think it's worth closing this bug and opening a new bug (if necessary) for some of the issues specific to Paul's example (i.e. inferred type of accessors related to inlining) since right now the bug's state is a bit confused. If we aren't going to close it, I'd like to get consensus on the test case for this bug (i.e. a source file and the desired output) since right now I'm not clear what it would take to consider it "fixed" |
@retronym said: |
The following demonstrates a method which is inlined until its class is specialized, after which it isn't, because the specialized version of the (declared final) method is not final. As a debugging aid, the specialized one is inlined if the call site is in a constructor, just not if it's in the body of a regular method.
The text was updated successfully, but these errors were encountered: