Skip to content

Commit

Permalink
Drop Mode.PrintShowExceptions && add Mode docs
Browse files Browse the repository at this point in the history
Free up Mode bit 18, by reusing -Yshow-print-errors.

[Cherry-picked 7bb666c]
  • Loading branch information
dwijnand authored and Kordyjan committed Dec 7, 2023
1 parent 4cde2e3 commit f55b40e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ object Decorators {
catch
case ex: CyclicReference => "... (caught cyclic reference) ..."
case NonFatal(ex)
if !ctx.mode.is(Mode.PrintShowExceptions) && !ctx.settings.YshowPrintErrors.value =>
if !ctx.settings.YshowPrintErrors.value =>
s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..."
case _ => String.valueOf(x).nn

Expand Down
13 changes: 9 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Mode.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package dotty.tools.dotc.core

/** A collection of mode bits that are part of a context */
/** A collection of mode bits that are part of a context.
*
* What's the difference between a boolean setting and a Mode?
* A setting is usually valid for the entire compilation run, whereas a mode is context specific.
* Changing a setting in a context creates a new SettingsState in that context, which is a relatively big object.
* By comparison, a mode is just an Int.
* But, Mode bits are a scarce resource, so for low priority situations, just reset the state with a setting.
* Also, a setting is externally settable, while a mode isn't.
*/
case class Mode(val bits: Int) extends AnyVal {
import Mode._
def | (that: Mode): Mode = Mode(bits | that.bits)
Expand Down Expand Up @@ -98,9 +106,6 @@ object Mode {
/** Read original positions when unpickling from TASTY */
val ReadPositions: Mode = newMode(17, "ReadPositions")

/** Don't suppress exceptions thrown during show */
val PrintShowExceptions: Mode = newMode(18, "PrintShowExceptions")

val PatternOrTypeBits: Mode = Pattern | Type

/** We are elaborating the fully qualified name of a package clause.
Expand Down
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/Pickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ class Pickler extends Phase {
else
super.runOn(units)
if ctx.settings.YtestPickler.value then
val ctx2 = ctx.fresh.setSetting(ctx.settings.YreadComments, true)
val ctx2 = ctx.fresh
.setSetting(ctx.settings.YreadComments, true)
.setSetting(ctx.settings.YshowPrintErrors, true)
testUnpickler(
using ctx2
.setPeriod(Period(ctx.runId + 1, ctx.base.typerPhase.id))
.setReporter(new ThrowingReporter(ctx.reporter))
.addMode(Mode.ReadPositions)
.addMode(Mode.PrintShowExceptions))
.setPeriod(Period(ctx.runId + 1, ctx.base.typerPhase.id))
.setReporter(new ThrowingReporter(ctx.reporter))
.addMode(Mode.ReadPositions)
)
result
}

Expand Down

0 comments on commit f55b40e

Please sign in to comment.