Skip to content

Commit de66494

Browse files
committed
Remove TermName -> String implicit.
These implicits were crutches going back to a much Stringier time. Of course "with great type safety comes great verbosity" and no doubt this could be cleaned up significantly further. At least the underpinnings are consistent now - the only implicits involving name should be String -> TypeName and String -> TermName.
1 parent 47245f5 commit de66494

File tree

15 files changed

+52
-61
lines changed

15 files changed

+52
-61
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ trait GenSymbols {
9898
def reifyFreeTerm(binding: Tree): Tree =
9999
reifyIntoSymtab(binding.symbol) { sym =>
100100
if (reifyDebug) println("Free term" + (if (sym.isCapturedVariable) " (captured)" else "") + ": " + sym + "(" + sym.accurateKindString + ")")
101-
val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name + (if (sym.isType) nme.REIFY_FREE_THIS_SUFFIX else ""))
101+
val name = newTermName("" + nme.REIFY_FREE_PREFIX + sym.name + (if (sym.isType) nme.REIFY_FREE_THIS_SUFFIX else ""))
102102
if (sym.isCapturedVariable) {
103103
assert(binding.isInstanceOf[Ident], showRaw(binding))
104104
val capturedBinding = referenceCapturedVariable(sym)
@@ -112,14 +112,14 @@ trait GenSymbols {
112112
reifyIntoSymtab(binding.symbol) { sym =>
113113
if (reifyDebug) println("Free type: %s (%s)".format(sym, sym.accurateKindString))
114114
state.reificationIsConcrete = false
115-
val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name)
115+
val name: TermName = nme.REIFY_FREE_PREFIX append sym.name
116116
Reification(name, binding, mirrorBuildCall(nme.newFreeType, reify(sym.name.toString), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym))))
117117
}
118118

