WIP Avoid ObjectRef overhead for effectively final case vars#66
Closed
WIP Avoid ObjectRef overhead for effectively final case vars#66
Conversation
4f9506b to
cf2937b
Compare
cf2937b to
744a984
Compare
Given
```scala
class C {
lazy val s: reflect.internal.SymbolTable = ???
import s._
def test(t: Tree) = {
t match {
case ap @ Apply(sel @ Select(_, _), _) if (ap, sel).hashCode > 0 =>
1
case ap @ Apply(sel @ Select(_, _), _) if (ap, sel).hashCode == 0 =>
() => ap
}
}
}
```
```
$ scalac -Xprint:jvm sandbox/test.scala 2>&1 | tee /tmp/old && qscalac -Xprint:jvm sandbox/test.scala 2>&1 | tee /tmp/new && diff -U1000 /tmp/{old,new}
```
```diff
--- /tmp/old 2019-08-27 10:47:15.000000000 +1000
+++ /tmp/new 2019-08-27 10:47:18.000000000 +1000
@@ -1,80 +1,80 @@
[[syntax trees at end of jvm]] // test.scala
package <empty> {
class C extends Object {
final <synthetic> lazy private[this] var s: scala.reflect.internal.SymbolTable = _;
@volatile private[this] var bitmap$0: Boolean = _;
private def s$lzycompute(): scala.reflect.internal.SymbolTable = {
C.this.synchronized(if (C.this.bitmap$0.unary_!())
{
C.this.s = (scala.Predef.???(): scala.reflect.internal.SymbolTable);
C.this.bitmap$0 = true
});
C.this.s
};
- <stable> <accessor> lazy def s(): scala.reflect.internal.SymbolTable = (if (C.this.bitmap$0.unary_!())
+ <stable> <accessor> lazy def s(): scala.reflect.internal.SymbolTable = if (C.this.bitmap$0.unary_!())
C.this.s$lzycompute()
else
- C.this.s: scala.reflect.internal.SymbolTable);
+ C.this.s;
def test(t: reflect.internal.Trees$Tree): Object = {
<synthetic> var rc13: Boolean = false;
- <synthetic> var x2: runtime.ObjectRef = scala.runtime.ObjectRef.create((null: reflect.internal.Trees$Apply));
+ <synthetic> <stable> var x2: reflect.internal.Trees$Apply = (null: reflect.internal.Trees$Apply);
{
case <synthetic> val x1: reflect.internal.Trees$Tree = t;
case15(){
if (x1.$isInstanceOf[reflect.internal.Trees$Apply]())
{
rc13 = true;
- x2.elem = (x1.$asInstanceOf[reflect.internal.Trees$Apply](): reflect.internal.Trees$Apply);
+ x2 = (x1.$asInstanceOf[reflect.internal.Trees$Apply](): reflect.internal.Trees$Apply);
{
- val sel: reflect.internal.Trees$Tree = x2.elem.$asInstanceOf[reflect.internal.Trees$Apply]().fun();
+ val sel: reflect.internal.Trees$Tree = x2.fun();
if (sel.$isInstanceOf[reflect.internal.Trees$Select]())
{
<synthetic> val x4: reflect.internal.Trees$Select = (sel.$asInstanceOf[reflect.internal.Trees$Select](): reflect.internal.Trees$Select);
- if (new Tuple2(x2.elem.$asInstanceOf[reflect.internal.Trees$Apply](), x4).hashCode().>(0))
+ if (new Tuple2(x2, x4).hashCode().>(0))
matchEnd14(scala.Int.box(1))
else
case16()
}
else
case16()
}
}
else
case16()
};
case16(){
if (rc13)
{
- val sel: reflect.internal.Trees$Tree = x2.elem.$asInstanceOf[reflect.internal.Trees$Apply]().fun();
+ val sel: reflect.internal.Trees$Tree = x2.fun();
if (sel.$isInstanceOf[reflect.internal.Trees$Select]())
{
<synthetic> val x9: reflect.internal.Trees$Select = (sel.$asInstanceOf[reflect.internal.Trees$Select](): reflect.internal.Trees$Select);
- if (new Tuple2(x2.elem.$asInstanceOf[reflect.internal.Trees$Apply](), x9).hashCode().==(0))
+ if (new Tuple2(x2, x9).hashCode().==(0))
matchEnd14({
$anonfun(x2)
})
else
case17()
}
else
case17()
}
else
case17()
};
case17(){
matchEnd14(throw new MatchError(x1))
};
matchEnd14(x: Object){
x
}
}
};
- final <static> <artifact> def $anonfun$test$1(x2$1: runtime.ObjectRef): reflect.internal.Trees$Apply = x2$1.elem.$asInstanceOf[reflect.internal.Trees$Apply]();
+ final <static> <artifact> def $anonfun$test$1(x2$1: reflect.internal.Trees$Apply): reflect.internal.Trees$Apply = x2$1;
def <init>(): C = {
C.super.<init>();
()
}
}
}
```
744a984 to
c69a52b
Compare
Owner
Author
|
Upstream: scala#8375 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Given