Skip to content

Commit b28f766

Browse files
committed
Change some
1 parent 0735a68 commit b28f766

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ object Config {
4949
*/
5050
final val checkNoSkolemsInInfo = false
5151

52+
/** Check that Name#toString is not called directly from backend by analyzing
53+
* the stack trace of each toString call on names. This is very expensive,
54+
* so not suitable for continuous testing. But it can be used to find a problem
55+
* when running a specific test.
56+
*/
57+
final val checkBackendNames = false
58+
5259
/** Type comparer will fail with an assert if the upper bound
5360
* of a constrained parameter becomes Nothing. This should be turned
5461
* on only for specific debugging as normally instantiation to Nothing

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import collection.mutable.{ Builder, StringBuilder, AnyRefMap }
1414
import collection.immutable.WrappedString
1515
import collection.generic.CanBuildFrom
1616
import util.{DotClass, SimpleMap}
17+
import config.Config
1718
import java.util.HashMap
1819

1920
//import annotation.volatile
@@ -289,7 +290,32 @@ object Names {
289290

290291
override def toString =
291292
if (length == 0) ""
292-
else new String(chrs, start, length)
293+
else {
294+
if (Config.checkBackendNames) {
295+
if (!toStringOK) {
296+
println("Backend should not call Name#toString, Name#mangledString should be used instead.")
297+
new Error().printStackTrace()
298+
assert(false)
299+
}
300+
}
301+
new String(chrs, start, length)
302+
}
303+
304+
private def toStringOK = {
305+
val trace = Thread.currentThread.getStackTrace
306+
!trace.exists(_.getClassName.endsWith("GenBCode")) ||
307+
trace.exists(elem =>
308+
List(
309+
"mangledString",
310+
"toSimpleName",
311+
"decode",
312+
"unmangle",
313+
"dotty$tools$dotc$core$NameOps$NameDecorator$$functionArityFor$extension",
314+
"dotty$tools$dotc$typer$Checking$CheckNonCyclicMap$$apply",
315+
"$plus$plus",
316+
"readConstant")
317+
.contains(elem.getMethodName))
318+
}
293319

294320
def debugString: String = toString
295321
}

0 commit comments

Comments
 (0)