Skip to content

Fix/pickle homogenization #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/dotty/tools/dotc/core/pickling/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ class TreePickler(pickler: TastyPickler) {
else pickleRef()
}
case tpe: TermRefWithSignature =>
writeByte(TERMREF)
pickleNameAndSig(tpe.name, tpe.signature); pickleType(tpe.prefix)
if (tpe.symbol.is(Flags.Package)) picklePackageRef(tpe.symbol)
else {
writeByte(TERMREF)
pickleNameAndSig(tpe.name, tpe.signature); pickleType(tpe.prefix)
}
case tpe: NamedType =>
if (tpe.name == tpnme.Apply && tpe.prefix.argInfos.nonEmpty && tpe.prefix.isInstantiatedLambda)
// instantiated lambdas are pickled as APPLIEDTYPE; #Apply will
Expand All @@ -187,8 +190,12 @@ class TreePickler(pickler: TastyPickler) {
pickleName(tpe.name); pickleType(tpe.prefix)
}
case tpe: ThisType =>
writeByte(THIS)
pickleType(tpe.tref)
if (tpe.cls.is(Flags.Package) && !tpe.cls.isEffectiveRoot)
picklePackageRef(tpe.cls)
else {
writeByte(THIS)
pickleType(tpe.tref)
}
case tpe: SuperType =>
writeByte(SUPERtype)
withLength { pickleType(tpe.thistpe); pickleType(tpe.supertpe)}
Expand Down Expand Up @@ -253,6 +260,11 @@ class TreePickler(pickler: TastyPickler) {
println(i"error while pickling type $tpe")
throw ex
}

def picklePackageRef(pkg: Symbol): Unit = {
writeByte(TERMREFpkg)
pickleName(qualifiedName(pkg))
}

def pickleMethodic(result: Type, names: List[Name], types: List[Type]) =
withLength {
Expand Down
19 changes: 12 additions & 7 deletions src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ class PlainPrinter(_ctx: Context) extends Printer {
def homogenize(tp: Type): Type =
if (homogenizedView)
tp match {
case tp: TypeVar if tp.isInstantiated => homogenize(tp.instanceOpt)
case AndType(tp1, tp2) => homogenize(tp1) & homogenize(tp2)
case OrType(tp1, tp2) => homogenize(tp1) | homogenize(tp2)
case tp: ThisType if tp.cls.is(Package) && !tp.cls.isEffectiveRoot =>
ctx.requiredPackage(tp.cls.fullName).termRef
case tp: TypeVar if tp.isInstantiated =>
homogenize(tp.instanceOpt)
case AndType(tp1, tp2) =>
homogenize(tp1) & homogenize(tp2)
case OrType(tp1, tp2) =>
homogenize(tp1) | homogenize(tp2)
case _ =>
val tp1 = tp.simplifyApply
if (tp1 eq tp) tp else homogenize(tp1)
Expand Down Expand Up @@ -230,10 +235,10 @@ class PlainPrinter(_ctx: Context) extends Printer {

/** The string representation of this type used as a prefix */
protected def toTextPrefix(tp: Type): Text = controlled {
tp match {
homogenize(tp) match {
case NoPrefix => ""
case tp: SingletonType => toTextRef(tp) ~ "."
case _ => trimPrefix(toTextLocal(tp)) ~ "#"
case tp => trimPrefix(toTextLocal(tp)) ~ "#"
}
}

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

/** String representation of a definition's type following its name */
protected def toTextRHS(tp: Type): Text = controlled {
tp match {
homogenize(tp) match {
case tp @ TypeBounds(lo, hi) =>
if (lo eq hi) {
val eql =
Expand All @@ -280,7 +285,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
else dclsText(trueDecls)
tparamsText ~ " extends " ~ toTextParents(tp.parents) ~ "{" ~ selfText ~ declsText ~
"} at " ~ preText
case _ =>
case tp =>
": " ~ toTextGlobal(tp)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
}

override def toTextPrefix(tp: Type): Text = controlled {
def isOmittable(sym: Symbol) = isOmittablePrefix(sym) && !ctx.settings.verbose.value
def isOmittable(sym: Symbol) =
if (ctx.settings.verbose.value) false
else if (homogenizedView) isEmptyPrefix(sym) // drop <root> and anonymous classes, but not scala, Predef.
else isOmittablePrefix(sym)
tp match {
case tp: ThisType =>
if (isOmittable(tp.cls)) return ""
Expand Down