Skip to content

Avoid typechecking val and def tpt-s twice#8075

Merged
retronym merged 1 commit intoscala:2.12.xfrom
retronym:topic/tpt-tpe-tapestry
May 21, 2019
Merged

Avoid typechecking val and def tpt-s twice#8075
retronym merged 1 commit intoscala:2.12.xfrom
retronym:topic/tpt-tpe-tapestry

Conversation

@retronym
Copy link
Member

Demo:

$ cat sandbox/test.scala && (scalac-ref 2.12.x -Ytyper-debug sandbox/test.scala 2>&1) > /tmp/old.log && (qscalac -Ytyper-debug sandbox/test.scala 2>&1) > /tmp/new.log && diff -U1000 /tmp/{old,new}.log
trait C {
  type X
  def foo: X
}
--- /tmp/old.log    2019-05-20 13:56:45.000000000 +1000
+++ /tmp/new.log    2019-05-20 13:56:47.000000000 +1000
@@ -1,12 +1,10 @@
 |-- <empty> EXPRmode-POLYmode-QUALmode (site: package <root>)
+|-- <empty> EXPRmode-POLYmode-QUALmode (site: package <root>)
 |    \-> <empty>.type
 |-- class C BYVALmode-EXPRmode (site: package <empty>)
 |    |-- X BYVALmode-EXPRmode (site: trait C)
 |    |    \-> [type X] C.this.X
 |    |-- def foo BYVALmode-EXPRmode (site: trait C)
 |    |    |-- X TYPEmode (site: method foo in C)
 |    |    |    \-> C.this.X
-|    |    |-- X TYPEmode (site: method foo in C)
-|    |    |    \-> C.this.X
 |    |    \-> [def foo] => C.this.X
 |    \-> [trait C] C

@scala-jenkins scala-jenkins added this to the 2.12.9 milestone May 20, 2019
@retronym retronym added the performance the need for speed. usually compiler performance, sometimes runtime performance. label May 20, 2019
@retronym retronym requested a review from lrytz May 20, 2019 04:09
@retronym
Copy link
Member Author

The performance benefit here is likely imperceptible in normal compilation as typechecking types is typically quick. However, in my work on "outline typing" at the moment, the profiles led me to notice this inefficiency.

Demo:

```
$ cat sandbox/test.scala && (scalac-ref 2.12.x -Ytyper-debug sandbox/test.scala 2>&1) > /tmp/old.log && (qscalac -Ytyper-debug sandbox/test.scala 2>&1) > /tmp/new.log && diff -U1000 /tmp/{old,new}.log
```

```scala
trait C {
  type X
  def foo: X
}
```

```diff
--- /tmp/old.log    2019-05-20 13:56:45.000000000 +1000
+++ /tmp/new.log    2019-05-20 13:56:47.000000000 +1000
@@ -1,12 +1,10 @@
 |-- <empty> EXPRmode-POLYmode-QUALmode (site: package <root>)
+|-- <empty> EXPRmode-POLYmode-QUALmode (site: package <root>)
 |    \-> <empty>.type
 |-- class C BYVALmode-EXPRmode (site: package <empty>)
 |    |-- X BYVALmode-EXPRmode (site: trait C)
 |    |    \-> [type X] C.this.X
 |    |-- def foo BYVALmode-EXPRmode (site: trait C)
 |    |    |-- X TYPEmode (site: method foo in C)
 |    |    |    \-> C.this.X
-|    |    |-- X TYPEmode (site: method foo in C)
-|    |    |    \-> C.this.X
 |    |    \-> [def foo] => C.this.X
 |    \-> [trait C] C
```
@retronym retronym force-pushed the topic/tpt-tpe-tapestry branch from 4477a74 to 7806650 Compare May 20, 2019 22:15
@retronym retronym merged commit 07fafa7 into scala:2.12.x May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance the need for speed. usually compiler performance, sometimes runtime performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants