Skip to content

Commit 96d0573

Browse files
committed
Support separate compilation
Inline trees can now be read form TASTY. However, positions are not set correctly. This remains to be implemented.
1 parent a47a800 commit 96d0573

File tree

6 files changed

+52
-18
lines changed

6 files changed

+52
-18
lines changed

src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Contexts._, Symbols._, Types._, Scopes._, SymDenotations._, Names._, Name
77
import StdNames._, Denotations._, Flags._, Constants._, Annotations._
88
import util.Positions._
99
import ast.{tpd, Trees, untpd}
10+
import typer.Inliner
1011
import Trees._
1112
import Decorators._
1213
import TastyUnpickler._, TastyBuffer._, PositionPickler._
@@ -468,6 +469,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
468469
val isClass = ttag == TEMPLATE
469470
val templateStart = currentAddr
470471
skipTree() // tpt
472+
val rhsStart = currentAddr
471473
val rhsIsEmpty = noRhs(end)
472474
if (!rhsIsEmpty) skipTree()
473475
val (givenFlags, annots, privateWithin) = readModifiers(end)
@@ -504,6 +506,11 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
504506
sym.completer.withDecls(newScope)
505507
forkAt(templateStart).indexTemplateParams()(localContext(sym))
506508
}
509+
else (annots.find(_.symbol == defn.InlineAnnot)) match {
510+
case Some(inlineAnnot) =>
511+
Inliner.attachBody(inlineAnnot, forkAt(rhsStart).readTerm()(localContext(sym)))
512+
case none =>
513+
}
507514
goto(start)
508515
sym
509516
}

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ object Inliner {
8282
| You can use -Xmax:inlines to change the limit.""")
8383
}
8484

85-
def dropInlined(tree: tpd.Inlined)(implicit ctx: Context): Tree = {
85+
def dropInlined(inlined: tpd.Inlined)(implicit ctx: Context): Tree = {
8686
val reposition = new TreeMap {
8787
override def transform(tree: Tree)(implicit ctx: Context): Tree =
88-
tree.withPos(tree.pos)
88+
tree.withPos(inlined.call.pos)
8989
}
90-
tpd.seq(tree.bindings, reposition.transform(tree.expansion))
90+
tpd.seq(inlined.bindings, reposition.transform(inlined.expansion))
9191
}
9292

9393
def inlineContext(tree: untpd.Inlined)(implicit ctx: Context): Context =

tests/run/inline/Test_2.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Test {
2+
3+
import p.inlines._
4+
5+
def main(args: Array[String]): Unit = {
6+
println(f(10))
7+
println(f(f(10)))
8+
9+
track("hello") { println("") }
10+
11+
val o = new Outer
12+
val i = new o.Inner
13+
println(i.m)
14+
//println(i.g)
15+
//println(i.h)
16+
}
17+
18+
}

tests/run/inlineTest.scala renamed to tests/run/inline/inlines_1.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
package p
12
import collection.mutable
23

3-
object Test {
4+
object inlines {
45

56
final val monitored = false
67

@@ -38,18 +39,4 @@ object Test {
3839
@dotty.annotation.inline def h = f ++ m
3940
}
4041
}
41-
42-
def main(args: Array[String]): Unit = {
43-
println(f(10))
44-
println(f(f(10)))
45-
46-
track("hello") { println("") }
47-
48-
val o = new Outer
49-
val i = new o.Inner
50-
println(i.m)
51-
//println(i.g)
52-
//println(i.h)
53-
}
54-
5542
}

tests/run/inlinePower/Test_2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import p.pow.power
2+
object Test {
3+
4+
def main(args: Array[String]): Unit = {
5+
println(power(2.0, 10))
6+
def x = 2.0
7+
println(power(x, 11))
8+
}
9+
}

tests/run/inlinePower/power_1.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package p
2+
3+
object pow {
4+
5+
@dotty.annotation.inline
6+
def power(x: Double, n: Int): Double =
7+
if (n == 0) 1.0
8+
else if (n == 1) x
9+
else {
10+
val y = power(x, n / 2)
11+
if (n % 2 == 0) y * y else y * y * x
12+
}
13+
}

0 commit comments

Comments
 (0)