Skip to content

Commit f3c260b

Browse files
committed
Move Liftable into the Universe cake; add additional standard Liftables
Previously we believed that having Liftable outside of the Universe will bring some advantages but it turned out this wasn’t worth it. Due to infectious nature of path dependent types inside of the universe one had to cast a lot. A nice example of what I’m talking about is a change in trait ArbitraryTreesAndNames. Additionally a number of standard Liftables is added for types that are available through Predef and/or default scala._ import: Array, Vector, List, Map, Set, Option, Either, TupleN.
1 parent 26a3348 commit f3c260b

File tree

10 files changed

+153
-80
lines changed

10 files changed

+153
-80
lines changed

src/compiler/scala/tools/reflect/quasiquotes/Holes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ trait Holes { self: Quasiquotes =>
8080
def cardinality(tpe: Type): Cardinality = parseCardinality(tpe)._1
8181

8282
def lifter(tpe: Type): Option[Tree => Tree] = {
83-
val lifterTpe = appliedType(LiftableClass.toType, List(tpe))
83+
val lifterTpe = appliedType(liftableType, List(tpe))
8484
val lifter = c.inferImplicitValue(lifterTpe, silent = true)
8585
if (lifter != EmptyTree) Some(tree => {
86-
val lifted = Apply(lifter, List(u, tree))
86+
val lifted = Apply(lifter, List(tree))
8787
val targetType = Select(u, tpnme.Tree)
8888
atPos(tree.pos)(TypeApply(Select(lifted, nme.asInstanceOf_), List(targetType)))
8989
}) else None

src/reflect/scala/reflect/api/Liftable.scala

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/reflect/scala/reflect/api/StandardLiftables.scala

Lines changed: 110 additions & 22 deletions
Large diffs are not rendered by default.

src/reflect/scala/reflect/api/StandardNames.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ trait StandardNames {
9696
* of non-private vals and vars are renamed using `LOCAL_SUFFIX_STRING`.
9797
*/
9898
val LOCAL_SUFFIX_STRING: String
99+
100+
protected[reflect] val Array: NameType
101+
protected[reflect] val collection: NameType
102+
protected[reflect] val immutable: NameType
103+
protected[reflect] val Left: NameType
104+
protected[reflect] val List: NameType
105+
protected[reflect] val Map: NameType
106+
protected[reflect] val None: NameType
107+
protected[reflect] val Right: NameType
108+
protected[reflect] val Set: NameType
109+
protected[reflect] val Some: NameType
110+
protected[reflect] val Symbol: NameType
111+
protected[reflect] val util: NameType
112+
protected[reflect] val Vector: NameType
99113
}
100114

101115
/** Defines standard type names that can be accessed via the [[tpnme]] member.

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ trait Definitions extends api.StandardDefinitions {
481481

482482
lazy val TypeCreatorClass = getClassIfDefined("scala.reflect.api.TypeCreator") // defined in scala-reflect.jar, so we need to be careful
483483
lazy val TreeCreatorClass = getClassIfDefined("scala.reflect.api.TreeCreator") // defined in scala-reflect.jar, so we need to be careful
484-
lazy val LiftableClass = getClassIfDefined("scala.reflect.api.Liftable") // defined in scala-reflect.jar, so we need to be careful
484+
lazy val LiftableClass = NoSymbol
485485

486486
lazy val BlackboxMacroClass = getClassIfDefined("scala.reflect.macros.BlackboxMacro") // defined in scala-reflect.jar, so we need to be careful
487487
def BlackboxMacroContextValue = BlackboxMacroClass.map(sym => getMemberValue(sym, nme.c))
@@ -1371,6 +1371,7 @@ trait Definitions extends api.StandardDefinitions {
13711371
lazy val symbolType = universeMemberType(tpnme.Symbol)
13721372
lazy val treeType = universeMemberType(tpnme.Tree)
13731373
lazy val caseDefType = universeMemberType(tpnme.CaseDef)
1374+
lazy val liftableType = universeMemberType(tpnme.Liftable)
13741375
lazy val iterableTreeType = appliedType(IterableClass, treeType)
13751376
lazy val listTreeType = appliedType(ListClass, treeType)
13761377
lazy val listListTreeType = appliedType(ListClass, listTreeType)

src/reflect/scala/reflect/internal/StdNames.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ trait StdNames {
124124
final val AnyRef: NameType = "AnyRef"
125125
final val Array: NameType = "Array"
126126
final val List: NameType = "List"
127+
final val Left: NameType = "Left"
128+
final val Right: NameType = "Right"
129+
final val Vector: NameType = "Vector"
127130
final val Seq: NameType = "Seq"
131+
final val Set: NameType = "Set"
132+
final val Some: NameType = "Some"
128133
final val Symbol: NameType = "Symbol"
134+
final val Map: NameType = "Map"
135+
final val None: NameType = "None"
129136
final val WeakTypeTag: NameType = "WeakTypeTag"
130137
final val TypeTag : NameType = "TypeTag"
131138
final val Expr: NameType = "Expr"
@@ -239,6 +246,7 @@ trait StdNames {
239246
final val Enum: NameType = "Enum"
240247
final val Group: NameType = "Group"
241248
final val implicitNotFound: NameType = "implicitNotFound"
249+
final val Liftable: NameType = "Liftable"
242250
final val Name: NameType = "Name"
243251
final val Tree: NameType = "Tree"
244252
final val TermName: NameType = "TermName"
@@ -753,6 +761,7 @@ trait StdNames {
753761
val typedProductIterator: NameType = "typedProductIterator"
754762
val TypeName: NameType = "TypeName"
755763
val typeTagToManifest: NameType = "typeTagToManifest"
764+
val util: NameType = "util"
756765
val unapply: NameType = "unapply"
757766
val unapplySeq: NameType = "unapplySeq"
758767
val unbox: NameType = "unbox"
@@ -786,7 +795,7 @@ trait StdNames {
786795
final val STAR : NameType = "*"
787796
final val TILDE: NameType = "~"
788797

789-
final val isUnary: Set[Name] = Set(MINUS, PLUS, TILDE, BANG)
798+
final val isUnary: Set[Name] = scala.collection.immutable.Set(MINUS, PLUS, TILDE, BANG)
790799
}
791800

792801
// value-conversion methods
@@ -839,8 +848,8 @@ trait StdNames {
839848
val UNARY_! = encode("unary_!")
840849

841850
// Grouped here so Cleanup knows what tests to perform.
842-
val CommonOpNames = Set[Name](OR, XOR, AND, EQ, NE)
843-
val BooleanOpNames = Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
851+
val CommonOpNames = scala.collection.immutable.Set[Name](OR, XOR, AND, EQ, NE)
852+
val BooleanOpNames = scala.collection.immutable.Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
844853

845854
val add: NameType = "add"
846855
val complement: NameType = "complement"

src/reflect/scala/reflect/runtime/JavaUniverseForce.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
204204
this.TermName
205205
this.TypeName
206206
this.BooleanFlag
207+
this.Liftable
207208
this.WeakTypeTag
208209
this.TypeTag
209210
this.Expr

test/files/pos/macro-implicit-invalidate-on-error.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
package scala.reflect
2-
package api
3-
41
import scala.language.experimental.macros
52
import scala.reflect.macros.Context
63

7-
trait Liftable[T] {
8-
def apply(universe: api.Universe, value: T): universe.Tree
4+
trait LegacyLiftable[T] {
5+
def apply(universe: scala.reflect.api.Universe, value: T): universe.Tree
96
}
107

11-
object Liftable {
12-
implicit def liftCaseClass[T <: Product]: Liftable[T] = macro liftCaseClassImpl[T]
8+
object LegacyLiftable {
9+
implicit def liftCaseClass[T <: Product]: LegacyLiftable[T] = macro liftCaseClassImpl[T]
1310

14-
def liftCaseClassImpl[T: c.WeakTypeTag](c: Context): c.Expr[Liftable[T]] = {
11+
def liftCaseClassImpl[T: c.WeakTypeTag](c: Context): c.Expr[LegacyLiftable[T]] = {
1512
import c.universe._
1613
val tpe = weakTypeOf[T]
1714
if (!tpe.typeSymbol.asClass.isCaseClass) c.abort(c.enclosingPosition, "denied")
1815
val p = List(q"Literal(Constant(1))")
19-
c.Expr[Liftable[T]] { q"""
20-
new scala.reflect.api.Liftable[$tpe] {
16+
c.Expr[LegacyLiftable[T]] { q"""
17+
new LegacyLiftable[$tpe] {
2118
def apply(universe: scala.reflect.api.Universe, value: $tpe): universe.Tree = {
2219
import universe._
2320
Apply(Select(Ident(TermName("C")), TermName("apply")), List(..$p))

test/files/scalacheck/quasiquotes/ArbitraryTreesAndNames.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.scalacheck._, Prop._, Gen._, Arbitrary._
2-
import scala.reflect.api.{Liftable, Universe}
32
import scala.reflect.runtime.universe._, Flag._
43

54
trait ArbitraryTreesAndNames {
@@ -265,14 +264,8 @@ trait ArbitraryTreesAndNames {
265264
def genTreeIsTypeWrapped(size: Int) =
266265
for(tit <- genTreeIsType(size)) yield TreeIsType(tit)
267266

268-
implicit object liftTreeIsTerm extends Liftable[TreeIsTerm] {
269-
def apply(universe: Universe, value: TreeIsTerm): universe.Tree =
270-
value.tree.asInstanceOf[universe.Tree]
271-
}
272-
implicit object liftTreeIsType extends Liftable[TreeIsType] {
273-
def apply(universe: Universe, value: TreeIsType): universe.Tree =
274-
value.tree.asInstanceOf[universe.Tree]
275-
}
267+
implicit val liftTreeIsTerm = Liftable[TreeIsTerm] { _.tree }
268+
implicit val liftTreeIsType = Liftable[TreeIsType] { _.tree }
276269
implicit def treeIsTerm2tree(tit: TreeIsTerm): Tree = tit.tree
277270
implicit def treeIsType2tree(tit: TreeIsType): Tree = tit.tree
278271

test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,6 @@ trait Helpers {
120120
def annot(name: TypeName): Tree = annot(name, Nil)
121121
def annot(name: String, args: List[Tree]): Tree = annot(TypeName(name), args)
122122
def annot(name: TypeName, args: List[Tree]): Tree = q"new $name(..$args)"
123-
}
123+
124+
val scalapkg = build.setSymbol(Ident(TermName("scala")), definitions.ScalaPackage)
125+
}

0 commit comments

Comments
 (0)