Skip to content

Commit 6f58fb6

Browse files
committed
Drop -print-lines option
It does not seem to be used anywhere and it complicates text formatting considerably.
1 parent 7ddf329 commit 6f58fb6

File tree

10 files changed

+30
-67
lines changed

10 files changed

+30
-67
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ trait AllScalaSettings extends CommonScalaSettings, PluginSettings, VerboseSetti
6262

6363
/* Decompiler settings */
6464
val printTasty: Setting[Boolean] = BooleanSetting(RootSetting, "print-tasty", "Prints the raw tasty.", aliases = List("--print-tasty"))
65-
val printLines: Setting[Boolean] = BooleanSetting(RootSetting, "print-lines", "Show source code line numbers.", aliases = List("--print-lines"))
6665

6766
/* Scala.js-related settings */
6867
val scalajsGenStaticForwardersForNonTopLevelObjects: Setting[Boolean] = BooleanSetting(RootSetting, "scalajs-genStaticForwardersForNonTopLevelObjects", "Generate static forwarders even for non-top-level objects (Scala.js only).")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ object Decorators {
245245
end extension
246246

247247
extension (text: Text)
248-
def show(using Context): String = text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value)
248+
def show(using Context): String = text.mkString(ctx.settings.pageWidth.value)
249249

250250
/** Test whether a list of strings representing phases contains
251251
* a given phase. See [[config.CompilerCommand#explainAdvanced]] for the

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
4949

5050
protected def controlled(op: => Text): Text = limiter.controlled(op)
5151

52-
def Str(str: String, lineRange: LineRange = EmptyLineRange): Str =
52+
def Str(str: String): Str =
5353
limiter.register(str)
54-
Texts.Str(str, lineRange)
54+
Texts.Str(str)
5555

5656
given stringToText: Conversion[String, Text] = Str(_)
5757

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
4141
private var enclosingDef: untpd.Tree = untpd.EmptyTree
4242
private var myCtx: Context = super.printerContext
4343
private var printPos = ctx.settings.YprintPos.value
44-
private val printLines = ctx.settings.printLines.value
4544

4645
override def printerContext: Context = myCtx
4746

@@ -481,7 +480,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
481480
case id @ Ident(name) =>
482481
val txt = tree.typeOpt match {
483482
case tp: NamedType if name != nme.WILDCARD =>
484-
toTextPrefixOf(tp) ~ withPos(selectionString(tp), tree.sourcePos)
483+
toTextPrefixOf(tp) ~ selectionString(tp)
485484
case _ =>
486485
toText(name)
487486
}
@@ -517,8 +516,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
517516
typeApplyText(tree)
518517
case Literal(c) =>
519518
tree.typeOpt match {
520-
case ConstantType(tc) => withPos(toText(tc), tree.sourcePos)
521-
case _ => withPos(toText(c), tree.sourcePos)
519+
case ConstantType(tc) => toText(tc)
520+
case _ => toText(c)
522521
}
523522
case New(tpt) =>
524523
keywordStr("new ") ~ {
@@ -729,8 +728,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
729728
case SymbolLit(str) =>
730729
"'" + str
731730
case InterpolatedString(id, segments) =>
732-
def strText(str: Literal) = withPos(escapedString(str.const.stringValue), tree.sourcePos)
733-
def segmentText(segment: Tree) = segment match {
731+
def strText(str: Literal) = escapedString(str.const.stringValue)
732+
def segmentText(segment: Tree): Text = segment match {
734733
case Thicket(List(str: Literal, expr)) => strText(str) ~ "{" ~ toTextGlobal(expr) ~ "}"
735734
case str: Literal => strText(str)
736735
}
@@ -968,14 +967,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
968967
tree.hasType && tree.symbol.exists && ctx.settings.YprintSyms.value
969968

970969
protected def nameIdText[T <: Untyped](tree: NameTree[T]): Text =
971-
if (tree.hasType && tree.symbol.exists && tree.symbol.isType == tree.name.isTypeName) {
972-
val str = nameString(tree.symbol)
973-
tree match {
974-
case tree: RefTree => withPos(str, tree.sourcePos)
975-
case tree: MemberDef => withPos(str, tree.sourcePos.withSpan(tree.nameSpan))
976-
case _ => str
977-
}
978-
}
970+
if tree.hasType && tree.symbol.exists && tree.symbol.isType == tree.name.isTypeName
971+
then nameString(tree.symbol)
979972
else toText(tree.name) ~ idText(tree)
980973

981974
private def toTextOwner(tree: Tree[?]) =
@@ -1280,11 +1273,4 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
12801273
}
12811274

12821275
override def plain: PlainPrinter = new PlainPrinter(_ctx)
1283-
1284-
private def withPos(txt: Text, pos: SourcePosition): Text =
1285-
if (!printLines || !pos.exists) txt
1286-
else txt match {
1287-
case Str(s, _) => Str(s, LineRange(pos.line, pos.endLine))
1288-
case _ => txt
1289-
}
12901276
}

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

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Texts {
1414
def relems: List[Text]
1515

1616
def isEmpty: Boolean = this match {
17-
case Str(s, _) => s.isEmpty
17+
case Str(s) => s.isEmpty
1818
case Fluid(relems) => relems forall (_.isEmpty)
1919
case Vertical(relems) => relems.isEmpty
2020
}
@@ -32,7 +32,7 @@ object Texts {
3232
def close: Text = if isSplittable then Closed(relems) else this
3333

3434
def remaining(width: Int): Int = this match {
35-
case Str(s, _) =>
35+
case Str(s) =>
3636
width - lengthWithoutAnsi(s)
3737
case Fluid(Nil) =>
3838
width
@@ -44,15 +44,15 @@ object Texts {
4444
}
4545

4646
def lastLine: String = this match {
47-
case Str(s, _) => s
47+
case Str(s) => s
4848
case _ => relems.head.lastLine
4949
}
5050

5151
def appendToLastLine(that: Text): Text = that match {
52-
case Str(s2, lines1) =>
52+
case Str(s2) =>
5353
this match {
54-
case Str(s1, lines2) => Str(s1 + s2, lines1 `union` lines2)
55-
case Fluid(Str(s1, lines2) :: prev) => Fluid(Str(s1 + s2, lines1 `union` lines2) :: prev)
54+
case Str(s1) => Str(s1 + s2)
55+
case Fluid(Str(s1) :: prev) => Fluid(Str(s1 + s2) :: prev)
5656
case Fluid(relems) => Fluid(that :: relems)
5757
case Vertical(_) => throw new IllegalArgumentException("Unexpected Vertical.appendToLastLine")
5858
}
@@ -77,7 +77,7 @@ object Texts {
7777
ansi.matcher(str).replaceAll("").length
7878

7979
def layout(width: Int): Text = this match {
80-
case Str(s, _) =>
80+
case Str(s) =>
8181
this
8282
case Fluid(relems) =>
8383
relems.reverse.foldLeft(Str(""): Text)(_.append(width)(_))
@@ -86,13 +86,13 @@ object Texts {
8686
}
8787

8888
def map(f: String => String): Text = this match {
89-
case Str(s, lines) => Str(f(s), lines)
89+
case Str(s) => Str(f(s))
9090
case Fluid(relems) => Fluid(relems.map(_.map(f)))
9191
case Vertical(relems) => Vertical(relems.map(_.map(f)))
9292
}
9393

9494
def stripPrefix(pre: String): Text = this match {
95-
case Str(s, _) =>
95+
case Str(s) =>
9696
if (s.startsWith(pre)) s.drop(pre.length) else s
9797
case Fluid(relems) =>
9898
val elems = relems.reverse
@@ -105,43 +105,27 @@ object Texts {
105105
}
106106

107107
private def indented: Text = this match {
108-
case Str(s, lines) => Str((" " * indentMargin) + s, lines)
108+
case Str(s) => Str((" " * indentMargin) + s)
109109
case Fluid(relems) => Fluid(relems map (_.indented))
110110
case Vertical(relems) => Vertical(relems map (_.indented))
111111
}
112112

113-
def print(sb: StringBuilder, numberWidth: Int): Unit = this match {
114-
case Str(s, lines) =>
115-
if (numberWidth != 0) {
116-
val ln = lines.show
117-
if (ln.nonEmpty) {
118-
val pad = (numberWidth - ln.length - 1)
119-
assert(pad >= 0)
120-
sb.append(" " * pad)
121-
sb.append(ln)
122-
sb.append("|")
123-
}
124-
}
113+
def print(sb: StringBuilder): Unit = this match {
114+
case Str(s) =>
125115
sb.append(s.replaceAll("[ ]+$", ""))
126116
case _ =>
127117
var follow = false
128118
for (elem <- relems.reverse) {
129119
if (follow) sb.append(System.lineSeparator)
130-
elem.print(sb, numberWidth)
120+
elem.print(sb)
131121
follow = true
132122
}
133123
}
134124

135-
def maxLine: Int = this match {
136-
case Str(_, lines) => lines.end
137-
case _ => relems.foldLeft(-1)((acc, relem) => acc max relem.maxLine)
138-
}
139-
140-
def mkString(width: Int = Int.MaxValue, withLineNumbers: Boolean = false): String = {
125+
def mkString(width: Int = Int.MaxValue): String = {
141126
val sb = new StringBuilder
142127
// width display can be upto a range "n-n" where 1 <= n <= maxLine+1
143-
val numberWidth = if (withLineNumbers) (2 * (maxLine + 1).toString.length) + 2 else 0
144-
layout(width - numberWidth).print(sb, numberWidth)
128+
layout(width).print(sb)
145129
sb.toString
146130
}
147131

@@ -190,12 +174,9 @@ object Texts {
190174

191175
}
192176

193-
case class Str(s: String, lineRange: LineRange = EmptyLineRange) extends Text {
177+
case class Str(s: String) extends Text:
194178
override def relems: List[Text] = List(this)
195-
override def toString = this match
196-
case Str(s, EmptyLineRange) => s"Str($s)"
197-
case Str(s, lineRange) => s"Str($s, $lineRange)"
198-
}
179+
override def toString = s"Str($s)"
199180

200181
case class Vertical(relems: List[Text]) extends Text
201182
case class Fluid(relems: List[Text]) extends Text

compiler/test/dotty/tools/dotc/TupleShowTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TupleShowTests extends DottyTest:
5252
))
5353
chkEq(exp, obt)
5454

55-
@Test def tup3_show10 = chkEq("(Int,\n Long,\n Short)".normEOL, tup3.toText(ctx.printer).mkString(10, false))
55+
@Test def tup3_show10 = chkEq("(Int,\n Long,\n Short)".normEOL, tup3.toText(ctx.printer).mkString(10))
5656

5757
val res21: String =
5858
"""|(Int, Int, Int, Int, Int, Long, Long, Long, Long, Long, Int, Int, Int, Int,

docs/_docs/contributing/debugging/other-debugging.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ So, the error happened in the Namer's `checkNoConflict` method (after which all
121121
Printing from the `show` and `-Xprint` is done from the Printers framework (discussed in more details below). The following settings influence the output of the printers:
122122

123123
```scala
124-
val printLines = BooleanSetting("-print-lines" , "Show source code line numbers.") withAbbreviation "--print-lines"
125124
val uniqid = BooleanSetting("-uniqid" , "Uniquely tag all identifiers in debugging output.") withAbbreviation "--unique-id"
126125
val XprintInline = BooleanSetting("-Xprint-inline" , "Show where inlined code comes from")
127126
val XprintTypes = BooleanSetting("-Xprint-types" , "Print tree types (debugging option).")

presentation-compiler/src/main/dotty/tools/pc/RawScalaPresentationCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ case class RawScalaPresentationCompiler(
6565

6666
override val scalaVersion = BuildInfo.scalaVersion
6767

68-
private val forbiddenOptions = Set("-print-lines", "-print-tasty")
68+
private val forbiddenOptions = Set("-print-tasty")
6969
private val forbiddenDoubleOptions = Set.empty[String]
7070

7171
val driverSettings =

presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case class ScalaPresentationCompiler(
7272

7373
val scalaVersion = BuildInfo.scalaVersion
7474

75-
private val forbiddenOptions = Set("-print-lines", "-print-tasty")
75+
private val forbiddenOptions = Set("-print-tasty")
7676
private val forbiddenDoubleOptions = Set.empty[String]
7777

7878

tests/neg/i13026.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -print-lines
2-
31
val x: Int = "not an int" // error
42
val y: Int = "not an int" // error
53
def foo(x: Any) = x.foo // error

0 commit comments

Comments
 (0)