Skip to content

Commit f62ffd8

Browse files
committed
Clean-up the new lazy vals
1 parent 572c674 commit f62ffd8

16 files changed

+140
-215
lines changed

Diff for: bench-micro/results_isStable.json

Whitespace-only changes.

Diff for: compiler/src/dotty/tools/dotc/core/Definitions.scala

+6
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,12 @@ class Definitions {
19901990
addSyntheticSymbolsComments
19911991
}
19921992

1993+
/** Definitions used in Lazy Vals implementation */
1994+
val LazyValsModuleName = "scala.runtime.LazyVals"
1995+
@tu lazy val LazyValsModule = requiredModule(LazyValsModuleName)
1996+
@tu lazy val LazyValsWaitingState = requiredClass(s"$LazyValsModuleName.Waiting")
1997+
@tu lazy val LazyValsControlState = requiredClass(s"$LazyValsModuleName.LazyValControlState")
1998+
19931999
def addSyntheticSymbolsComments(using Context): Unit =
19942000
def add(sym: Symbol, doc: String) = ctx.docCtx.foreach(_.addDocstring(sym, Some(Comment(NoSpan, doc))))
19952001

Diff for: compiler/src/dotty/tools/dotc/transform/LazyVals.scala

+96-153
Large diffs are not rendered by default.

Diff for: compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

