diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-09-05 15:27:15 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-09-05 16:13:44 +0200 |
commit | fb43ec8dc28625c929beaf28767a955388700d0d (patch) | |
tree | 1ece2ca12eacf4878839bb35a9b85d9306ffa6f6 /src/library | |
parent | d46519da657ada39d9928308709cdb80ddcd53ce (diff) | |
download | scala-fb43ec8dc28625c929beaf28767a955388700d0d.tar.gz scala-fb43ec8dc28625c929beaf28767a955388700d0d.tar.bz2 scala-fb43ec8dc28625c929beaf28767a955388700d0d.zip |
SI-7814 Avoid init cycle between Predef, `package`, ScalaRuntime
Not every application will force these in a single thread; we
have to do our best to avoid cycles between them.
The enclosed test was failing every time before the change.
This commit breaks the cycle by avoiding computing `tupleNames`
in the constructor of `ScalaRuntime`. The new version has the
added benefit of including specialized tuple subclasses, which
is verified with a unit test for `isTuple`.
Are there more of these lurking? It seems likely. I'm more than
a little concerned about the way the `ControlThrowable` fires up
`scala.SystemProperties` to check whether or not to suppress
stack traces; there is already an ugly hack in place:
object NoStackTrace {
final def noSuppression = _noSuppression
// two-stage init to make checkinit happy,
// since sys.SystemProperties.noTraceSupression.value
// calls back into NoStackTrace.noSuppression
final private var _noSuppression = false
_noSuppression = sys.SystemProperties.noTraceSupression.value
}
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/runtime/ScalaRunTime.scala | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index 1d8fe5e9ad..4fee6d75a3 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -34,21 +34,13 @@ object ScalaRunTime { clazz.isArray && (atLevel == 1 || isArrayClass(clazz.getComponentType, atLevel - 1)) def isValueClass(clazz: jClass[_]) = clazz.isPrimitive() - def isTuple(x: Any) = x != null && tupleNames(x.getClass.getName) + + // includes specialized subclasses and future proofed against hypothetical TupleN (for N > 22) + def isTuple(x: Any) = x != null && x.getClass.getName.startsWith("scala.Tuple") def isAnyVal(x: Any) = x match { case _: Byte | _: Short | _: Char | _: Int | _: Long | _: Float | _: Double | _: Boolean | _: Unit => true case _ => false } - // Avoiding boxing which messes up the specialized tests. Don't ask. - private val tupleNames = { - var i = 22 - var names: List[String] = Nil - while (i >= 1) { - names ::= ("scala.Tuple" + String.valueOf(i)) - i -= 1 - } - names.toSet - } /** Return the class object representing an array with element class `clazz`. */ |