Skip to content

Commit 4efcfa6

Browse files
committed
Merge pull request #475 from dotty-staging/fix/pickle-homogenization
Fix/pickle homogenization
2 parents e47ecb1 + 72d91a3 commit 4efcfa6

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/dotty/tools/dotc/core/pickling/TreePickler.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ class TreePickler(pickler: TastyPickler) {
171171
else pickleRef()
172172
}
173173
case tpe: TermRefWithSignature =>
174-
writeByte(TERMREF)
175-
pickleNameAndSig(tpe.name, tpe.signature); pickleType(tpe.prefix)
174+
if (tpe.symbol.is(Flags.Package)) picklePackageRef(tpe.symbol)
175+
else {
176+
writeByte(TERMREF)
177+
pickleNameAndSig(tpe.name, tpe.signature); pickleType(tpe.prefix)
178+
}
176179
case tpe: NamedType =>
177180
if (tpe.name == tpnme.Apply && tpe.prefix.argInfos.nonEmpty && tpe.prefix.isInstantiatedLambda)
178181
// instantiated lambdas are pickled as APPLIEDTYPE; #Apply will
@@ -187,8 +190,12 @@ class TreePickler(pickler: TastyPickler) {
187190
pickleName(tpe.name); pickleType(tpe.prefix)
188191
}
189192
case tpe: ThisType =>
190-
writeByte(THIS)
191-
pickleType(tpe.tref)
193+
if (tpe.cls.is(Flags.Package) && !tpe.cls.isEffectiveRoot)
194+
picklePackageRef(tpe.cls)
195+
else {
196+
writeByte(THIS)
197+
pickleType(tpe.tref)
198+
}
192199
case tpe: SuperType =>
193200
writeByte(SUPERtype)
194201
withLength { pickleType(tpe.thistpe); pickleType(tpe.supertpe)}
@@ -253,6 +260,11 @@ class TreePickler(pickler: TastyPickler) {
253260
println(i"error while pickling type $tpe")
254261
throw ex
255262
}
263+
264+
def picklePackageRef(pkg: Symbol): Unit = {
265+
writeByte(TERMREFpkg)
266+
pickleName(qualifiedName(pkg))
267+
}
256268

257269
def pickleMethodic(result: Type, names: List[Name], types: List[Type]) =
258270
withLength {

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
4040
def homogenize(tp: Type): Type =
4141
if (homogenizedView)
4242
tp match {
43-
case tp: TypeVar if tp.isInstantiated => homogenize(tp.instanceOpt)
44-
case AndType(tp1, tp2) => homogenize(tp1) & homogenize(tp2)
45-
case OrType(tp1, tp2) => homogenize(tp1) | homogenize(tp2)
43+
case tp: ThisType if tp.cls.is(Package) && !tp.cls.isEffectiveRoot =>
44+
ctx.requiredPackage(tp.cls.fullName).termRef
45+
case tp: TypeVar if tp.isInstantiated =>
46+
homogenize(tp.instanceOpt)
47+
case AndType(tp1, tp2) =>
48+
homogenize(tp1) & homogenize(tp2)
49+
case OrType(tp1, tp2) =>
50+
homogenize(tp1) | homogenize(tp2)
4651
case _ =>
4752
val tp1 = tp.simplifyApply
4853
if (tp1 eq tp) tp else homogenize(tp1)
@@ -230,10 +235,10 @@ class PlainPrinter(_ctx: Context) extends Printer {
230235

231236
/** The string representation of this type used as a prefix */
232237
protected def toTextPrefix(tp: Type): Text = controlled {
233-
tp match {
238+
homogenize(tp) match {
234239
case NoPrefix => ""
235240
case tp: SingletonType => toTextRef(tp) ~ "."
236-
case _ => trimPrefix(toTextLocal(tp)) ~ "#"
241+
case tp => trimPrefix(toTextLocal(tp)) ~ "#"
237242
}
238243
}
239244

@@ -253,7 +258,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
253258

254259
/** String representation of a definition's type following its name */
255260
protected def toTextRHS(tp: Type): Text = controlled {
256-
tp match {
261+
homogenize(tp) match {
257262
case tp @ TypeBounds(lo, hi) =>
258263
if (lo eq hi) {
259264
val eql =
@@ -280,7 +285,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
280285
else dclsText(trueDecls)
281286
tparamsText ~ " extends " ~ toTextParents(tp.parents) ~ "{" ~ selfText ~ declsText ~
282287
"} at " ~ preText
283-
case _ =>
288+
case tp =>
284289
": " ~ toTextGlobal(tp)
285290
}
286291
}

src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
6363
}
6464

6565
override def toTextPrefix(tp: Type): Text = controlled {
66-
def isOmittable(sym: Symbol) = isOmittablePrefix(sym) && !ctx.settings.verbose.value
66+
def isOmittable(sym: Symbol) =
67+
if (ctx.settings.verbose.value) false
68+
else if (homogenizedView) isEmptyPrefix(sym) // drop <root> and anonymous classes, but not scala, Predef.
69+
else isOmittablePrefix(sym)
6770
tp match {
6871
case tp: ThisType =>
6972
if (isOmittable(tp.cls)) return ""

0 commit comments

Comments
 (0)