From ac35e2fa07a85277e1f3514483a23c4034bc4d97 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Thu, 14 Nov 2024 19:12:10 +0100 Subject: [PATCH] address review: part 3 --- .../dotty/tools/dotc/core/Annotations.scala | 7 +--- .../tools/dotc/core/tasty/TreeUnpickler.scala | 18 +++------ .../dotty/tools/dotc/inlines/Inlines.scala | 14 +------ .../add-param-unroll2/a_v1/A.scala | 10 ----- .../add-param-unroll2/a_v2/B.scala | 8 ---- .../add-param-unroll2/a_v3/A.scala | 19 ---------- .../add-param-unroll2/a_v3_2/A.scala | 10 ----- .../add-param-unroll2/a_v3_2/C.scala | 9 ----- .../tasty-compat/add-param-unroll2/build.sbt | 38 ------------------- .../project/DottyInjectedPlugin.scala | 11 ------ sbt-test/tasty-compat/add-param-unroll2/test | 11 ------ 11 files changed, 7 insertions(+), 148 deletions(-) delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/a_v1/A.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/a_v2/B.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/a_v3_2/A.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/a_v3_2/C.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/build.sbt delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/project/DottyInjectedPlugin.scala delete mode 100644 sbt-test/tasty-compat/add-param-unroll2/test diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index e47e6b4b7967..d6a99b12e3b3 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -177,13 +177,8 @@ object Annotations { assert(myTree != null) myTree match { case treeFn: (Context ?=> Tree) @unchecked => - var result: Tree | Null = null myTree = null - try - result = atPhaseBeforeTransforms(treeFn) - myTree = result - finally if result == null then - myTree = ctx ?=> treeFn(using ctx) // reset, if unit is suspended then it will re-enter this annotation + myTree = atPhaseBeforeTransforms(treeFn) case _ => } myTree.asInstanceOf[Tree] diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 6b7817a68694..efdcf45c8857 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -170,13 +170,12 @@ class TreeUnpickler(reader: TastyReader, case ex: Exception => fail(ex) } - class TreeReader(val reader: TastyReader, inInlineBody: Boolean = false) { + class TreeReader(val reader: TastyReader) { import reader.* - def forkAt(start: Addr, inInlineBody: Boolean = false): TreeReader = - new TreeReader(subReader(start, endAddr), inInlineBody) + def forkAt(start: Addr): TreeReader = new TreeReader(subReader(start, endAddr)) - def fork: TreeReader = forkAt(currentAddr, inInlineBody) + def fork: TreeReader = forkAt(currentAddr) def skipParentTree(tag: Int): Unit = { if tag == SPLITCLAUSE then () @@ -696,7 +695,7 @@ class TreeUnpickler(reader: TastyReader, val ctx1 = localContext(sym)(using ctx0).addMode(Mode.ReadPositions) inContext(sourceChangeContext(Addr(0))(using ctx1)) { // avoids space leaks by not capturing the current context - forkAt(rhsStart, inInlineBody = true).readTree() + forkAt(rhsStart).readTree() } }) goto(start) @@ -1585,11 +1584,7 @@ class TreeUnpickler(reader: TastyReader, val denot = inContext(ctx.addMode(Mode.ResolveFromTASTy)): searchDenot // able to resolve Invisible members - - val sel = makeSelect(qual, name, denot) - if denot == NoDenotation && inInlineBody && sel.denot.symbol.exists && sel.symbol.isDefinedInCurrentRun then - throw new ChangedMethodDenot(sel.denot.symbol) - sel + makeSelect(qual, name, denot) case REPEATED => val elemtpt = readTpt() SeqLiteral(until(end)(readTree()), elemtpt) @@ -1896,9 +1891,6 @@ class TreeUnpickler(reader: TastyReader, object TreeUnpickler { - /** Specifically thrown when a SELECTin was written to TASTy, i.e. is expected to resolve, and then doesn't. */ - private[dotc] final class ChangedMethodDenot(val resolved: Symbol) extends Exception - /** Define the expected format of the tasty bytes * - TopLevel: Tasty that contains a full class nested in its package * - Term: Tasty that contains only a term tree diff --git a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala index a09874ff56ee..b327e110874f 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala @@ -19,7 +19,6 @@ import staging.StagingLevel import collection.mutable import reporting.{NotConstant, trace} import util.Spans.Span -import dotty.tools.dotc.core.tasty.TreeUnpickler /** Support for querying inlineable methods and for inlining calls to such methods */ object Inlines: @@ -159,18 +158,7 @@ object Inlines: else if enclosingInlineds.length < ctx.settings.XmaxInlines.value && !reachedInlinedTreesLimit then val body = try bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors - catch - case _: MissingInlineInfo => throw CyclicReference(ctx.owner) - case err: TreeUnpickler.ChangedMethodDenot => - // tested in sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala - if err.resolved.source == ctx.source then - report.error(em"""cannot inline ${tree.symbol}: - | The definition of ${err.resolved.showLocated}, defined in the current file, has changed incompatibly. - | Try inlining from a different file.""", tree.srcPos) - EmptyTree - else - // Tested in sbt-test/tasty-compat/add-param-unroll2/a_v3_2/C.scala - ctx.compilationUnit.suspend("suspending in case of possible generated methods") + catch case _: MissingInlineInfo => throw CyclicReference(ctx.owner) new InlineCall(tree).expand(body) else ctx.base.stopInlining = true diff --git a/sbt-test/tasty-compat/add-param-unroll2/a_v1/A.scala b/sbt-test/tasty-compat/add-param-unroll2/a_v1/A.scala deleted file mode 100644 index 7ad2eb78214c..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/a_v1/A.scala +++ /dev/null @@ -1,10 +0,0 @@ -package a - -import scala.annotation.unroll - -// new project with a single file, first compile via Zinc -object A { - - def foo(s: String, x: Int): String = s + x - -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/a_v2/B.scala b/sbt-test/tasty-compat/add-param-unroll2/a_v2/B.scala deleted file mode 100644 index 7f9168b0798e..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/a_v2/B.scala +++ /dev/null @@ -1,8 +0,0 @@ -package b - -import a.* - -// Add a separate file in the same project as A, second compile via Zinc -object B { - transparent inline def caller = A.foo("abc", 2) -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala b/sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala deleted file mode 100644 index 64df683f34a9..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala +++ /dev/null @@ -1,19 +0,0 @@ -package a -import b.* - -import scala.annotation.unroll - -// modify A.scala and add a parameter to foo, and add C, third compile via Zinc -object A { - - def foo(s: String, x: Int, @unroll b: Boolean = true): String = s + x + b - -} - -// C is the same compilation unit as A, and inlines B.caller, so its TASTy will attempt to -// resolve the generated forwarder A.foo, which doesn't exist yet in typer phase. -// issue a compilation error here, suggesting to move C to a separate compilation unit. -// In a_v3_2/C.scala, demonstrate fixing the error by moving C to a separate compilation unit. -object C { - val res: String = B.caller -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/A.scala b/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/A.scala deleted file mode 100644 index 039676557381..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/A.scala +++ /dev/null @@ -1,10 +0,0 @@ -package a - -import scala.annotation.unroll - -// modify A.scala and add a parameter to foo, and add C (in another file), third compile via Zinc -object A { - - def foo(s: String, x: Int, @unroll b: Boolean = true): String = s + x + b - -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/C.scala b/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/C.scala deleted file mode 100644 index e9238c7edbb6..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/a_v3_2/C.scala +++ /dev/null @@ -1,9 +0,0 @@ -package a -import b.* - -// C is a separate compilation unit to A, and inlines B.caller, so its TASTy will try to resolve -// the generated A.foo forwarder, which will not exist yet in typer phase. -// The unit will suspend, and in the second run, A.foo will be generated, so resolution will succeed. -object C { - val res: String = B.caller -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/build.sbt b/sbt-test/tasty-compat/add-param-unroll2/build.sbt deleted file mode 100644 index bc61bded9b73..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/build.sbt +++ /dev/null @@ -1,38 +0,0 @@ -lazy val commonSettings = Seq( - scalacOptions += "-experimental", -) - -lazy val printSettings = Seq( - scalacOptions += "-Yprint-tasty", - scalacOptions += "-Ydebug-error" -) - -lazy val a_v1 = project.in(file("a_v1")) - .settings(commonSettings) - .settings( - Compile / classDirectory := (ThisBuild / baseDirectory).value / "v2-input" - ) - -lazy val a_v2 = project.in(file("a_v2")) - .settings(commonSettings) - .settings(printSettings) - .settings( - Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v2-input", - Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-input" - ) - -lazy val a_v3 = project.in(file("a_v3")) - .settings(commonSettings) - .settings(printSettings) - .settings( - Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v3-input", - Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-output" - ) - -lazy val a_v3_2 = project.in(file("a_v3_2")) - .settings(commonSettings) - .settings(printSettings) - .settings( - Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v3-input", - Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3_2-output" - ) diff --git a/sbt-test/tasty-compat/add-param-unroll2/project/DottyInjectedPlugin.scala b/sbt-test/tasty-compat/add-param-unroll2/project/DottyInjectedPlugin.scala deleted file mode 100644 index fb946c4b8c61..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/project/DottyInjectedPlugin.scala +++ /dev/null @@ -1,11 +0,0 @@ -import sbt._ -import Keys._ - -object DottyInjectedPlugin extends AutoPlugin { - override def requires = plugins.JvmPlugin - override def trigger = allRequirements - - override val projectSettings = Seq( - scalaVersion := sys.props("plugin.scalaVersion") - ) -} diff --git a/sbt-test/tasty-compat/add-param-unroll2/test b/sbt-test/tasty-compat/add-param-unroll2/test deleted file mode 100644 index 79116f6a1464..000000000000 --- a/sbt-test/tasty-compat/add-param-unroll2/test +++ /dev/null @@ -1,11 +0,0 @@ -# compile library A via Zinc, with an initial file A defining method foo -> a_v1/compile -# compile library A via Zinc, for the second time, adding a new file that defines an inline -# method B.caller, calling A.foo -> a_v2/compile -# compile library A via Zinc, for the third time, add a new parameter to A.foo, using @unroll to generate a forwarder -# in the same file A.scala, define object C that inlines B.caller, it should fail to resolve the new invisible forwarder, as it is not visible yet --> a_v3/compile -# compile library A via Zinc, for the third time (alternative scenario), add a new parameter to A.foo, using @unroll to generate a forwarder -# in a new file C.scala, define object C that inlines B.caller, it should suspend the unit and then resolve the new invisible forwarder -> a_v3_2/compile