+1
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class TreeChecker extends Phase with SymTransformer {
498498
def isAllowed(sym: Symbol): Boolean = sym.is(ConstructorProxy)
499499

500500
val symbolsNotDefined = (decls -- defined - constr.symbol).filterNot(isAllowed)
501+
501502
assert(symbolsNotDefined.isEmpty,
502503
i" $cls tree does not define members: ${symbolsNotDefined.toList}%, %\n" +
503504
i"expected: ${decls.toList}%, %\n" +

Diff for: compiler/test/dotc/pos-lazy-vals-tests.allowlist

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ t6278-synth-def.scala
3434
t6925b.scala
3535
t7011.scala
3636
t8306.scala
37-
zipped.scala
37+
zipped.scala

Diff for: compiler/test/dotc/run-from-tasty.blacklist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# CI only: cannot reduce summonFrom with
2-
sip23-valueof.scala
2+
sip23-valueof.scala

Diff for: compiler/test/dotc/run-lazy-vals-tests.allowlist

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ t7406.scala
6363
t8245.scala
6464
unapply.scala
6565
unit-lazy-val.scala
66-
view-iterator-stream.scala
66+
view-iterator-stream.scala

Diff for: compiler/test/dotc/run-test-pickling.blacklist

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ i12753
4343
t6138
4444
t6138-2
4545
i12656.scala
46-
trait-static-forwarder
46+
trait-static-forwarder

Diff for: compiler/test/dotc/run-test-recheck.excludes

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ i5976.scala
1010
tagless.scala
1111
safeThrowsStrawman2.scala
1212
t7584.scala
13-
function-arity.scala
13+
function-arity.scala

Diff for: library/src/scala/runtime/LazyVals.scala

-9
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,11 @@ object LazyVals {
163163

164164

165165
object Names {
166-
final val controlState = "LazyValControlState"
167-
final val waiting = "Waiting"
168-
final val evaluating = "Evaluating"
169-
final val nullValue = "NullValue"
170-
final val waitingAwaitRelease = "await"
171-
final val waitingRelease = "countDown"
172166
final val state = "STATE"
173167
final val cas = "CAS"
174-
final val objCas = "objCAS"
175168
final val setFlag = "setFlag"
176169
final val wait4Notification = "wait4Notification"
177170
final val get = "get"
178171
final val getOffset = "getOffset"
179-
final val getOffsetStatic = "getOffsetStatic"
180-
final val getStaticFieldOffset = "getStaticFieldOffset"
181172
}
182173
}

Diff for: project/MiMaFilters.scala

-11
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@ object MiMaFilters {
55
val Library: Seq[ProblemFilter] = Seq(
66
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.MappedAlternative"),
77

8-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
9-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getOffsetStatic"),
108
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticFieldOffset"),
11-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticFieldOffset"),
129
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
13-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.evaluating"),
14-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticOffset"),
15-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.nullValue"),
16-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.objCas"),
17-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waiting"),
18-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingAwaitRelease"),
19-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingRelease"),
2010
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$LazyValControlState"),
21-
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.controlState"),
2211
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Evaluating$"),
2312
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NullValue$"),
2413
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),

Diff for: tests/printing/transformed/lazy-vals-legacy.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
object A {
22
lazy val x: Int = 2
3-
}
3+
}

Diff for: tests/printing/transformed/lazy-vals-new.check

+28-33
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ package <empty> {
2222
)
2323
private def writeReplace(): Object =
2424
new scala.runtime.ModuleSerializationProxy(classOf[A])
25-
@volatile lazy <static> var x$lzy1: Object = null
25+
@volatile private lazy <static> var x$lzy1: Object = null
2626
lazy def x(): Int =
2727
{
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())
28+
val result: Object = A#x$lzy1
29+
if result.isInstanceOf[Int] then scala.Int.unbox(result) else
30+
if result.eq(scala.runtime.LazyVals.NullValue) then
31+
scala.Int.unbox(null)
32+
else scala.Int.unbox(A.x$lzyINIT1())
3333
}
3434
private def x$lzyINIT1(): Object =
3535
while <empty> do
3636
{
3737
val current: Object = A#x$lzy1
38-
if current.==(null) then
38+
if current.eq(null) then
3939
if
4040
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0, null,
4141
scala.runtime.LazyVals.Evaluating
@@ -47,31 +47,29 @@ package <empty> {
4747
try
4848
{
4949
resultNullable = scala.Int.box(2)
50-
if resultNullable.==(null) then
50+
if resultNullable.eq(null) then
5151
result = scala.runtime.LazyVals.NullValue
5252
else result = resultNullable
53-
return resultNullable
53+
()
5454
}
5555
finally
56-
{
57-
if
56+
if
57+
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
58+
scala.runtime.LazyVals.Evaluating
59+
, result).unary_!()
60+
then
61+
{
62+
val lock: scala.runtime.LazyVals.LazyVals$Waiting =
63+
A#x$lzy1.asInstanceOf[
64+
scala.runtime.LazyVals.LazyVals$Waiting
65+
]
5866
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
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-
}
67+
lock
68+
, result)
69+
lock.countDown()
70+
}
71+
else ()
72+
return resultNullable
7573
}
7674
else ()
7775
else
@@ -80,10 +78,10 @@ package <empty> {
8078
scala.runtime.LazyVals.LazyVals$LazyValControlState
8179
]
8280
then
83-
if current.==(scala.runtime.LazyVals.Evaluating) then
81+
if current.eq(scala.runtime.LazyVals.Evaluating) then
8482
{
8583
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
86-
scala.runtime.LazyVals.Evaluating
84+
current
8785
, new scala.runtime.LazyVals.LazyVals$Waiting())
8886
()
8987
}
@@ -94,10 +92,7 @@ package <empty> {
9492
current.asInstanceOf[scala.runtime.LazyVals.LazyVals$Waiting].
9593
await
9694
()
97-
else
98-
if current.==(scala.runtime.LazyVals.NullValue) then
99-
return null
100-
else ()
95+
else return null
10196
else return current
10297
}
10398
}

Diff for: tests/printing/transformed/lazy-vals-new.flags

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-Ylightweight-lazy-vals
1+
-Ylightweight-lazy-vals

Diff for: tests/printing/transformed/lazy-vals-new.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
object A {
22
lazy val x: Int = 2
3-
}
3+
}

Diff for: tests/run/lazyVals_c3.1.0.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class Foo:
1010
@main def Test =
1111
val foo = new Foo
1212
println(foo.x)
13-
println(foo.y)
13+
println(foo.y)

0 commit comments

Comments
 (0)