Skip to content

Commit 2f749a5

Browse files
committed
encode packages in tasty and signatures
1 parent 2333316 commit 2f749a5

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ object NameOps {
141141
* followed by `kind` and the name.
142142
*/
143143
def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(using Context): N =
144-
likeSpacedN { base.fullNameSeparated(ExpandPrefixName, kind, name) }
144+
likeSpacedN { base.fullNameSeparated(ExpandPrefixName, kind, name, doEncodeName = false, encodePackages = false) }
145145

146146
/** Revert the expanded name. */
147147
def unexpandedName: N = likeSpacedN {

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -458,29 +458,38 @@ object SymDenotations {
458458
* are separated by `separator` strings as indicated by the given name kind.
459459
* Drops package objects. Represents each term in the owner chain by a simple `_$`.
460460
*/
461-
def fullNameSeparated(kind: QualifiedNameKind)(using Context): Name =
462-
maybeOwner.fullNameSeparated(kind, kind, name)
461+
def fullNameSeparated(kind: QualifiedNameKind, encodePackages: Boolean)(using Context): Name =
462+
val doEncodeName = encodePackages && is(PackageClass) && !isEffectiveRoot
463+
maybeOwner.fullNameSeparated(kind, kind, name, doEncodeName, encodePackages)
463464

464465
/** The encoded full path name of this denotation (separated by `prefixKind`),
465466
* followed by the separator implied by `kind` and the given `name`.
466467
* Drops package objects. Represents each term in the owner chain by a simple `_$`.
467468
*/
468-
def fullNameSeparated(prefixKind: QualifiedNameKind, kind: QualifiedNameKind, name: Name)(using Context): Name =
469-
if (symbol == NoSymbol || isEffectiveRoot || kind == FlatName && is(PackageClass))
470-
name
469+
def fullNameSeparated(
470+
prefixKind: QualifiedNameKind,
471+
kind: QualifiedNameKind,
472+
name: Name,
473+
doEncodeName: Boolean,
474+
encodePackages: Boolean
475+
)(using Context): Name =
476+
if symbol == NoSymbol || isEffectiveRoot || kind == FlatName && is(PackageClass) then {
477+
if doEncodeName then name.encode else name
478+
}
471479
else {
472480
var filler = ""
473481
var encl = symbol
474482
while (!encl.isClass && !encl.isPackageObject) {
475483
encl = encl.owner
476484
filler += "_$"
477485
}
478-
var prefix = encl.fullNameSeparated(prefixKind)
486+
var prefix = encl.fullNameSeparated(prefixKind, encodePackages)
479487
if (kind.separator == "$")
480488
// duplicate scalac's behavior: don't write a double '$$' for module class members.
481489
prefix = prefix.exclude(ModuleClassName)
482-
def qualify(n: SimpleName) =
483-
val qn = kind(prefix.toTermName, if (filler.isEmpty) n else termName(filler + n))
490+
def qualify(n0: SimpleName) =
491+
val n1 = if (filler.isEmpty) n0 else termName(filler + n0)
492+
val qn = kind(prefix.toTermName, if doEncodeName then n1.encode else n1)
484493
if kind == FlatName && !encl.is(JavaDefined) then qn.compactified else qn
485494
val fn = name replace {
486495
case name: SimpleName => qualify(name)
@@ -490,10 +499,12 @@ object SymDenotations {
490499
}
491500

492501
/** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */
493-
def flatName(using Context): Name = fullNameSeparated(FlatName)
502+
def flatName(using Context): Name = fullNameSeparated(FlatName, encodePackages = false)
494503

495504
/** `fullName` where `.' is the separator character */
496-
def fullName(using Context): Name = fullNameSeparated(QualifiedName)
505+
def fullName(using Context): Name = fullNameSeparated(QualifiedName, encodePackages = false)
506+
507+
def tastyCompatibleFullName(using Context): Name = fullNameSeparated(QualifiedName, encodePackages = true)
497508

498509
private var myTargetName: Name = null
499510

@@ -1701,7 +1712,7 @@ object SymDenotations {
17011712
// ----- caches -------------------------------------------------------
17021713

17031714
private var myTypeParams: List[TypeSymbol] = null
1704-
private var fullNameCache: SimpleIdentityMap[QualifiedNameKind, Name] = SimpleIdentityMap.empty
1715+
private var fullNameCache: SimpleIdentityMap[(QualifiedNameKind, Boolean), Name] = SimpleIdentityMap.empty
17051716

17061717
private var myMemberCache: EqHashMap[Name, PreDenotation] = null
17071718
private var myMemberCachePeriod: Period = Nowhere
@@ -2252,19 +2263,22 @@ object SymDenotations {
22522263
}
22532264
}
22542265

2255-
override final def fullNameSeparated(kind: QualifiedNameKind)(using Context): Name = {
2256-
val cached = fullNameCache(kind)
2266+
override final def fullNameSeparated(kind: QualifiedNameKind, encodePackages: Boolean)(using Context): Name = {
2267+
val cached = fullNameCache((kind, encodePackages))
22572268
if (cached != null) cached
22582269
else {
2259-
val fn = super.fullNameSeparated(kind)
2260-
fullNameCache = fullNameCache.updated(kind, fn)
2270+
val fn = super.fullNameSeparated(kind, encodePackages)
2271+
fullNameCache = fullNameCache.updated((kind, encodePackages), fn)
22612272
fn
22622273
}
22632274
}
22642275

22652276
// to avoid overloading ambiguities
22662277
override def fullName(using Context): Name = super.fullName
22672278

2279+
// to avoid overloading ambiguities
2280+
override def tastyCompatibleFullName(using Context): Name = super.tastyCompatibleFullName
2281+
22682282
override def primaryConstructor(using Context): Symbol = {
22692283
def constrNamed(cname: TermName) = info.decls.denotsNamed(cname).last.symbol
22702284
// denotsNamed returns Symbols in reverse order of occurrence

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
804804
// It's important to use the initial symbol to compute the full name
805805
// because the current symbol might have a different name or owner
806806
// and signatures are required to be stable before erasure.
807-
cls.initial.fullName
807+
cls.initial.tastyCompatibleFullName
808808
else
809-
cls.fullName
810-
fullName.asTypeName
809+
cls.tastyCompatibleFullName
810+
fullName.asTypeName // TODO encode packages
811811
case tp: AppliedType =>
812812
val sym = tp.tycon.typeSymbol
813813
sigName( // todo: what about repeatedParam?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class TreePickler(pickler: TastyPickler) {
191191
}
192192
if (sym.is(Flags.Package)) {
193193
writeByte(if (tpe.isType) TYPEREFpkg else TERMREFpkg)
194-
pickleName(sym.fullName)
194+
pickleName(sym.tastyCompatibleFullName)
195195
}
196196
else if (tpe.prefix == NoPrefix) {
197197
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ object Splicer {
508508
// Take the flatten name of the class and the full package name
509509
val pack = tpe.classSymbol.topLevelClass.owner
510510
val packageName = if (pack == defn.EmptyPackageClass) "" else s"${pack.fullName}."
511-
packageName + tpe.classSymbol.fullNameSeparated(FlatName).toString
511+
packageName + tpe.classSymbol.fullNameSeparated(FlatName, encodePackages = false).toString
512512
}
513513

514514
val sym = param.classSymbol

0 commit comments

Comments
 (0)