Skip to content

LazyVals: fix underflows in binary shifts. #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import scala.annotation.tailrec
object LazyVals {
private val unsafe = scala.concurrent.util.Unsafe.instance

final val BITS_PER_LAZY_VAL = 2
final val LAZY_VAL_MASK = 3
final val BITS_PER_LAZY_VAL = 2L
final val LAZY_VAL_MASK = 3L

@inline def STATE(cur: Long, ord: Int) = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK
@inline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = {
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
// compute or create appropriate offsetSymol, bitmap and bits used by current ValDef
appendOffsetDefs.get(companion.moduleClass) match {
case Some(info) =>
val flagsPerLong = 64 / dotty.runtime.LazyVals.BITS_PER_LAZY_VAL
val flagsPerLong = (64 / dotty.runtime.LazyVals.BITS_PER_LAZY_VAL).toInt
info.ord += 1
ord = info.ord % flagsPerLong
val id = info.ord / flagsPerLong
Expand Down
65 changes: 65 additions & 0 deletions tests/run/LazyValsLongs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class I {
object A1
object A2
object A3
object A4
object A5
object A6
object A7
object A8
object A9
object A10
object A11
object A12
object A13
object A14
object A15
object A16
object A17
object A18
}

object Test {
def main(args: Array[String]): Unit = {
val c = new I
import c._
val l1 = List(A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
A10,
A11,
A12,
A13,
A14,
A15,
A16,
A17,
A18)
val l2 = List(A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
A10,
A11,
A12,
A13,
A14,
A15,
A16,
A17,
A18)
assert(l1.mkString == l2.mkString)
assert(!l1.contains(null))
}
}