From ef3dacfc56f301cdc6598757352e75fc728e83df Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 2 Sep 2022 11:49:19 +0200 Subject: [PATCH 1/2] Better output under -Ydetailed-stats - Don't print empty lines if Stats.enabled is false - Print constraint size --- compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala | 7 ++++--- compiler/src/dotty/tools/dotc/util/Stats.scala | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala index c1b23888b491..61d1ee0de58a 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala @@ -12,9 +12,10 @@ trait ConstraintRunInfo { self: Run => maxSize = size maxConstraint = c } - def printMaxConstraint()(using Context): Unit = { + def printMaxConstraint()(using Context): Unit = val printer = if (ctx.settings.YdetailedStats.value) default else typr - if (maxSize > 0) printer.println(s"max constraint = ${maxConstraint.nn.show}") - } + if maxSize > 0 then + printer.println(s"max constraint = ${maxConstraint.nn.show}\nsize = $maxSize") + protected def reset(): Unit = maxConstraint = null } diff --git a/compiler/src/dotty/tools/dotc/util/Stats.scala b/compiler/src/dotty/tools/dotc/util/Stats.scala index 60465e519452..f04957f26400 100644 --- a/compiler/src/dotty/tools/dotc/util/Stats.scala +++ b/compiler/src/dotty/tools/dotc/util/Stats.scala @@ -55,7 +55,7 @@ import collection.mutable } def maybeMonitored[T](op: => T)(using Context): T = - if (ctx.settings.YdetailedStats.value) { + if (ctx.settings.YdetailedStats.value && hits.nonEmpty) { monitored = true try op finally { From 5c16d2c41aea1b239cc48777c7fefcc5f919d6ed Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 2 Sep 2022 12:05:41 +0200 Subject: [PATCH 2/2] Handle stackoverflows when trying to print the maximal constraint --- compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala index 61d1ee0de58a..d2b1246a8149 100644 --- a/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala +++ b/compiler/src/dotty/tools/dotc/core/ConstraintRunInfo.scala @@ -13,9 +13,11 @@ trait ConstraintRunInfo { self: Run => maxConstraint = c } def printMaxConstraint()(using Context): Unit = - val printer = if (ctx.settings.YdetailedStats.value) default else typr if maxSize > 0 then - printer.println(s"max constraint = ${maxConstraint.nn.show}\nsize = $maxSize") + val printer = if ctx.settings.YdetailedStats.value then default else typr + printer.println(s"max constraint size: $maxSize") + try printer.println(s"max constraint = ${maxConstraint.nn.show}") + catch case ex: StackOverflowError => printer.println("max constraint cannot be printed due to stack overflow") protected def reset(): Unit = maxConstraint = null }