aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala7
-rw-r--r--src/dotty/tools/dotc/typer/Inliner.scala6
-rw-r--r--tests/run/inline/Test_2.scala18
-rw-r--r--tests/run/inline/inlines_1.scala (renamed from tests/run/inlineTest.scala)17
-rw-r--r--tests/run/inlinePower/Test_2.scala9
-rw-r--r--tests/run/inlinePower/power_1.scala13
6 files changed, 52 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
index 56bb8498a..11f2eddac 100644
--- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
@@ -7,6 +7,7 @@ import Contexts._, Symbols._, Types._, Scopes._, SymDenotations._, Names._, Name
import StdNames._, Denotations._, Flags._, Constants._, Annotations._
import util.Positions._
import ast.{tpd, Trees, untpd}
+import typer.Inliner
import Trees._
import Decorators._
import TastyUnpickler._, TastyBuffer._, PositionPickler._
@@ -468,6 +469,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
val isClass = ttag == TEMPLATE
val templateStart = currentAddr
skipTree() // tpt
+ val rhsStart = currentAddr
val rhsIsEmpty = noRhs(end)
if (!rhsIsEmpty) skipTree()
val (givenFlags, annots, privateWithin) = readModifiers(end)
@@ -504,6 +506,11 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table) {
sym.completer.withDecls(newScope)
forkAt(templateStart).indexTemplateParams()(localContext(sym))
}
+ else (annots.find(_.symbol == defn.InlineAnnot)) match {
+ case Some(inlineAnnot) =>
+ Inliner.attachBody(inlineAnnot, forkAt(rhsStart).readTerm()(localContext(sym)))
+ case none =>
+ }
goto(start)
sym
}
diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala
index 06eea9113..68bc55860 100644
--- a/src/dotty/tools/dotc/typer/Inliner.scala
+++ b/src/dotty/tools/dotc/typer/Inliner.scala
@@ -82,12 +82,12 @@ object Inliner {
| You can use -Xmax:inlines to change the limit.""")
}
- def dropInlined(tree: tpd.Inlined)(implicit ctx: Context): Tree = {
+ def dropInlined(inlined: tpd.Inlined)(implicit ctx: Context): Tree = {
val reposition = new TreeMap {
override def transform(tree: Tree)(implicit ctx: Context): Tree =
- tree.withPos(tree.pos)
+ tree.withPos(inlined.call.pos)
}
- tpd.seq(tree.bindings, reposition.transform(tree.expansion))
+ tpd.seq(inlined.bindings, reposition.transform(inlined.expansion))
}
def inlineContext(tree: untpd.Inlined)(implicit ctx: Context): Context =
diff --git a/tests/run/inline/Test_2.scala b/tests/run/inline/Test_2.scala
new file mode 100644
index 000000000..0d1723018
--- /dev/null
+++ b/tests/run/inline/Test_2.scala
@@ -0,0 +1,18 @@
+object Test {
+
+ import p.inlines._
+
+ def main(args: Array[String]): Unit = {
+ println(f(10))
+ println(f(f(10)))
+
+ track("hello") { println("") }
+
+ val o = new Outer
+ val i = new o.Inner
+ println(i.m)
+ //println(i.g)
+ //println(i.h)
+ }
+
+}
diff --git a/tests/run/inlineTest.scala b/tests/run/inline/inlines_1.scala
index 39153951e..64adb031c 100644
--- a/tests/run/inlineTest.scala
+++ b/tests/run/inline/inlines_1.scala
@@ -1,6 +1,7 @@
+package p
import collection.mutable
-object Test {
+object inlines {
final val monitored = false
@@ -38,18 +39,4 @@ object Test {
@dotty.annotation.inline def h = f ++ m
}
}
-
- def main(args: Array[String]): Unit = {
- println(f(10))
- println(f(f(10)))
-
- track("hello") { println("") }
-
- val o = new Outer
- val i = new o.Inner
- println(i.m)
- //println(i.g)
- //println(i.h)
- }
-
}
diff --git a/tests/run/inlinePower/Test_2.scala b/tests/run/inlinePower/Test_2.scala
new file mode 100644
index 000000000..8e16587b5
--- /dev/null
+++ b/tests/run/inlinePower/Test_2.scala
@@ -0,0 +1,9 @@
+import p.pow.power
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ println(power(2.0, 10))
+ def x = 2.0
+ println(power(x, 11))
+ }
+}
diff --git a/tests/run/inlinePower/power_1.scala b/tests/run/inlinePower/power_1.scala
new file mode 100644
index 000000000..1faa10516
--- /dev/null
+++ b/tests/run/inlinePower/power_1.scala
@@ -0,0 +1,13 @@
+package p
+
+object pow {
+
+ @dotty.annotation.inline
+ def power(x: Double, n: Int): Double =
+ if (n == 0) 1.0
+ else if (n == 1) x
+ else {
+ val y = power(x, n / 2)
+ if (n % 2 == 0) y * y else y * y * x
+ }
+}