From 0683579ae28e3e0abb12b9390c4d5078b0a9d79a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 19 Apr 2022 17:07:57 +0200 Subject: [PATCH] Remove support -scala-output-version with quotes --- .../dotty/tools/dotc/core/Definitions.scala | 2 - .../tools/dotc/quoted/PickledQuotes.scala | 4 +- .../tools/dotc/transform/PickleQuotes.scala | 42 +++---------------- .../dotty/tools/dotc/transform/Splicing.scala | 8 +--- .../macros-forward-3.0/app/App.scala | 17 -------- .../macros-forward-3.0/build.sbt | 14 ------- .../macros-forward-3.0/lib/Macro.scala | 20 --------- .../project/DottyInjectedPlugin.scala | 11 ----- .../scala3-compat/macros-forward-3.0/test | 1 - .../forwardCompat-3.0/Macro_1_r3.0.scala | 20 --------- .../forwardCompat-3.0/Test_2_c3.0.2.scala | 15 ------- .../pos-macros/forwardCompat-3.0/why.md | 3 -- .../forwardCompat-3.1/Macro_1_r3.1.scala | 20 --------- .../forwardCompat-3.1/Test_2_c3.1.0.scala | 15 ------- .../pos-macros/forwardCompat-3.1/why.md | 1 - 15 files changed, 9 insertions(+), 184 deletions(-) delete mode 100644 sbt-test/scala3-compat/macros-forward-3.0/app/App.scala delete mode 100644 sbt-test/scala3-compat/macros-forward-3.0/build.sbt delete mode 100644 sbt-test/scala3-compat/macros-forward-3.0/lib/Macro.scala delete mode 100644 sbt-test/scala3-compat/macros-forward-3.0/project/DottyInjectedPlugin.scala delete mode 100644 sbt-test/scala3-compat/macros-forward-3.0/test delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.0/Test_2_c3.0.2.scala delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.0/why.md delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala delete mode 100644 tests/disabled/pos-macros/forwardCompat-3.1/why.md diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 18fbf977bbc2..e09b7ca98955 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -827,9 +827,7 @@ class Definitions { @tu lazy val QuoteUnpicklerClass: ClassSymbol = requiredClass("scala.quoted.runtime.QuoteUnpickler") - @tu lazy val QuoteUnpickler_unpickleExpr: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleExpr") @tu lazy val QuoteUnpickler_unpickleExprV2: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleExprV2") - @tu lazy val QuoteUnpickler_unpickleType: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleType") @tu lazy val QuoteUnpickler_unpickleTypeV2: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleTypeV2") @tu lazy val QuoteMatchingClass: ClassSymbol = requiredClass("scala.quoted.runtime.QuoteMatching") diff --git a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala index b3a4783a783c..2e0454c3a7aa 100644 --- a/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala @@ -50,7 +50,7 @@ object PickledQuotes { /** `typeHole`/`types` argument of `QuoteUnpickler.{unpickleExpr,unpickleExprV2,unpickleType,unpickleTypeV2}` */ enum TypeHole: /** `termHole` argument of `QuoteUnpickler.{unpickleExpr, unpickleType}`. - * From code compiled with Scala 3.0.x and 3.1.x or with -scala-output-version 3.0 and 3.1 + * From code compiled with Scala 3.0.x and 3.1.x. * Note: For `unpickleType` it will always be `null`. */ case V1(evalHole: Null | ((Int, Seq[scala.quoted.Type[?]]) => scala.quoted.Type[?])) @@ -65,7 +65,7 @@ object PickledQuotes { enum ExprHole: /** `termHole` argument of `QuoteUnpickler.{unpickleExpr, unpickleType}`. - * From code compiled with Scala 3.0.x and 3.1.x or with -scala-output-version 3.0 and 3.1 + * From code compiled with Scala 3.0.x and 3.1.x. * Note: For `unpickleType` it will always be `null`. */ case V1(evalHole: Null | ((Int, Seq[ExprHole.ArgV1], scala.quoted.Quotes) => scala.quoted.Expr[?])) diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index 40e3526861d0..a12ef6d50bed 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -291,9 +291,6 @@ object PickleQuotes { * this closure is always applied directly to the actual context and the BetaReduce phase removes it. */ def pickleAsTasty() = { - - val unpickleV1 = ctx.scalaRelease <= Release3_1 - val pickleQuote = PickledQuotes.pickleQuote(body) val pickledQuoteStrings = pickleQuote match case x :: Nil => Literal(Constant(x)) @@ -306,26 +303,8 @@ object PickleQuotes { // This and all closures in typeSplices are removed by the BetaReduce phase val types = - if unpickleV1 then - if typeSplices.isEmpty then Literal(Constant(null)) // keep pickled quote without contents as small as possible - else - Lambda( - MethodType( - List(nme.idx, nme.contents).map(name => UniqueName.fresh(name).toTermName), - List(defn.IntType, defn.SeqType.appliedTo(defn.AnyType)), - defn.QuotedTypeClass.typeRef.appliedTo(WildcardType)), - args => { - val cases = typeSplices.map { case (splice, idx) => - CaseDef(Literal(Constant(idx)), EmptyTree, splice) - } - cases match - case CaseDef(_, _, rhs) :: Nil => rhs - case _ => Match(args(0).annotated(New(ref(defn.UncheckedAnnot.typeRef))), cases) - } - ) - else // if unpickleV2 then - if typeSplices.isEmpty then Literal(Constant(null)) // keep pickled quote without contents as small as possible - else SeqLiteral(typeSplices.map(_._1), TypeTree(defn.QuotedTypeClass.typeRef.appliedTo(WildcardType))) + if typeSplices.isEmpty then Literal(Constant(null)) // keep pickled quote without contents as small as possible + else SeqLiteral(typeSplices.map(_._1), TypeTree(defn.QuotedTypeClass.typeRef.appliedTo(WildcardType))) // This and all closures in termSplices are removed by the BetaReduce phase val termHoles = @@ -341,12 +320,7 @@ object PickleQuotes { val defn.FunctionOf(argTypes, defn.FunctionOf(quotesType :: _, _, _, _), _, _) = splice.tpe val rhs = { val spliceArgs = argTypes.zipWithIndex.map { (argType, i) => - val argi = args(1).select(nme.apply).appliedTo(Literal(Constant(i))) - if unpickleV1 && argType.derivesFrom(defn.QuotedExprClass) then - val argType1 = defn.FunctionType(1).appliedTo(defn.QuotesClass.typeRef, argType) - argi.asInstance(argType1).select(nme.apply).appliedTo(args(2)) - else - argi.asInstance(argType) + args(1).select(nme.apply).appliedTo(Literal(Constant(i))).asInstance(argType) } val Block(List(ddef: DefDef), _) = splice // TODO: beta reduce inner closure? Or wait until BetaReduce phase? @@ -363,14 +337,10 @@ object PickleQuotes { val quotedType = quoteClass.typeRef.appliedTo(originalTp) val lambdaTpe = MethodType(defn.QuotesClass.typeRef :: Nil, quotedType) val unpickleMeth = - if unpickleV1 then - if isType then defn.QuoteUnpickler_unpickleType - else defn.QuoteUnpickler_unpickleExpr - else // if unpickleV2 then - if isType then defn.QuoteUnpickler_unpickleTypeV2 - else defn.QuoteUnpickler_unpickleExprV2 + if isType then defn.QuoteUnpickler_unpickleTypeV2 + else defn.QuoteUnpickler_unpickleExprV2 val unpickleArgs = - if isType && !unpickleV1 then List(pickledQuoteStrings, types) + if isType then List(pickledQuoteStrings, types) else List(pickledQuoteStrings, types, termHoles) quotes .asInstance(defn.QuoteUnpicklerClass.typeRef) diff --git a/compiler/src/dotty/tools/dotc/transform/Splicing.scala b/compiler/src/dotty/tools/dotc/transform/Splicing.scala index 7f99ad57b2d0..fe0c233173b7 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicing.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicing.scala @@ -135,13 +135,7 @@ class Splicing extends MacroTransform: val hole = tpd.Hole(false, holeIdx, Nil, ref(qual), TypeTree(tp)) typeHoles.put(qual.symbol, hole) hole - val rhs = - if ctx.scalaRelease <= Release3_1 then - val secondHoleIdx = numHoles - numHoles += 1 - TypeBoundsTree(hole, cpy.Hole(hole)(idx = secondHoleIdx)) - else hole - cpy.TypeDef(tree)(rhs = rhs) + cpy.TypeDef(tree)(rhs = hole) case Apply(Select(Apply(TypeApply(fn,_), List(code)),nme.apply),List(quotes)) if fn.symbol == defn.QuotedRuntime_exprQuote => super.transform(tree)(using quoteContext) diff --git a/sbt-test/scala3-compat/macros-forward-3.0/app/App.scala b/sbt-test/scala3-compat/macros-forward-3.0/app/App.scala deleted file mode 100644 index ce7bf1b45b13..000000000000 --- a/sbt-test/scala3-compat/macros-forward-3.0/app/App.scala +++ /dev/null @@ -1,17 +0,0 @@ -package app - -import lib.* - -def powerTest(x: Double): Unit = - power(x, 0) - power(x, 1) - power(x, 5) - power(x, 10) - -def letTest: Unit = - let(0) { _ + 1 } - let(0) { _.toString } - let((4, 'a')) { _.swap } - let(new Foo) { _.hashCode } - -class Foo diff --git a/sbt-test/scala3-compat/macros-forward-3.0/build.sbt b/sbt-test/scala3-compat/macros-forward-3.0/build.sbt deleted file mode 100644 index 974fd6cff6cc..000000000000 --- a/sbt-test/scala3-compat/macros-forward-3.0/build.sbt +++ /dev/null @@ -1,14 +0,0 @@ -lazy val checkOptions = Seq("-Xcheck-macros", "-Ycheck:all", "-Yno-double-bindings") - -lazy val lib = project.in(file("lib")) - .settings( - scalacOptions ++= Seq("-scala-output-version", "3.0") ++ checkOptions - ) - -lazy val app = project.in(file("app")) - .dependsOn(lib) - .settings( - scalaVersion := "3.0.2", - scalacOptions ++= checkOptions, - dependencyOverrides += scalaOrganization.value %% "scala3-library" % scalaVersion.value, - ) diff --git a/sbt-test/scala3-compat/macros-forward-3.0/lib/Macro.scala b/sbt-test/scala3-compat/macros-forward-3.0/lib/Macro.scala deleted file mode 100644 index 12e69a6ce4fd..000000000000 --- a/sbt-test/scala3-compat/macros-forward-3.0/lib/Macro.scala +++ /dev/null @@ -1,20 +0,0 @@ -package lib - -import scala.quoted.* - -inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } - -private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = - unrolledPowerCode(x, n.valueOrError) - -private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = - if n == 0 then '{ 1.0 } // tests simple quotes without splices - else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices - else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture - - -inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } - -private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = - // tests use of Type - '{ val y: T = $x; $body(y): U } diff --git a/sbt-test/scala3-compat/macros-forward-3.0/project/DottyInjectedPlugin.scala b/sbt-test/scala3-compat/macros-forward-3.0/project/DottyInjectedPlugin.scala deleted file mode 100644 index fb946c4b8c61..000000000000 --- a/sbt-test/scala3-compat/macros-forward-3.0/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/scala3-compat/macros-forward-3.0/test b/sbt-test/scala3-compat/macros-forward-3.0/test deleted file mode 100644 index 19aca297fdcf..000000000000 --- a/sbt-test/scala3-compat/macros-forward-3.0/test +++ /dev/null @@ -1 +0,0 @@ -> app/compile diff --git a/tests/disabled/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala b/tests/disabled/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala deleted file mode 100644 index fb06e93f91c0..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala +++ /dev/null @@ -1,20 +0,0 @@ -import scala.quoted.* - -object Macros: - - inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } - - private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = - unrolledPowerCode(x, n.valueOrError) - - private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = - if n == 0 then '{ 1.0 } // tests simple quotes without splices - else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices - else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture - - - inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } - - private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = - // tests use of Type - '{ val y: T = $x; $body(y): U } diff --git a/tests/disabled/pos-macros/forwardCompat-3.0/Test_2_c3.0.2.scala b/tests/disabled/pos-macros/forwardCompat-3.0/Test_2_c3.0.2.scala deleted file mode 100644 index 8c0a8004b9cf..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.0/Test_2_c3.0.2.scala +++ /dev/null @@ -1,15 +0,0 @@ -import Macros.* - -def powerTest(x: Double): Unit = - power(x, 0) - power(x, 1) - power(x, 5) - power(x, 10) - -def letTest: Unit = - let(0) { _ + 1 } - let(0) { _.toString } - let((4, 'a')) { _.swap } - let(new Foo) { _.hashCode } - -class Foo diff --git a/tests/disabled/pos-macros/forwardCompat-3.0/why.md b/tests/disabled/pos-macros/forwardCompat-3.0/why.md deleted file mode 100644 index efb05ec1e0f4..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.0/why.md +++ /dev/null @@ -1,3 +0,0 @@ -Fails `testCompilation` as if the release flag was not set. But it was and the compile used it. - -Manual tests show that this does work. diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala deleted file mode 100644 index fb06e93f91c0..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala +++ /dev/null @@ -1,20 +0,0 @@ -import scala.quoted.* - -object Macros: - - inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) } - - private def powerCode(x: Expr[Double], n: Expr[Int])(using Quotes): Expr[Double] = - unrolledPowerCode(x, n.valueOrError) - - private def unrolledPowerCode(x: Expr[Double], n: Int)(using Quotes): Expr[Double] = - if n == 0 then '{ 1.0 } // tests simple quotes without splices - else if n % 2 == 1 then '{ $x * ${ unrolledPowerCode(x, n - 1) } } // tests simple splices - else '{ val y = $x * $x; ${ unrolledPowerCode('y, n / 2) } } // tests splice with term capture - - - inline def let[T, U](x: T)(inline body: T => U): U = ${ letCode('x, 'body) } - - private def letCode[T: Type, U: Type](x: Expr[T], body: Expr[T => U])(using Quotes): Expr[U] = - // tests use of Type - '{ val y: T = $x; $body(y): U } diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala b/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala deleted file mode 100644 index 8c0a8004b9cf..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala +++ /dev/null @@ -1,15 +0,0 @@ -import Macros.* - -def powerTest(x: Double): Unit = - power(x, 0) - power(x, 1) - power(x, 5) - power(x, 10) - -def letTest: Unit = - let(0) { _ + 1 } - let(0) { _.toString } - let((4, 'a')) { _.swap } - let(new Foo) { _.hashCode } - -class Foo diff --git a/tests/disabled/pos-macros/forwardCompat-3.1/why.md b/tests/disabled/pos-macros/forwardCompat-3.1/why.md deleted file mode 100644 index f281f9c08662..000000000000 --- a/tests/disabled/pos-macros/forwardCompat-3.1/why.md +++ /dev/null @@ -1 +0,0 @@ -Disabled until https://github.com/lampepfl/dotty/issues/14306 is fixed