Skip to content

Remove PreName add (almost) all other implicit conversions #4077

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
" := " ~ tp.toText(printer)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an improvement, lots of nitty gritty boilerplate to add.

val indent = 3
val header: Text = "Constraint("
val header: Text = "Constraint(".toText
val uninstVarsText = " uninstVars = " ~
Text(uninstVars map (_.toText(printer)), ", ") ~ ";"
val constrainedText =
Expand All @@ -626,7 +626,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
Text(ups.map(_.toText(printer)), ", ")
Text(deps, "\n")
}
Text.lines(List(header, uninstVarsText, constrainedText, boundsText, orderingText, ")"))
Text.lines(List(header, uninstVarsText, constrainedText, boundsText, orderingText, ")".toText))
}

override def toString: String = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object TreePickler {

case class Hole(idx: Int, args: List[tpd.Tree]) extends tpd.TermTree {
override def fallbackToText(printer: Printer): Text =
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
s"[[$idx|".toText ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ object Formatting {
seen.record(super.ParamRefNameString(param), param)

override def toTextRef(tp: SingletonType): Text = tp match {
case tp: SkolemType => seen.record(tp.repr.toString, tp)
case tp: SkolemType => seen.record(tp.repr.toString, tp).toText
case _ => super.toTextRef(tp)
}
}
Expand Down
71 changes: 36 additions & 35 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
else {
if (ctx.toTextRecursions >= maxToTextRecursions)
recursionLimitExceeded()
"..."
"...".toText
}

protected def recursionLimitExceeded() = {
Expand Down Expand Up @@ -138,7 +138,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
else
toTextPrefix(tp.prefix) ~ selectionString(tp)
case tp: TermParamRef =>
ParamRefNameString(tp) ~ ".type"
ParamRefNameString(tp) ~ ".type".toText
case tp: TypeParamRef =>
ParamRefNameString(tp) ~ lambdaHash(tp.binder)
case tp: SingletonType =>
Expand All @@ -152,21 +152,21 @@ class PlainPrinter(_ctx: Context) extends Printer {
case tp: RecType =>
try {
openRecs = tp :: openRecs
"{" ~ selfRecName(openRecs.length) ~ " => " ~ toTextGlobal(tp.parent) ~ "}"
"{" ~ selfRecName(openRecs.length).toText ~ " => " ~ toTextGlobal(tp.parent) ~ "}"
}
finally openRecs = openRecs.tail
case AndType(tp1, tp2) =>
changePrec(AndPrec) { toText(tp1) ~ " & " ~ toText(tp2) }
case OrType(tp1, tp2) =>
changePrec(OrPrec) { toText(tp1) ~ " | " ~ toText(tp2) }
case tp: ErrorType =>
s"<error ${tp.msg.msg}>"
s"<error ${tp.msg.msg}>".toText
case tp: WildcardType =>
if (tp.optBounds.exists) "(?" ~ toTextRHS(tp.bounds) ~ ")" else "?"
if (tp.optBounds.exists) "(?" ~ toTextRHS(tp.bounds) ~ ")" else "?".toText
case NoType =>
"<notype>"
"<notype>".toText
case NoPrefix =>
"<noprefix>"
"<noprefix>".toText
case tp: MethodType =>
changePrec(GlobalPrec) {
(if (tp.isImplicitMethod) "(implicit " else "(") ~ paramsText(tp) ~
Expand Down Expand Up @@ -222,10 +222,10 @@ class PlainPrinter(_ctx: Context) extends Printer {

/** If -uniqid is set, the hashcode of the lambda type, after a # */
protected def lambdaHash(pt: LambdaType): Text =
if (ctx.settings.uniqid.value)
(if (ctx.settings.uniqid.value)
try "#" + pt.hashCode
catch { case ex: NullPointerException => "" }
else ""
else "").toText

/** If -uniqid is set, the unique id of symbol, after a # */
protected def idString(sym: Symbol): String =
Expand Down Expand Up @@ -259,19 +259,19 @@ class PlainPrinter(_ctx: Context) extends Printer {
case tp: TermRef =>
toTextPrefix(tp.prefix) ~ selectionString(tp)
case tp: ThisType =>
nameString(tp.cls) + ".this"
(nameString(tp.cls) + ".this").toText
case SuperType(thistpe: SingletonType, _) =>
toTextRef(thistpe).map(_.replaceAll("""\bthis$""", "super"))
case SuperType(thistpe, _) =>
"Super(" ~ toTextGlobal(thistpe) ~ ")"
case tp @ ConstantType(value) =>
toText(value)
case pref: TermParamRef =>
nameString(pref.binder.paramNames(pref.paramNum))
nameString(pref.binder.paramNames(pref.paramNum)).toText
case tp: RecThis =>
val idx = openRecs.reverse.indexOf(tp.binder)
if (idx >= 0) selfRecName(idx + 1)
else "{...}.this" // TODO move underlying type to an addendum, e.g. ... z3 ... where z3: ...
(if (idx >= 0) selfRecName(idx + 1)
else "{...}.this").toText // TODO move underlying type to an addendum, e.g. ... z3 ... where z3: ...
case tp: SkolemType =>
if (homogenizedView) toText(tp.info) else toText(tp.repr)
}
Expand All @@ -280,7 +280,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
/** The string representation of this type used as a prefix */
protected def toTextPrefix(tp: Type): Text = controlled {
homogenize(tp) match {
case NoPrefix => ""
case NoPrefix => "".toText
case tp: SingletonType => toTextRef(tp) ~ "."
case tp => trimPrefix(toTextLocal(tp)) ~ "#"
}
Expand All @@ -297,7 +297,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
*/
protected def toTextRHS(optType: Option[Type]): Text = optType match {
case Some(tp) => toTextRHS(tp)
case None => "?"
case None => "?".toText
}

/** String representation of a definition's type following its name */
Expand All @@ -315,7 +315,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
if (tparams.isEmpty) Text() else ("[" ~ dclsText(tparams) ~ "]").close
val selfText: Text = selfInfo match {
case NoType => Text()
case sym: Symbol if !sym.isCompleted => "this: ? =>"
case sym: Symbol if !sym.isCompleted => "this: ? =>".toText
case _ => "this: " ~ atPrec(InfixPrec) { toText(tp.selfType) } ~ " =>"
}
val trueDecls = otherDecls.filterNot(treatAsTypeArg)
Expand Down Expand Up @@ -379,7 +379,7 @@ class PlainPrinter(_ctx: Context) extends Printer {

/** String representation of symbol's flags */
protected def toTextFlags(sym: Symbol): Text =
Text(sym.flagsUNSAFE.flagStrings map stringToText, " ")
Text(sym.flagsUNSAFE.flagStrings.map(_.toText), " ")

/** String representation of symbol's variance or "" if not applicable */
protected def varianceString(sym: Symbol): String = varianceString(sym.variance)
Expand All @@ -398,17 +398,17 @@ class PlainPrinter(_ctx: Context) extends Printer {

private def dclTextWithInfo(sym: Symbol, info: Option[Type]): Text =
(toTextFlags(sym) ~~ keyString(sym) ~~
(varianceString(sym) ~ nameString(sym)) ~ toTextRHS(info)).close
(varianceString(sym) ~ nameString(sym).toText) ~ toTextRHS(info)).close

def toText(sym: Symbol): Text =
(kindString(sym) ~~ {
(kindString(sym).toText ~~ {
if (sym.isAnonymousClass) toText(sym.info.parents, " with ") ~ "{...}"
else if (hasMeaninglessName(sym)) simpleNameString(sym.owner) + idString(sym)
else nameString(sym)
else if (hasMeaninglessName(sym)) (simpleNameString(sym.owner) + idString(sym)).toText
else nameString(sym).toText
}).close

def locationText(sym: Symbol): Text =
if (!sym.exists) ""
if (!sym.exists) "".toText
else {
val ownr = sym.effectiveOwner
if (ownr.isClass && !isEmptyPrefix(ownr)) " in " ~ toText(ownr) else Text()
Expand All @@ -418,18 +418,18 @@ class PlainPrinter(_ctx: Context) extends Printer {
(toText(sym) ~ locationText(sym)).close

def extendedLocationText(sym: Symbol): Text =
if (!sym.exists) ""
if (!sym.exists) "".toText
else {
def recur(ownr: Symbol, innerLocation: String): Text = {
def nextOuter(innerKind: String): Text =
recur(ownr.effectiveOwner,
if (!innerLocation.isEmpty) innerLocation
else s" in an anonymous $innerKind")
def showLocation(ownr: Symbol, where: String): Text =
innerLocation ~ " " ~ where ~ " " ~ toText(ownr)
innerLocation ~ " ".toText ~ where ~ " " ~ toText(ownr)
if (ownr.isAnonymousClass) nextOuter("class")
else if (ownr.isAnonymousFunction) nextOuter("function")
else if (isEmptyPrefix(ownr)) ""
else if (isEmptyPrefix(ownr)) "".toText
else if (ownr.isLocalDummy) showLocation(ownr.owner, "locally defined in")
else if (ownr.isTerm && !ownr.is(Module | Method)) showLocation(ownr, "in the initalizer of")
else showLocation(ownr, "in")
Expand Down Expand Up @@ -461,7 +461,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case _ => literalText(String.valueOf(const.value))
}

def toText(annot: Annotation): Text = s"@${annot.symbol.name}" // for now
def toText(annot: Annotation): Text = s"@${annot.symbol.name}".toText // for now

protected def escapedString(str: String): String = str flatMap escapedChar

Expand All @@ -476,9 +476,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
def toTextElem(elem: Any): Text = elem match {
case elem: Showable => elem.toText(this)
case elem: List[_] => "List(" ~ Text(elem map toTextElem, ",") ~ ")"
case elem => elem.toString
case elem => elem.toString.toText
}
val nodeName = node.productPrefix
val nodeName = node.productPrefix.toText
val elems =
Text(node.productIterator.map(toTextElem).toList, ", ")
val tpSuffix =
Expand All @@ -498,13 +498,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
"SearchSuccess: " ~ toText(result.ref) ~ " via " ~ toText(result.tree)
case result: SearchFailure =>
result.reason match {
case _: NoMatchingImplicits => "No Matching Implicit"
case _: DivergingImplicit => "Diverging Implicit"
case _: ShadowedImplicit => "Shadowed Implicit"
case _: NoMatchingImplicits => "No Matching Implicit".toText
case _: DivergingImplicit => "Diverging Implicit".toText
case _: ShadowedImplicit => "Shadowed Implicit".toText
case result: AmbiguousImplicits =>
"Ambiguous Implicit: " ~ toText(result.alt1.ref) ~ " and " ~ toText(result.alt2.ref)
case _ =>
"?Unknown Implicit Result?" + result.getClass
s"?Unknown Implicit Result?${result.getClass}".toText
}
}

Expand All @@ -515,7 +515,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
case Ident(name) :: Nil => name.show
case _ => "{...}"
}
s"import $exprStr.$selectorStr"
s"import $exprStr.$selectorStr".toText
}


Expand All @@ -533,15 +533,16 @@ class PlainPrinter(_ctx: Context) extends Printer {
def plain = this

protected def keywordStr(text: String): String = coloredStr(text, SyntaxHighlighting.KeywordColor)
protected def keywordText(text: String): Text = coloredStr(text, SyntaxHighlighting.KeywordColor)
protected def keywordText(text: String): Text = keywordStr(text).toText
protected def valDefText(text: Text): Text = coloredText(text, SyntaxHighlighting.ValDefColor)
protected def typeText(text: Text): Text = coloredText(text, SyntaxHighlighting.TypeColor)
protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor)
protected def literalText(string: String): Text = literalText(string.toText)
protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor)
protected def stringText(string: String): Text = stringText(string.toText)

private def coloredStr(text: String, color: String): String =
if (ctx.useColors) color + text + SyntaxHighlighting.NoColor else text
private def coloredText(text: Text, color: String): Text =
if (ctx.useColors) color ~ text ~ SyntaxHighlighting.NoColor else text
}

Loading