Skip to content

Commit 013acf6

Browse files
committed
renames asType to toType and asXXXSymbol to asXXX
This renaming arguably makes the intent of `asType` more clear, but more importantly it shaves 6 symbols off pervasive casts that are required to anything meaningful with reflection API (as in mirror.reflectMethod(tpe.member(newTermName("x")).asMethodSymbol)).
1 parent 367b82d commit 013acf6

File tree

45 files changed

+182
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+182
-181
lines changed

src/compiler/scala/reflect/makro/runtime/ExprUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait ExprUtils {
2929

3030
def literal(x: Double) = Expr[Double](Literal(Constant(x)))(TypeTag.Double)
3131

32-
def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.asTypeConstructor))
32+
def literal(x: String) = Expr[String](Literal(Constant(x)))(TypeTag[String](definitions.StringClass.toTypeConstructor))
3333

3434
def literal(x: Char) = Expr[Char](Literal(Constant(x)))(TypeTag.Char)
3535
}

src/compiler/scala/reflect/makro/runtime/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait Typers {
3737

3838
def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = {
3939
macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s".format(from, to, tree, !withMacrosDisabled))
40-
val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).asTypeConstructor, List(from, to))
40+
val viewTpe = universe.appliedType(universe.definitions.FunctionClass(1).toTypeConstructor, List(from, to))
4141
inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos)
4242
}
4343

