Skip to content

Commit 1aa2a30

Browse files
committed
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.
1 parent 07c71e5 commit 1aa2a30

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object C {
2-
def test: Unit = {
2+
def main(args: Array[String]): Unit = {
33
val i: Int = B.getInline
44
}
55
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object B {
2+
@inline def getInline: Int =
3+
sys.error("This is an expected failure when running C")
4+
}

bridge/src/sbt-test/source-dependencies/inline/test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ $ copy-file changes/B1.scala B.scala
44
$ copy-file changes/B2.scala B.scala
55
# Compilation of C.scala should fail because B.getInline now has type Double instead of Int
66
-> compile
7+
8+
$ copy-file changes/B1.scala B.scala
9+
> run
10+
11+
$ copy-file changes/B3.scala B.scala
12+
# The body of B.getInline was changed so C.scala should be recompiled
13+
# If it was recompiled, run should fail since B.getInline now throws an exception
14+
-> run

src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ast.{Trees, tpd}
55
import core._, core.Decorators._
66
import Contexts._, Flags._, Phases._, Trees._, Types._, Symbols._
77
import Names._, NameOps._, StdNames._
8+
import typer.Inliner
89

910
import dotty.tools.io.Path
1011
import java.io.PrintWriter
@@ -497,6 +498,21 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
497498
sym.is(Implicit), sym.is(Lazy), sym.is(Macro), sym.is(SuperAccessor))
498499
}
499500

500-
// TODO: Annotation support
501-
def apiAnnotations(s: Symbol): List[api.Annotation] = Nil
501+
// TODO: Support other annotations
502+
def apiAnnotations(s: Symbol): List[api.Annotation] = {
503+
val annots = new mutable.ListBuffer[api.Annotation]
504+
505+
if (Inliner.hasBodyToInline(s)) {
506+
// FIXME: If the body of an inline method changes, all the reverse
507+
// dependencies of this method need to be recompiled. sbt has no way
508+
// of tracking method bodies, so as a hack we include the pretty-printed
509+
// typed tree of the method as part of the signature we send to sbt.
510+
// To do this properly we would need a way to hash trees and types in
511+
// dotty itself.
512+
val printTypesCtx = ctx.fresh.setSetting(ctx.settings.printtypes, true)
513+
annots += marker(Inliner.bodyToInline(s).show(printTypesCtx).toString)
514+
}
515+
516+
annots.toList
517+
}
502518
}

0 commit comments

Comments
 (0)