Skip to content

Commit 4629ec1

Browse files
committed
Fixing tests, mima and synchronization in new lazy vals
1 parent 7f79060 commit 4629ec1

File tree

5 files changed

+62
-32
lines changed

5 files changed

+62
-32
lines changed

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
422422
// if observed a null (uninitialized) value
423423
val initialize = {
424424
// var result: AnyRef
425-
val resSymbNullable = newSymbol(lazyInitMethodSymbol, lazyNme.result, Synthetic | Mutable, defn.ObjectType)
425+
val resSymbNullable = newSymbol(lazyInitMethodSymbol, lazyNme.resultNullable, Synthetic | Mutable, defn.ObjectType)
426426
val resSymb = newSymbol(lazyInitMethodSymbol, lazyNme.result, Synthetic | Mutable, defn.ObjectType)
427427
// releasing block in finally
428428
val lockRel = {
@@ -747,6 +747,7 @@ object LazyVals {
747747
val flag: TermName = "flag".toTermName
748748
val state: TermName = "state".toTermName
749749
val result: TermName = "result".toTermName
750+
val resultNullable: TermName = "resultNullable".toTermName
750751
val value: TermName = "value".toTermName
751752
val initialized: TermName = "initialized".toTermName
752753
val initialize: TermName = "initialize".toTermName

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
597597
val clsIn = dir.lookupName("Test.class", directory = false).input
598598
val clsNode = loadClassNode(clsIn)
599599
val method = getMethod(clsNode, "test")
600-
assertEquals(118, instructionsFromMethod(method).size)
600+
assertEquals(36, instructionsFromMethod(method).size)
601601
}
602602
}
603603

library/src/scala/runtime/LazyVals.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ object LazyVals {
141141
}
142142

143143
def getStaticFieldOffset(field: java.lang.reflect.Field): Long = {
144+
@nowarn
144145
val r = unsafe.staticFieldOffset(field)
145146
if (debug)
146147
println(s"getStaticFieldOffset(${field.getDeclaringClass}, ${field.getName}) = $r")

project/MiMaFilters.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import com.typesafe.tools.mima.core._
44
object MiMaFilters {
55
val Library: Seq[ProblemFilter] = Seq(
66
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
7+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getOffsetStatic"),
8+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticFieldOffset"),
9+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticFieldOffset"),
710
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
811
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.evaluating"),
912
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticOffset"),
@@ -12,10 +15,12 @@ object MiMaFilters {
1215
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waiting"),
1316
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingAwaitRelease"),
1417
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingRelease"),
18+
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$LazyValControlState"),
19+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.controlState"),
1520
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Evaluating$"),
16-
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NULL$"),
21+
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NullValue$"),
1722
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),
1823
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.Evaluating"),
19-
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.NULL"),
24+
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.NullValue"),
2025
)
2126
}

tests/printing/transformed/lazy-vals-new.check

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ package <empty> {
2424
new scala.runtime.ModuleSerializationProxy(classOf[A])
2525
@volatile lazy <static> var x$lzy1: Object = null
2626
lazy def x(): Int =
27+
{
28+
var result: Object = A#x$lzy1
29+
if result.isInstanceOf[Int] then return scala.Int.unbox(result) else
30+
if result.==(scala.runtime.LazyVals.NullValue) then
31+
return scala.Int.unbox(null)
32+
else return scala.Int.unbox(A.x$lzyINIT1())
33+
}
34+
private def x$lzyINIT1(): Object =
2735
while <empty> do
2836
{
2937
val current: Object = A#x$lzy1
@@ -35,49 +43,64 @@ package <empty> {
3543
then
3644
{
3745
var result: Object = null
46+
var resultNullable: Object = null
3847
try
3948
{
40-
result = scala.Int.box(2)
41-
if result.==(null) then
49+
resultNullable = scala.Int.box(2)
50+
if resultNullable.==(null) then
4251
result = scala.runtime.LazyVals.NullValue
52+
else result = resultNullable
53+
return resultNullable
4354
}
4455
finally
45-
if
46-
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
47-
scala.runtime.LazyVals.Evaluating
48-
, result).unary_!()
49-
then
50-
{
51-
val lock: scala.runtime.LazyVals.LazyVals$Waiting =
52-
A#x$lzy1.asInstanceOf[
53-
scala.runtime.LazyVals.LazyVals$Waiting
54-
]
56+
{
57+
if
5558
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
56-
lock
57-
, result)
58-
lock.countDown()
59-
}
59+
scala.runtime.LazyVals.Evaluating
60+
, result).unary_!()
61+
then
62+
{
63+
val lock: scala.runtime.LazyVals.LazyVals$Waiting =
64+
A#x$lzy1.asInstanceOf[
65+
scala.runtime.LazyVals.LazyVals$Waiting
66+
]
67+
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0
68+
,
69+
lock, result)
70+
lock.countDown()
71+
}
72+
else ()
73+
()
74+
}
6075
}
76+
else ()
6177
else
62-
if current.isInstanceOf[scala.runtime.LazyVals.Evaluating] then
63-
{
64-
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
65-
scala.runtime.LazyVals.Evaluating
66-
, new scala.runtime.LazyVals.LazyVals$Waiting())
67-
()
68-
}
69-
else
70-
if current.isInstanceOf[scala.runtime.LazyVals.NullValue] then
71-
return 0
78+
if
79+
current.isInstanceOf[
80+
scala.runtime.LazyVals.LazyVals$LazyValControlState
81+
]
82+
then
83+
if current.==(scala.runtime.LazyVals.Evaluating) then
84+
{
85+
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
86+
scala.runtime.LazyVals.Evaluating
87+
, new scala.runtime.LazyVals.LazyVals$Waiting())
88+
()
89+
}
7290
else
7391
if current.isInstanceOf[scala.runtime.LazyVals.LazyVals$Waiting]
7492
then
7593

7694
current.asInstanceOf[scala.runtime.LazyVals.LazyVals$Waiting].
7795
await
7896
()
79-
else return scala.Int.unbox(current)
97+
else
98+
if current.==(scala.runtime.LazyVals.NullValue) then
99+
return null
100+
else ()
101+
else return current
80102
}
81103
}
82104
final lazy module val A: A = new A()
83-
}
105+
}
106+

0 commit comments

Comments
 (0)