Skip to content

Commit c1b0444

Browse files
authored
Merge pull request #13464 from dwijnand/typed-trace
Make trace typed, to avoid needless casting
2 parents d519682 + 3fe0054 commit c1b0444

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait TraceSyntax:
3333
apply(question, if cond then Printers.default else Printers.noPrinter, show)(op)
3434
else op
3535

36-
inline def apply[T](inline question: String, inline printer: Printers.Printer, inline showOp: Any => String)(inline op: T)(using Context): T =
36+
inline def apply[T, U >: T](inline question: String, inline printer: Printers.Printer, inline showOp: U => String)(inline op: T)(using Context): T =
3737
inline if isEnabled then
3838
doTrace[T](question, printer, showOp)(op)
3939
else op
@@ -60,15 +60,15 @@ trait TraceSyntax:
6060

6161
private def doTrace[T](question: => String,
6262
printer: Printers.Printer = Printers.default,
63-
showOp: Any => String = alwaysToString)
63+
showOp: T => String = alwaysToString)
6464
(op: => T)(using Context): T =
6565
if ctx.mode.is(Mode.Printing) || !isForced && (printer eq Printers.noPrinter) then op
6666
else
6767
// Avoid evaluating question multiple time, since each evaluation
6868
// may cause some extra logging output.
6969
val q = question
7070
val leading = s"==> $q?"
71-
val trailing = (res: Any) => s"<== $q = ${showOp(res)}"
71+
val trailing = (res: T) => s"<== $q = ${showOp(res)}"
7272
var finalized = false
7373
var logctx = ctx
7474
while logctx.reporter.isInstanceOf[StoreReporter] do logctx = logctx.outer

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class Semantic {
321321
def widenArgs: List[Value] = values.map(_.widenArg).toList
322322

323323
extension (value: Value)
324-
def select(field: Symbol, source: Tree, needResolve: Boolean = true): Contextual[Result] = log("select " + field.show, printer, res => res.asInstanceOf[Result].show) {
324+
def select(field: Symbol, source: Tree, needResolve: Boolean = true): Contextual[Result] = log("select " + field.show, printer, (_: Result).show) {
325325
if promoted.isCurrentObjectPromoted then Result(Hot, Nil)
326326
else value match {
327327
case Hot =>
@@ -371,7 +371,7 @@ class Semantic {
371371
}
372372
}
373373

374-
def call(meth: Symbol, args: List[ArgInfo], superType: Type, source: Tree, needResolve: Boolean = true): Contextual[Result] = log("call " + meth.show + ", args = " + args, printer, res => res.asInstanceOf[Result].show) {
374+
def call(meth: Symbol, args: List[ArgInfo], superType: Type, source: Tree, needResolve: Boolean = true): Contextual[Result] = log("call " + meth.show + ", args = " + args, printer, (_: Result).show) {
375375
def checkArgs = args.flatMap(_.promote)
376376

377377
// fast track if the current object is already initialized
@@ -445,7 +445,7 @@ class Semantic {
445445
}
446446

447447
/** Handle a new expression `new p.C` where `p` is abstracted by `value` */
448-
def instantiate(klass: ClassSymbol, ctor: Symbol, args: List[ArgInfo], source: Tree): Contextual[Result] = log("instantiating " + klass.show + ", value = " + value + ", args = " + args, printer, res => res.asInstanceOf[Result].show) {
448+
def instantiate(klass: ClassSymbol, ctor: Symbol, args: List[ArgInfo], source: Tree): Contextual[Result] = log("instantiating " + klass.show + ", value = " + value + ", args = " + args, printer, (_: Result).show) {
449449
val trace1 = trace.add(source)
450450
if promoted.isCurrentObjectPromoted then Result(Hot, Nil)
451451
else value match {
@@ -702,7 +702,7 @@ class Semantic {
702702
*
703703
* This method only handles cache logic and delegates the work to `cases`.
704704
*/
705-
def eval(expr: Tree, thisV: Addr, klass: ClassSymbol, cacheResult: Boolean = false): Contextual[Result] = log("evaluating " + expr.show + ", this = " + thisV.show, printer, res => res.asInstanceOf[Result].show) {
705+
def eval(expr: Tree, thisV: Addr, klass: ClassSymbol, cacheResult: Boolean = false): Contextual[Result] = log("evaluating " + expr.show + ", this = " + thisV.show, printer, (_: Result).show) {
706706
val innerMap = cache.getOrElseUpdate(thisV, new EqHashMap[Tree, Value])
707707
if (innerMap.contains(expr)) Result(innerMap(expr), Errors.empty)
708708
else {
@@ -911,7 +911,7 @@ class Semantic {
911911
}
912912

913913
/** Handle semantics of leaf nodes */
914-
def cases(tp: Type, thisV: Addr, klass: ClassSymbol, source: Tree): Contextual[Result] = log("evaluating " + tp.show, printer, res => res.asInstanceOf[Result].show) {
914+
def cases(tp: Type, thisV: Addr, klass: ClassSymbol, source: Tree): Contextual[Result] = log("evaluating " + tp.show, printer, (_: Result).show) {
915915
tp match {
916916
case _: ConstantType =>
917917
Result(Hot, Errors.empty)
@@ -941,7 +941,7 @@ class Semantic {
941941
}
942942

943943
/** Resolve C.this that appear in `klass` */
944-
def resolveThis(target: ClassSymbol, thisV: Value, klass: ClassSymbol, source: Tree): Contextual[Value] = log("resolving " + target.show + ", this = " + thisV.show + " in " + klass.show, printer, res => res.asInstanceOf[Value].show) {
944+
def resolveThis(target: ClassSymbol, thisV: Value, klass: ClassSymbol, source: Tree): Contextual[Value] = log("resolving " + target.show + ", this = " + thisV.show + " in " + klass.show, printer, (_: Value).show) {
945945
if target == klass then thisV
946946
else if target.is(Flags.Package) then Hot
947947
else
@@ -969,7 +969,7 @@ class Semantic {
969969
*
970970
* See `tpd.outerSelect` and `ElimOuterSelect`.
971971
*/
972-
def resolveOuterSelect(target: ClassSymbol, thisV: Value, hops: Int, source: Tree): Contextual[Value] = log("resolving outer " + target.show + ", this = " + thisV.show + ", hops = " + hops, printer, res => res.asInstanceOf[Value].show) {
972+
def resolveOuterSelect(target: ClassSymbol, thisV: Value, hops: Int, source: Tree): Contextual[Value] = log("resolving outer " + target.show + ", this = " + thisV.show + ", hops = " + hops, printer, (_: Value).show) {
973973
// Is `target` reachable from `cls` with the given `hops`?
974974
def reachable(cls: ClassSymbol, hops: Int): Boolean =
975975
if hops == 0 then cls == target
@@ -1011,7 +1011,7 @@ class Semantic {
10111011
else cases(tref.prefix, thisV, klass, source)
10121012

10131013
/** Initialize part of an abstract object in `klass` of the inheritance chain */
1014-
def init(tpl: Template, thisV: Addr, klass: ClassSymbol): Contextual[Result] = log("init " + klass.show, printer, res => res.asInstanceOf[Result].show) {
1014+
def init(tpl: Template, thisV: Addr, klass: ClassSymbol): Contextual[Result] = log("init " + klass.show, printer, (_: Result).show) {
10151015
val errorBuffer = new mutable.ArrayBuffer[Error]
10161016

10171017
val paramsMap = tpl.constr.termParamss.flatten.map { vdef =>

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ trait SpaceLogic {
114114
def show(sp: Space): String
115115

116116
/** Simplify space such that a space equal to `Empty` becomes `Empty` */
117-
def simplify(space: Space)(using Context): Space = trace(s"simplify ${show(space)} --> ", debug, x => show(x.asInstanceOf[Space]))(space match {
117+
def simplify(space: Space)(using Context): Space = trace(s"simplify ${show(space)} --> ", debug, show)(space match {
118118
case Prod(tp, fun, spaces) =>
119119
val sps = spaces.map(simplify(_))
120120
if (sps.contains(Empty)) Empty
@@ -194,7 +194,7 @@ trait SpaceLogic {
194194
}
195195

196196
/** Intersection of two spaces */
197-
def intersect(a: Space, b: Space)(using Context): Space = trace(s"${show(a)} & ${show(b)}", debug, x => show(x.asInstanceOf[Space])) {
197+
def intersect(a: Space, b: Space)(using Context): Space = trace(s"${show(a)} & ${show(b)}", debug, show) {
198198
def tryDecompose1(tp: Type) = intersect(Or(decompose(tp)), b)
199199
def tryDecompose2(tp: Type) = intersect(a, Or(decompose(tp)))
200200

@@ -226,7 +226,7 @@ trait SpaceLogic {
226226
}
227227

228228
/** The space of a not covered by b */
229-
def minus(a: Space, b: Space)(using Context): Space = trace(s"${show(a)} - ${show(b)}", debug, x => show(x.asInstanceOf[Space])) {
229+
def minus(a: Space, b: Space)(using Context): Space = trace(s"${show(a)} - ${show(b)}", debug, show) {
230230
def tryDecompose1(tp: Type) = minus(Or(decompose(tp)), b)
231231
def tryDecompose2(tp: Type) = minus(a, Or(decompose(tp)))
232232

0 commit comments

Comments
 (0)