Skip to content

Commit 3ceb51d

Browse files
committed
Make reporting nicer
Allow use of `result` instead of having to pass a lambda.
1 parent 1a2682b commit 3ceb51d

File tree

9 files changed

+30
-17
lines changed

9 files changed

+30
-17
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ object desugar {
766766
}
767767

768768
flatTree(cdef1 :: companions ::: implicitWrappers)
769-
}.reporting(res => i"desugared: $res", Printers.desugar)
769+
}.reporting(i"desugared: $result", Printers.desugar)
770770

771771
/** Expand
772772
*

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package core
34

45
import annotation.tailrec
@@ -168,11 +169,16 @@ object Decorators {
168169
}
169170
}
170171

171-
implicit class genericDeco[T](val x: T) extends AnyVal {
172-
def reporting(op: T => String, printer: config.Printers.Printer = config.Printers.default): T = {
173-
printer.println(op(x))
172+
implicit object reportDeco {
173+
def (x: T) reporting[T](
174+
op: given WrappedResult[T] => String,
175+
printer: config.Printers.Printer = config.Printers.default): T = {
176+
printer.println(op given WrappedResult(x))
174177
x
175178
}
179+
}
180+
181+
implicit class genericDeco[T](val x: T) extends AnyVal {
176182
def assertingErrorsReported(implicit ctx: Context): T = {
177183
assert(ctx.reporter.errorsReported)
178184
x

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ final class ProperGadtConstraint private(
123123
}
124124

125125
// The replaced symbols are picked up here.
126-
addToConstraint(poly1, tvars).reporting({ _ =>
127-
i"added to constraint: $params%, %\n$debugBoundsDescription"
128-
}, gadts)
126+
addToConstraint(poly1, tvars)
127+
.reporting(i"added to constraint: $params%, %\n$debugBoundsDescription", gadts)
129128
}
130129

131130
override def addBound(sym: Symbol, bound: Type, isUpper: Boolean)(implicit ctx: Context): Boolean = {
@@ -159,7 +158,7 @@ final class ProperGadtConstraint private(
159158
val oldUpperBound = bounds(symTvar.origin)
160159
// If we have bounds:
161160
// F >: [t] => List[t] <: [t] => Any
162-
// and we want to record that:
161+
// and we want to record that:
163162
// F <: [+A] => List[A]
164163
// we need to adapt the variance and instead record that:
165164
// F <: [A] => List[A]
@@ -177,10 +176,10 @@ final class ProperGadtConstraint private(
177176
if (isUpper) addUpperBound(symTvar.origin, bound1)
178177
else addLowerBound(symTvar.origin, bound1)
179178
}
180-
).reporting({ res =>
179+
).reporting({
181180
val descr = if (isUpper) "upper" else "lower"
182181
val op = if (isUpper) "<:" else ">:"
183-
i"adding $descr bound $sym $op $bound = $res"
182+
i"adding $descr bound $sym $op $bound = $result"
184183
}, gadts)
185184
}
186185

@@ -206,7 +205,7 @@ final class ProperGadtConstraint private(
206205
case tb => tb
207206
}
208207
retrieveBounds
209-
//.reporting({ res => i"gadt bounds $sym: $res" }, gadts)
208+
//.reporting(i"gadt bounds $sym: $result", gadts)
210209
//.ensuring(containsNoInternalTypes(_))
211210
}
212211
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
548548
merge(this.boundsMap, that.boundsMap, mergeEntries),
549549
merge(this.lowerMap, that.lowerMap, mergeParams),
550550
merge(this.upperMap, that.upperMap, mergeParams))
551-
}.reporting(res => i"constraint merge $this with $other = $res", constr)
551+
}.reporting(i"constraint merge $this with $other = $result", constr)
552552

553553
def rename(tl: TypeLambda)(implicit ctx: Context): OrderingConstraint = {
554554
assert(contains(tl))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ object Symbols {
782782
}
783783
sourceFromTopLevel(ctx.withPhaseNoLater(ctx.flattenPhase))
784784
}
785-
}//.reporting(res => i"source of $this # $id in ${denot.owner} = $res")
785+
}//.reporting(i"source of $this # $id in ${denot.owner} = $result")
786786
mySource
787787
}
788788

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
628628
if (idx >= 0 && idx < args.length) {
629629
def finish(arg: Tree) =
630630
new TreeTypeMap().transform(arg) // make sure local bindings in argument have fresh symbols
631-
.reporting(res => i"projecting $tree -> $res", inlining)
631+
.reporting(i"projecting $tree -> $result", inlining)
632632
val arg = args(idx)
633633
if (precomputed)
634634
if (isPureExpr(arg)) finish(arg)

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ object ProtoTypes {
401401
resType match {
402402
case SelectionProto(name: TermName, mbrType, _, _) =>
403403
ctx.typer.hasExtensionMethod(tp, name, argType, mbrType)
404-
//.reporting(res => i"has ext $tp $name $argType $mbrType: $res")
404+
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
405405
case _ =>
406406
false
407407
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ class Typer extends Namer
25652565
typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt)
25662566
}
25672567
recur(tycon, pt)
2568-
.reporting(res => i"try new $tree -> $res", typr)
2568+
.reporting(i"try new $tree -> $result", typr)
25692569
}
25702570
} { (nu, nuState) =>
25712571
if (nu.isEmpty) fallBack

compiler/src/dotty/tools/package.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ package object tools {
2323
/** Throws an `UnsupportedOperationException` with the given method name. */
2424
def unsupported(methodName: String): Nothing =
2525
throw new UnsupportedOperationException(methodName)
26+
27+
object WrappedResult {
28+
opaque type Type[T] = T
29+
def unwrap[T](x: Type[T]): T = x
30+
def apply[T](x: T): Type[T] = x
31+
}
32+
type WrappedResult[T] = WrappedResult.Type[T]
33+
def result[T] given (x: WrappedResult[T]): T = WrappedResult.unwrap(x)
2634
}

0 commit comments

Comments
 (0)