Skip to content

Commit

Permalink
Remove support -scala-output-version with quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Apr 19, 2022
1 parent 2005c87 commit 0683579
Show file tree
Hide file tree
Showing 15 changed files with 9 additions and 184 deletions.
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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[?]))
Expand All @@ -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[?]))
Expand Down
42 changes: 6 additions & 36 deletions compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 =
Expand All @@ -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?
Expand All @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions compiler/src/dotty/tools/dotc/transform/Splicing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 0 additions & 17 deletions sbt-test/scala3-compat/macros-forward-3.0/app/App.scala

This file was deleted.

14 changes: 0 additions & 14 deletions sbt-test/scala3-compat/macros-forward-3.0/build.sbt

This file was deleted.

20 changes: 0 additions & 20 deletions sbt-test/scala3-compat/macros-forward-3.0/lib/Macro.scala

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion sbt-test/scala3-compat/macros-forward-3.0/test

This file was deleted.

20 changes: 0 additions & 20 deletions tests/disabled/pos-macros/forwardCompat-3.0/Macro_1_r3.0.scala

This file was deleted.

15 changes: 0 additions & 15 deletions tests/disabled/pos-macros/forwardCompat-3.0/Test_2_c3.0.2.scala

This file was deleted.

3 changes: 0 additions & 3 deletions tests/disabled/pos-macros/forwardCompat-3.0/why.md

This file was deleted.

20 changes: 0 additions & 20 deletions tests/disabled/pos-macros/forwardCompat-3.1/Macro_1_r3.1.scala

This file was deleted.

15 changes: 0 additions & 15 deletions tests/disabled/pos-macros/forwardCompat-3.1/Test_2_c3.1.0.scala

This file was deleted.

1 change: 0 additions & 1 deletion tests/disabled/pos-macros/forwardCompat-3.1/why.md

This file was deleted.

0 comments on commit 0683579

Please sign in to comment.