From 6821bac06b34c416ca94216025b864e73592cbe7 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 30 Sep 2016 18:42:34 +0200 Subject: Fix incremental compilation when inline method body changes Since we have no nice way of hashing a typed tree we use the pretty-printed tree of the method (as it would be printed by -Xprint:posttyper -Xprint-types) as a hacky substitute for now. --- .../src/sbt-test/source-dependencies/inline/C.scala | 2 +- .../source-dependencies/inline/changes/B3.scala | 4 ++++ bridge/src/sbt-test/source-dependencies/inline/test | 8 ++++++++ src/dotty/tools/dotc/sbt/ExtractAPI.scala | 20 ++++++++++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 bridge/src/sbt-test/source-dependencies/inline/changes/B3.scala diff --git a/bridge/src/sbt-test/source-dependencies/inline/C.scala b/bridge/src/sbt-test/source-dependencies/inline/C.scala index 0370943e1..caeb61535 100644 --- a/bridge/src/sbt-test/source-dependencies/inline/C.scala +++ b/bridge/src/sbt-test/source-dependencies/inline/C.scala @@ -1,5 +1,5 @@ object C { - def test: Unit = { + def main(args: Array[String]): Unit = { val i: Int = B.getInline } } diff --git a/bridge/src/sbt-test/source-dependencies/inline/changes/B3.scala b/bridge/src/sbt-test/source-dependencies/inline/changes/B3.scala new file mode 100644 index 000000000..991bd17b8 --- /dev/null +++ b/bridge/src/sbt-test/source-dependencies/inline/changes/B3.scala @@ -0,0 +1,4 @@ +object B { + @inline def getInline: Int = + sys.error("This is an expected failure when running C") +} diff --git a/bridge/src/sbt-test/source-dependencies/inline/test b/bridge/src/sbt-test/source-dependencies/inline/test index ba891710f..56fdb0486 100644 --- a/bridge/src/sbt-test/source-dependencies/inline/test +++ b/bridge/src/sbt-test/source-dependencies/inline/test @@ -4,3 +4,11 @@ $ copy-file changes/B1.scala B.scala $ copy-file changes/B2.scala B.scala # Compilation of C.scala should fail because B.getInline now has type Double instead of Int -> compile + +$ copy-file changes/B1.scala B.scala +> run + +$ copy-file changes/B3.scala B.scala +# The body of B.getInline was changed so C.scala should be recompiled +# If it was recompiled, run should fail since B.getInline now throws an exception +-> run diff --git a/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 437e36bb9..a7b18b6d6 100644 --- a/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -5,6 +5,7 @@ import ast.{Trees, tpd} import core._, core.Decorators._ import Contexts._, Flags._, Phases._, Trees._, Types._, Symbols._ import Names._, NameOps._, StdNames._ +import typer.Inliner import dotty.tools.io.Path import java.io.PrintWriter @@ -497,6 +498,21 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder sym.is(Implicit), sym.is(Lazy), sym.is(Macro), sym.is(SuperAccessor)) } - // TODO: Annotation support - def apiAnnotations(s: Symbol): List[api.Annotation] = Nil + // TODO: Support other annotations + def apiAnnotations(s: Symbol): List[api.Annotation] = { + val annots = new mutable.ListBuffer[api.Annotation] + + if (Inliner.hasBodyToInline(s)) { + // FIXME: If the body of an inline method changes, all the reverse + // dependencies of this method need to be recompiled. sbt has no way + // of tracking method bodies, so as a hack we include the pretty-printed + // typed tree of the method as part of the signature we send to sbt. + // To do this properly we would need a way to hash trees and types in + // dotty itself. + val printTypesCtx = ctx.fresh.setSetting(ctx.settings.printtypes, true) + annots += marker(Inliner.bodyToInline(s).show(printTypesCtx).toString) + } + + annots.toList + } } -- cgit v1.2.3