From f55b40efa01218cfdbd082720ab8f795dc6902db Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 26 Jul 2023 18:18:42 +0100 Subject: [PATCH] Drop Mode.PrintShowExceptions && add Mode docs Free up Mode bit 18, by reusing -Yshow-print-errors. [Cherry-picked 7bb666c799ff83bf374da26dd18f8448f7542e68] --- compiler/src/dotty/tools/dotc/core/Decorators.scala | 2 +- compiler/src/dotty/tools/dotc/core/Mode.scala | 13 +++++++++---- .../src/dotty/tools/dotc/transform/Pickler.scala | 12 +++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 4ef0dbc9a43b..8ae4cb4ceee2 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Mode.scala b/compiler/src/dotty/tools/dotc/core/Mode.scala index ea63eb6a419b..11abe43732db 100644 --- a/compiler/src/dotty/tools/dotc/core/Mode.scala +++ b/compiler/src/dotty/tools/dotc/core/Mode.scala @@ -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) @@ -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. diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index d69076107d48..97a4b3a3afe0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -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 }