src/compiler/scala/reflect/reify/codegen/GenSymbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait GenSymbols {
3636
else if (sym.isEmptyPackageClass)
3737
mirrorMirrorSelect(nme.EmptyPackageClass)
3838
else if (sym.isModuleClass)
39-
Select(Select(reify(sym.sourceModule), nme.asModuleSymbol), nme.moduleClass)
39+
Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass)
4040
else if (sym.isPackage)
4141
mirrorMirrorCall(nme.staticPackage, reify(sym.fullName))
4242
else if (sym.isLocatable) {

src/compiler/scala/reflect/reify/codegen/GenTypes.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait GenTypes {
3030

3131
val tsym = tpe.typeSymbolDirect
3232
if (tsym.isClass && tpe == tsym.typeConstructor && tsym.isStatic)
33-
Select(Select(reify(tsym), nme.asTypeSymbol), nme.asTypeConstructor)
33+
Select(Select(reify(tsym), nme.asType), nme.toTypeConstructor)
3434
else tpe match {
3535
case tpe @ NoType =>
3636
reifyMirrorObject(tpe)
@@ -42,7 +42,7 @@ trait GenTypes {
4242
mirrorBuildCall(nme.thisPrefix, mirrorMirrorSelect(nme.EmptyPackageClass))
4343
case tpe @ ThisType(clazz) if clazz.isModuleClass && clazz.isStatic =>
4444
val module = reify(clazz.sourceModule)
45-
val moduleClass = Select(Select(module, nme.asModuleSymbol), nme.moduleClass)
45+
val moduleClass = Select(Select(module, nme.asModule), nme.moduleClass)
4646
mirrorFactoryCall(nme.ThisType, moduleClass)
4747
case tpe @ ThisType(_) =>
4848
reifyProduct(tpe)
@@ -94,7 +94,7 @@ trait GenTypes {
9494
}
9595
case success =>
9696
if (reifyDebug) println("implicit search has produced a result: " + success)
97-
state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.asTypeConstructor
97+
state.reificationIsConcrete &= concrete || success.tpe <:< TypeTagClass.toTypeConstructor
9898
Select(Apply(Select(success, nme.in), List(Ident(nme.MIRROR_SHORT))), nme.tpe)
9999
}
100100
if (result != EmptyTree) return result
@@ -109,7 +109,7 @@ trait GenTypes {
109109
def searchForManifest(typer: analyzer.Typer): Tree =
110110
analyzer.inferImplicit(
111111
EmptyTree,
112-
appliedType(FullManifestClass.asTypeConstructor, List(tpe)),
112+
appliedType(FullManifestClass.toTypeConstructor, List(tpe)),
113113
reportAmbiguous = false,
114114
isView = false,
115115
context = typer.context,

src/compiler/scala/reflect/reify/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package object reify {
2929
import definitions._
3030
val enclosingErasure = reifyEnclosingRuntimeClass(global)(typer0)
3131
// JavaUniverse is defined in scala-reflect.jar, so we must be very careful in case someone reifies stuff having only scala-library.jar on the classpath
32-
val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.asTypeConstructor
32+
val isJavaUniverse = JavaUniverseClass != NoSymbol && universe.tpe <:< JavaUniverseClass.toTypeConstructor
3333
if (isJavaUniverse && !enclosingErasure.isEmpty) Apply(Select(universe, nme.runtimeMirror), List(Select(enclosingErasure, sn.GetClassLoader)))
3434
else Select(universe, nme.rootMirror)
3535
}
@@ -69,7 +69,7 @@ package object reify {
6969
if (isThisInScope) {
7070
val enclosingClasses = typer0.context.enclosingContextChain map (_.tree) collect { case classDef: ClassDef => classDef }
7171
val classInScope = enclosingClasses.headOption getOrElse EmptyTree
72-
if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.asTypeConstructor, concrete = true)
72+
if (!classInScope.isEmpty) reifyRuntimeClass(global)(typer0, classInScope.symbol.toTypeConstructor, concrete = true)
7373
else Select(This(tpnme.EMPTY), sn.GetClass)
7474
} else EmptyTree
7575
}

src/compiler/scala/reflect/reify/utils/Extractors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait Extractors {
4040
// def apply[U >: Nothing <: scala.reflect.base.Universe with Singleton]($m$untyped: scala.reflect.base.MirrorOf[U]): U#Type = {
4141
// val $u: U = $m$untyped.universe;
4242
// val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
43-
// $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").asTypeConstructor))
43+
// $u.TypeRef($u.ThisType($m.staticPackage("scala.collection.immutable").moduleClass), $m.staticClass("scala.collection.immutable.List"), List($m.staticClass("scala.Int").toTypeConstructor))
4444
// }
4545
// };
4646
// new $typecreator1()

src/compiler/scala/tools/nsc/typechecker/Tags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ trait Tags {
6161
*/
6262
def resolveTypeTag(pos: Position, pre: Type, tp: Type, concrete: Boolean, allowMaterialization: Boolean = true): Tree = {
6363
val tagSym = if (concrete) TypeTagClass else AbsTypeTagClass
64-
val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.asTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name)
64+
val tagTp = if (pre == NoType) TypeRef(BaseUniverseClass.toTypeConstructor, tagSym, List(tp)) else singleType(pre, pre member tagSym.name)
6565
val taggedTp = appliedType(tagTp, List(tp))
6666
resolveTag(pos, taggedTp, allowMaterialization)
6767
}

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5089,7 +5089,7 @@ trait Typers extends Modes with Adaptations with Tags {
50895089
// convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len), where Array HK gets applied (N-1) times
50905090
// [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions)
50915091
val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe)
5092-
val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.asType, List(tpe))).last
5092+
val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last
50935093
val newArrayApp = atPos(tree.pos) {
50945094
val tag = resolveClassTag(tree.pos, tagType)
50955095
if (tag.isEmpty) MissingClassTagError(tree, tagType)

src/compiler/scala/tools/reflect/StdTags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait StdTags {
2020
def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type = {
2121
val u = m.universe
2222
val pre = u.ThisType(m.staticPackage("scala.collection.immutable").moduleClass.asInstanceOf[u.Symbol])
23-
u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.asTypeConstructor))
23+
u.TypeRef(pre, u.definitions.ListClass, List(u.definitions.StringClass.toTypeConstructor))
2424
}
2525
})
2626

@@ -29,7 +29,7 @@ trait StdTags {
2929
m,
3030
new TypeCreator {
3131
def apply[U <: BaseUniverse with Singleton](m: MirrorOf[U]): U # Type =
32-
m.staticClass(classTag[T].runtimeClass.getName).asTypeConstructor.asInstanceOf[U # Type]
32+
m.staticClass(classTag[T].runtimeClass.getName).toTypeConstructor.asInstanceOf[U # Type]
3333
})
3434
lazy val tagOfInt = u.TypeTag.Int
3535
lazy val tagOfString = tagOfStaticClass[String]

src/compiler/scala/tools/reflect/ToolBoxFactory.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
8585
if (tree.hasSymbol && tree.symbol.isFreeTerm) {
8686
tree match {
8787
case Ident(_) =>
88-
val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTermSymbol))
88+
val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTerm))
8989
if (wrapFreeTermRefs) Apply(freeTermRef, List()) else freeTermRef
9090
case _ =>
9191
throw new Error("internal error: %s (%s, %s) is not supported".format(tree, tree.productPrefix, tree.getClass))
@@ -350,7 +350,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
350350
}
351351

352352
def inferImplicitView(tree: u.Tree, from: u.Type, to: u.Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: u.Position = u.NoPosition): u.Tree = {
353-
val viewTpe = u.appliedType(u.definitions.FunctionClass(1).asTypeConstructor, List(from, to))
353+
val viewTpe = u.appliedType(u.definitions.FunctionClass(1).toTypeConstructor, List(from, to))
354354
inferImplicit(tree, viewTpe, isView = true, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = pos)
355355
}
356356

0 commit comments

Comments
 (0)