Skip to content

Commit a90f381

Browse files
committed
Add Variant NameInfo
Plus further bug fixes.
1 parent c5eca49 commit a90f381

File tree

12 files changed

+55
-29
lines changed

12 files changed

+55
-29
lines changed

compiler/src/dotty/tools/dotc/core/NameInfos.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ object NameInfo {
2020

2121
val TermNameKind = 0
2222
val QualifiedKind = 1
23-
val ModuleClassKind = 2
2423
val DefaultGetterKind = 3
24+
val VariantKind = 4
25+
val ModuleClassKind = 10
2526

2627
val qualifier: Map[String, SimpleTermName => Qualified] =
2728
Map("." -> Select,
@@ -81,9 +82,18 @@ object NameInfo {
8182
}
8283
}
8384

85+
case class Variant(val num: Int) extends Numbered {
86+
def kind = VariantKind
87+
def mkString(underlying: TermName) = varianceToPrefix(num).toString + underlying
88+
}
89+
8490
val ModuleClass = new NameInfo {
8591
def kind = ModuleClassKind
8692
def mkString(underlying: TermName) = underlying + "$"
8793
override def toString = "ModuleClass"
8894
}
95+
96+
/** Map between variances and name prefixes */
97+
val varianceToPrefix = Map(-1 -> '-', 0 -> '=', 1 -> '+')
98+
val prefixToVariance = Map('-' -> -1, '=' -> 0, '+' -> 1)
8999
}

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,9 @@ object Names {
482482
val CONSTRUCTOR: TermName = termName("<init>")
483483
val STATIC_CONSTRUCTOR: TermName = termName("<clinit>")
484484
val EMPTY_PACKAGE: TermName = termName("<empty>")
485+
val REFINEMENT: TermName = termName("<refinement>")
485486

486-
val dontEncode = Set(CONSTRUCTOR, EMPTY_PACKAGE)
487+
val dontEncode = Set(CONSTRUCTOR, EMPTY_PACKAGE, REFINEMENT)
487488

488489
def termNameBuilder: Builder[Char, TermName] =
489490
StringBuilder.newBuilder.mapResult(termName)

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ object StdNames {
544544

545545
val nothingClass: N = "Nothing$"
546546
val nullClass: N = "Null$"
547-
547+
548548
val falseModuleClassNames = Set(nothingClass, nullClass, nothingRuntimeClass, nullRuntimeClass)
549549

550550
// unencoded operators

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,18 @@ object SymDenotations {
388388
* enclosing packages do not form part of the name.
389389
*/
390390
def fullNameSeparated(separator: String)(implicit ctx: Context): Name = {
391-
var sep = separator
392-
var stopAtPackage = false
393-
if (sep.isEmpty) {
394-
sep = "$"
395-
stopAtPackage = true
396-
}
391+
val stopAtPackage = separator.isEmpty
392+
val sep = if (stopAtPackage) "$" else separator
397393
if (symbol == NoSymbol ||
398394
owner == NoSymbol ||
399395
owner.isEffectiveRoot ||
400396
stopAtPackage && owner.is(PackageClass)) name
401397
else {
398+
var filler = ""
402399
var encl = owner
403400
while (!encl.isClass && !encl.isPackageObject) {
404401
encl = encl.owner
405-
sep += "~"
402+
filler += "~"
406403
}
407404
var prefix = encl.fullNameSeparated(separator)
408405
val fn =
@@ -411,14 +408,17 @@ object SymDenotations {
411408
// duplicate scalac's behavior: don't write a double '$$' for module class members.
412409
prefix = prefix.exclude(NameInfo.ModuleClassKind)
413410
name rewrite {
414-
case n: SimpleTermName => prefix.derived(NameInfo.qualifier(sep)(n))
411+
case n: SimpleTermName =>
412+
val n1 = if (filler.isEmpty) n else termName(filler ++ n)
413+
prefix.derived(NameInfo.qualifier(sep)(n1))
415414
}
416415
}
417416
else {
418-
if (owner.is(ModuleClass, butNot = Package) && sep == "$")
419-
// duplicate scalac's behavior: don't write a double '$$' for module class members.
420-
sep = ""
421-
prefix ++ sep ++ name
417+
val sep1 =
418+
if (owner.is(ModuleClass, butNot = Package) && sep == "$") ""
419+
else sep
420+
// duplicate scalac's behavior: don't write a double '$$' for module class members.
421+
prefix ++ sep1 ++ name
422422
}
423423
if (isType) fn.toTypeName else fn.toTermName
424424
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ object Types {
17931793
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
17941794
fixDenot(TermRef.withSig(prefix, name, sig), prefix)
17951795

1796-
override def shadowed(implicit ctx: Context): NamedType =
1796+
override def shadowed(implicit ctx: Context): NamedType =
17971797
fixDenot(TermRef.withSig(prefix, name.shadowedName, sig), prefix)
17981798

17991799
override def equals(that: Any) = that match {

compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class NameBuffer extends TastyBuffer(10000) {
3838
tcon(nameIndex(prefix, toTasty), nameIndex(qual.name))
3939
case DerivedTermName(prefix, NameInfo.DefaultGetter(num)) =>
4040
DefaultGetter(nameIndex(prefix, toTasty), num)
41+
case DerivedTermName(prefix, NameInfo.Variant(sign)) =>
42+
Variant(nameIndex(prefix, toTasty), sign)
4143
case name1 =>
4244
if (name1.isShadowedName) Shadowed(nameIndex(name1.revertShadowed, toTasty))
4345
else toTasty(name1.asSimpleName)
@@ -102,6 +104,9 @@ class NameBuffer extends TastyBuffer(10000) {
102104
case Shadowed(original) =>
103105
writeByte(SHADOWED)
104106
withLength { writeNameRef(original) }
107+
case Variant(original, sign) =>
108+
writeByte(VARIANT)
109+
withLength { writeNameRef(original); writeNat(sign + 1) }
105110
}
106111

107112
override def assemble(): Unit = {

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ object TastyFormat {
228228
final val SUPERACCESSOR = 7
229229
final val DEFAULTGETTER = 8
230230
final val SHADOWED = 9
231+
final val VARIANT = 10
231232

232233
// AST tags
233234

@@ -410,11 +411,14 @@ object TastyFormat {
410411
def nameTagToString(tag: Int): String = tag match {
411412
case UTF8 => "UTF8"
412413
case QUALIFIED => "QUALIFIED"
413-
case SIGNED => "SIGNED"
414+
case FLATTENED => "FLATTENED"
414415
case EXPANDED => "EXPANDED"
416+
case SIGNED => "SIGNED"
415417
case OBJECTCLASS => "OBJECTCLASS"
416418
case SUPERACCESSOR => "SUPERACCESSOR"
417419
case DEFAULTGETTER => "DEFAULTGETTER"
420+
case SHADOWED => "SHADOWED"
421+
case VARIANT => "VARIANT"
418422
}
419423

420424
def astTagToString(tag: Int): String = tag match {
@@ -547,8 +551,4 @@ object TastyFormat {
547551
case POLYtype | METHODtype => -1
548552
case _ => 0
549553
}
550-
551-
/** Map between variances and name prefixes */
552-
val varianceToPrefix = Map(-1 -> '-', 0 -> '=', 1 -> '+')
553-
val prefixToVariance = Map('-' -> -1, '=' -> 0, '+' -> 1)
554554
}

compiler/src/dotty/tools/dotc/core/tasty/TastyName.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ object TastyName {
2121
case class SuperAccessor(accessed: NameRef) extends TastyName
2222
case class DefaultGetter(method: NameRef, num: Int) extends TastyName
2323
case class Shadowed(original: NameRef) extends TastyName
24+
case class Variant(original: NameRef, sign: Int) extends TastyName
2425

2526
class Table extends (NameRef => TastyName) {
2627
private val names = new mutable.ArrayBuffer[TastyName]

compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class TastyUnpickler(reader: TastyReader) {
6262
DefaultGetter(readNameRef(), readNat())
6363
case SHADOWED =>
6464
Shadowed(readNameRef())
65+
case VARIANT =>
66+
Variant(readNameRef(), readNat() - 1)
6567
}
6668
assert(currentAddr == end, s"bad name $result $start $currentAddr $end")
6769
result

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NameOps._
1313
import StdNames.nme
1414
import TastyBuffer._
1515
import TypeApplications._
16+
import config.Config
1617

1718
class TreePickler(pickler: TastyPickler) {
1819
val buf = new TreeBuffer
@@ -256,7 +257,10 @@ class TreePickler(pickler: TastyPickler) {
256257
case tpe: PolyType =>
257258
writeByte(POLYtype)
258259
val paramNames = tpe.typeParams.map(tparam =>
259-
(varianceToPrefix(tparam.paramVariance) +: tparam.paramName.toString).toTypeName)
260+
if (Config.semanticNames)
261+
tparam.paramName.derived(NameInfo.Variant(tparam.paramVariance))
262+
else
263+
(NameInfo.varianceToPrefix(tparam.paramVariance) +: tparam.paramName.toString).toTypeName)
260264
pickleMethodic(tpe.resultType, paramNames, tpe.paramBounds)
261265
case tpe: MethodType if richTypes =>
262266
writeByte(METHODtype)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
9191
case ModuleClass(original) => toTermName(original).moduleClassName.toTermName
9292
case SuperAccessor(accessed) => toTermName(accessed).superName
9393
case DefaultGetter(meth, num) => toTermName(meth).defaultGetterName(num)
94+
case Variant(original, sign) => toTermName(original).derived(NameInfo.Variant(sign))
9495
}
9596

9697
private def qualTermName(qual: NameRef, name: NameRef, sep: String) =
@@ -280,8 +281,14 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
280281
TypeRef.withFixedSym(NoPrefix, sym.name, sym)
281282
case POLYtype =>
282283
val (rawNames, paramReader) = readNamesSkipParams
283-
val (variances, paramNames) = rawNames
284-
.map(name => (prefixToVariance(name.head), name.tail.toTypeName)).unzip
284+
val (variances, paramNames) = rawNames // !!! check integration with lambdas
285+
.map(name =>
286+
if (Config.semanticNames) {
287+
val DerivedTermName(n, NameInfo.Variant(v)) = name
288+
(v, n.toTypeName)
289+
}
290+
else
291+
(NameInfo.prefixToVariance(name.head), name.tail.toTypeName)).unzip
285292
val result = PolyType(paramNames, variances)(
286293
pt => registeringType(pt, paramReader.readParamTypes[TypeBounds](end)),
287294
pt => readType())

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
9797
|| (sym.name == nme.PACKAGE) // package
9898
)
9999

100-
def nameString(name: Name): String = name.toString + {
101-
if (ctx.settings.debugNames.value)
102-
if (name.isTypeName) "/T" else "/V"
103-
else ""
104-
}
100+
def nameString(name: Name): String = name.toString
105101

106102
def toText(name: Name): Text = Str(nameString(name))
107103

0 commit comments

Comments
 (0)