119119
def reifySymDef(sym: Symbol): Tree =
120120
reifyIntoSymtab(sym) { sym =>
121121
if (reifyDebug) println("Sym def: %s (%s)".format(sym, sym.accurateKindString))
122-
val name = newTermName(nme.REIFY_SYMDEF_PREFIX + sym.name)
122+
val name: TermName = nme.REIFY_SYMDEF_PREFIX append sym.name
123123
def reifiedOwner = if (sym.owner.isLocatable) reify(sym.owner) else reifySymDef(sym.owner)
124124
Reification(name, Ident(sym), mirrorBuildCall(nme.newNestedSymbol, reifiedOwner, reify(sym.name), reify(sym.pos), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(sym.isClass)))
125125
}

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,35 @@ trait GenUtils {
3030
def call(fname: String, args: Tree*): Tree =
3131
Apply(termPath(fname), args.toList)
3232

33-
def mirrorSelect(name: String): Tree =
34-
termPath(nme.UNIVERSE_PREFIX + name)
33+
def mirrorSelect(name: String): Tree = termPath(nme.UNIVERSE_PREFIX + name)
34+
def mirrorSelect(name: TermName): Tree = mirrorSelect(name.toString)
3535

36-
def mirrorBuildSelect(name: String): Tree =
37-
termPath(nme.UNIVERSE_BUILD_PREFIX + name)
36+
def mirrorBuildSelect(name: TermName): Tree =
37+
termPath("" + nme.UNIVERSE_BUILD_PREFIX + name)
3838

39-
def mirrorMirrorSelect(name: String): Tree =
40-
termPath(nme.MIRROR_PREFIX + name)
39+
def mirrorMirrorSelect(name: TermName): Tree =
40+
termPath("" + nme.MIRROR_PREFIX + name)
4141

4242
def mirrorCall(name: TermName, args: Tree*): Tree =
43-
call("" + (nme.UNIVERSE_PREFIX append name), args: _*)
44-
45-
def mirrorCall(name: String, args: Tree*): Tree =
46-
call(nme.UNIVERSE_PREFIX + name, args: _*)
43+
call("" + nme.UNIVERSE_PREFIX + name, args: _*)
4744

4845
def mirrorBuildCall(name: TermName, args: Tree*): Tree =
49-
call("" + (nme.UNIVERSE_BUILD_PREFIX append name), args: _*)
50-
51-
def mirrorBuildCall(name: String, args: Tree*): Tree =
52-
call(nme.UNIVERSE_BUILD_PREFIX + name, args: _*)
46+
call("" + nme.UNIVERSE_BUILD_PREFIX + name, args: _*)
5347

5448
def mirrorMirrorCall(name: TermName, args: Tree*): Tree =
55-
call("" + (nme.MIRROR_PREFIX append name), args: _*)
56-
57-
def mirrorMirrorCall(name: String, args: Tree*): Tree =
58-
call(nme.MIRROR_PREFIX + name, args: _*)
49+
call("" + nme.MIRROR_PREFIX + name, args: _*)
5950

6051
def mirrorFactoryCall(value: Product, args: Tree*): Tree =
6152
mirrorFactoryCall(value.productPrefix, args: _*)
6253

63-
def mirrorFactoryCall(prefix: String, args: Tree*): Tree =
64-
mirrorCall(prefix, args: _*)
54+
def mirrorFactoryCall(prefix: TermName, args: Tree*): Tree =
55+
mirrorCall("" + prefix, args: _*)
56+
57+
def scalaFactoryCall(name: TermName, args: Tree*): Tree =
58+
call(s"scala.$name.apply", args: _*)
6559

6660
def scalaFactoryCall(name: String, args: Tree*): Tree =
67-
call("scala." + name + ".apply", args: _*)
61+
scalaFactoryCall(name: TermName, args: _*)
6862

6963
def mkList(args: List[Tree]): Tree =
7064
scalaFactoryCall("collection.immutable.List", args: _*)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ trait NodePrinters {
7575
printout += universe.trim
7676
if (mirrorIsUsed) printout += mirror.replace("Mirror[", "scala.reflect.api.Mirror[").trim
7777
val imports = scala.collection.mutable.ListBuffer[String]();
78-
imports += nme.UNIVERSE_SHORT
78+
imports += nme.UNIVERSE_SHORT.toString
7979
// if (buildIsUsed) imports += nme.build
80-
if (mirrorIsUsed) imports += nme.MIRROR_SHORT
81-
if (flagsAreUsed) imports += nme.Flag
80+
if (mirrorIsUsed) imports += nme.MIRROR_SHORT.toString
81+
if (flagsAreUsed) imports += nme.Flag.toString
8282
printout += s"""import ${imports map (_ + "._") mkString ", "}"""
8383

8484
val name = if (isExpr) "tree" else "tpe"

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ abstract class GenICode extends SubComponent {
15651565
*/
15661566
def genEqEqPrimitive(l: Tree, r: Tree, ctx: Context)(thenCtx: Context, elseCtx: Context): Unit = {
15671567
def getTempLocal = ctx.method.lookupLocal(nme.EQEQ_LOCAL_VAR) getOrElse {
1568-
ctx.makeLocal(l.pos, AnyRefClass.tpe, nme.EQEQ_LOCAL_VAR)
1568+
ctx.makeLocal(l.pos, AnyRefClass.tpe, nme.EQEQ_LOCAL_VAR.toString)
15691569
}
15701570

15711571
/** True if the equality comparison is between values that require the use of the rich equality

src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
11981198
/* Typestate: should be called before emitting fields (because it adds an IField to the current IClass). */
11991199
def addCreatorCode(block: BasicBlock) {
12001200
val fieldSymbol = (
1201-
clasz.symbol.newValue(newTermName(androidFieldName), NoPosition, Flags.STATIC | Flags.FINAL)
1201+
clasz.symbol.newValue(androidFieldName, NoPosition, Flags.STATIC | Flags.FINAL)
12021202
setInfo AndroidCreatorClass.tpe
12031203
)
12041204
val methodSymbol = definitions.getMember(clasz.symbol.companionModule, androidFieldName)
@@ -1213,7 +1213,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
12131213

12141214
jclass.visitField(
12151215
PublicStaticFinal,
1216-
androidFieldName,
1216+
androidFieldName.toString,
12171217
tdesc_creator,
12181218
null, // no java-generic-signature
12191219
null // no initial value
@@ -1233,15 +1233,15 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
12331233
clinit.visitMethodInsn(
12341234
asm.Opcodes.INVOKEVIRTUAL,
12351235
moduleName,
1236-
androidFieldName,
1236+
androidFieldName.toString,
12371237
asm.Type.getMethodDescriptor(creatorType, Array.empty[asm.Type]: _*)
12381238
)
12391239

12401240
// PUTSTATIC `thisName`.CREATOR;
12411241
clinit.visitFieldInsn(
12421242
asm.Opcodes.PUTSTATIC,
12431243
thisName,
1244-
androidFieldName,
1244+
androidFieldName.toString,
12451245
tdesc_creator
12461246
)
12471247
}

src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait GenAndroid {
3535
def addCreatorCode(codegen: BytecodeGenerator, block: BasicBlock) {
3636
import codegen._
3737
val fieldSymbol = (
38-
clasz.symbol.newValue(newTermName(fieldName), NoPosition, Flags.STATIC | Flags.FINAL)
38+
clasz.symbol.newValue(fieldName, NoPosition, Flags.STATIC | Flags.FINAL)
3939
setInfo AndroidCreatorClass.tpe
4040
)
4141
val methodSymbol = definitions.getMember(clasz.symbol.companionModule, fieldName)
@@ -48,15 +48,15 @@ trait GenAndroid {
4848
import codegen._
4949
val creatorType = javaType(AndroidCreatorClass)
5050
jclass.addNewField(PublicStaticFinal,
51-
fieldName,
51+
fieldName.toString,
5252
creatorType)
5353
val moduleName = javaName(clasz.symbol)+"$"
5454
clinit.emitGETSTATIC(moduleName,
5555
nme.MODULE_INSTANCE_FIELD.toString,
5656
new JObjectType(moduleName))
57-
clinit.emitINVOKEVIRTUAL(moduleName, fieldName,
57+
clinit.emitINVOKEVIRTUAL(moduleName, fieldName.toString,
5858
new JMethodType(creatorType, Array()))
59-
clinit.emitPUTSTATIC(jclass.getName(), fieldName, creatorType)
59+
clinit.emitPUTSTATIC(jclass.getName(), fieldName.toString, creatorType)
6060
}
6161

6262
}

src/compiler/scala/tools/nsc/interactive/Global.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
810810
respond(response) { scopeMembers(pos) }
811811
}
812812

813-
private val Dollar = newTermName("$")
814-
815813
private class Members[M <: Member] extends LinkedHashMap[Name, Set[M]] {
816814
override def default(key: Name) = Set()
817815

@@ -827,7 +825,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
827825
def add(sym: Symbol, pre: Type, implicitlyAdded: Boolean)(toMember: (Symbol, Type) => M) {
828826
if ((sym.isGetter || sym.isSetter) && sym.accessed != NoSymbol) {
829827
add(sym.accessed, pre, implicitlyAdded)(toMember)
830-
} else if (!sym.name.decodedName.containsName(Dollar) && !sym.isSynthetic && sym.hasRawInfo) {
828+
} else if (!sym.name.decodedName.containsName("$") && !sym.isSynthetic && sym.hasRawInfo) {
831829
val symtpe = pre.memberType(sym) onTypeError ErrorType
832830
matching(sym, symtpe, this(sym.name)) match {
833831
case Some(m) =>

src/compiler/scala/tools/nsc/transform/CleanUp.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
120120
}
121121

122122
def addStaticMethodToClass(forBody: (Symbol, Symbol) => Tree): Symbol = {
123-
val methSym = currentClass.newMethod(mkTerm(nme.reflMethodName), ad.pos, STATIC | SYNTHETIC)
123+
val methSym = currentClass.newMethod(mkTerm(nme.reflMethodName.toString), ad.pos, STATIC | SYNTHETIC)
124124
val params = methSym.newSyntheticValueParams(List(ClassClass.tpe))
125125
methSym setInfoAndEnter MethodType(params, MethodClass.tpe)
126126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ trait ContextErrors {
511511
NormalTypeError(tree, fun.tpe+" does not take parameters")
512512

513513
// Dynamic
514-
def DynamicVarArgUnsupported(tree: Tree, name: String) =
514+
def DynamicVarArgUnsupported(tree: Tree, name: Name) =
515515
issueNormalTypeError(tree, name+ " does not support passing a vararg parameter")
516516

517517
def DynamicRewriteError(tree: Tree, err: AbsTypeError) = {

src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait CPSUtils {
3535
lazy val MarkerCPSAdaptMinus = rootMirror.getRequiredClass("scala.util.continuations.cpsMinus")
3636

3737
lazy val Context = rootMirror.getRequiredClass("scala.util.continuations.ControlContext")
38-
lazy val ModCPS = rootMirror.getRequiredPackage("scala.util.continuations")
38+
lazy val ModCPS = rootMirror.getPackage("scala.util.continuations")
3939

4040
lazy val MethShiftUnit = definitions.getMember(ModCPS, cpsNames.shiftUnit)
4141
lazy val MethShiftUnit0 = definitions.getMember(ModCPS, cpsNames.shiftUnit0)

0 commit comments

Comments
 (0)