Skip to content

Commit

Permalink
Clean-up the new lazy vals
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Oct 28, 2022
1 parent 572c674 commit f62ffd8
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 215 deletions.
Empty file removed bench-micro/results_isStable.json
Empty file.
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,12 @@ class Definitions {
addSyntheticSymbolsComments
}

/** Definitions used in Lazy Vals implementation */
val LazyValsModuleName = "scala.runtime.LazyVals"
@tu lazy val LazyValsModule = requiredModule(LazyValsModuleName)
@tu lazy val LazyValsWaitingState = requiredClass(s"$LazyValsModuleName.Waiting")
@tu lazy val LazyValsControlState = requiredClass(s"$LazyValsModuleName.LazyValControlState")

def addSyntheticSymbolsComments(using Context): Unit =
def add(sym: Symbol, doc: String) = ctx.docCtx.foreach(_.addDocstring(sym, Some(Comment(NoSpan, doc))))

Expand Down
249 changes: 96 additions & 153 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class TreeChecker extends Phase with SymTransformer {
def isAllowed(sym: Symbol): Boolean = sym.is(ConstructorProxy)

val symbolsNotDefined = (decls -- defined - constr.symbol).filterNot(isAllowed)

assert(symbolsNotDefined.isEmpty,
i" $cls tree does not define members: ${symbolsNotDefined.toList}%, %\n" +
i"expected: ${decls.toList}%, %\n" +
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotc/pos-lazy-vals-tests.allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ t6278-synth-def.scala
t6925b.scala
t7011.scala
t8306.scala
zipped.scala
zipped.scala
2 changes: 1 addition & 1 deletion compiler/test/dotc/run-from-tasty.blacklist
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CI only: cannot reduce summonFrom with
sip23-valueof.scala
sip23-valueof.scala
2 changes: 1 addition & 1 deletion compiler/test/dotc/run-lazy-vals-tests.allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ t7406.scala
t8245.scala
unapply.scala
unit-lazy-val.scala
view-iterator-stream.scala
view-iterator-stream.scala
2 changes: 1 addition & 1 deletion compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ i12753
t6138
t6138-2
i12656.scala
trait-static-forwarder
trait-static-forwarder
2 changes: 1 addition & 1 deletion compiler/test/dotc/run-test-recheck.excludes
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ i5976.scala
tagless.scala
safeThrowsStrawman2.scala
t7584.scala
function-arity.scala
function-arity.scala
9 changes: 0 additions & 9 deletions library/src/scala/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,11 @@ object LazyVals {


object Names {
final val controlState = "LazyValControlState"
final val waiting = "Waiting"
final val evaluating = "Evaluating"
final val nullValue = "NullValue"
final val waitingAwaitRelease = "await"
final val waitingRelease = "countDown"
final val state = "STATE"
final val cas = "CAS"
final val objCas = "objCAS"
final val setFlag = "setFlag"
final val wait4Notification = "wait4Notification"
final val get = "get"
final val getOffset = "getOffset"
final val getOffsetStatic = "getOffsetStatic"
final val getStaticFieldOffset = "getStaticFieldOffset"
}
}
11 changes: 0 additions & 11 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@ object MiMaFilters {
val Library: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.MappedAlternative"),

ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getOffsetStatic"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticFieldOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticFieldOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.evaluating"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.nullValue"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.objCas"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waiting"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingAwaitRelease"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.waitingRelease"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$LazyValControlState"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals#Names.controlState"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Evaluating$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NullValue$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),
Expand Down
2 changes: 1 addition & 1 deletion tests/printing/transformed/lazy-vals-legacy.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
object A {
lazy val x: Int = 2
}
}
61 changes: 28 additions & 33 deletions tests/printing/transformed/lazy-vals-new.check
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ package <empty> {
)
private def writeReplace(): Object =
new scala.runtime.ModuleSerializationProxy(classOf[A])
@volatile lazy <static> var x$lzy1: Object = null
@volatile private lazy <static> var x$lzy1: Object = null
lazy def x(): Int =
{
var result: Object = A#x$lzy1
if result.isInstanceOf[Int] then return scala.Int.unbox(result) else
if result.==(scala.runtime.LazyVals.NullValue) then
return scala.Int.unbox(null)
else return scala.Int.unbox(A.x$lzyINIT1())
val result: Object = A#x$lzy1
if result.isInstanceOf[Int] then scala.Int.unbox(result) else
if result.eq(scala.runtime.LazyVals.NullValue) then
scala.Int.unbox(null)
else scala.Int.unbox(A.x$lzyINIT1())
}
private def x$lzyINIT1(): Object =
while <empty> do
{
val current: Object = A#x$lzy1
if current.==(null) then
if current.eq(null) then
if
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0, null,
scala.runtime.LazyVals.Evaluating
Expand All @@ -47,31 +47,29 @@ package <empty> {
try
{
resultNullable = scala.Int.box(2)
if resultNullable.==(null) then
if resultNullable.eq(null) then
result = scala.runtime.LazyVals.NullValue
else result = resultNullable
return resultNullable
()
}
finally
{
if
if
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
scala.runtime.LazyVals.Evaluating
, result).unary_!()
then
{
val lock: scala.runtime.LazyVals.LazyVals$Waiting =
A#x$lzy1.asInstanceOf[
scala.runtime.LazyVals.LazyVals$Waiting
]
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
scala.runtime.LazyVals.Evaluating
, result).unary_!()
then
{
val lock: scala.runtime.LazyVals.LazyVals$Waiting =
A#x$lzy1.asInstanceOf[
scala.runtime.LazyVals.LazyVals$Waiting
]
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0
,
lock, result)
lock.countDown()
}
else ()
()
}
lock
, result)
lock.countDown()
}
else ()
return resultNullable
}
else ()
else
Expand All @@ -80,10 +78,10 @@ package <empty> {
scala.runtime.LazyVals.LazyVals$LazyValControlState
]
then
if current.==(scala.runtime.LazyVals.Evaluating) then
if current.eq(scala.runtime.LazyVals.Evaluating) then
{
scala.runtime.LazyVals.objCAS(classOf[A], A.OFFSET$_m_0,
scala.runtime.LazyVals.Evaluating
current
, new scala.runtime.LazyVals.LazyVals$Waiting())
()
}
Expand All @@ -94,10 +92,7 @@ package <empty> {
current.asInstanceOf[scala.runtime.LazyVals.LazyVals$Waiting].
await
()
else
if current.==(scala.runtime.LazyVals.NullValue) then
return null
else ()
else return null
else return current
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/printing/transformed/lazy-vals-new.flags
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Ylightweight-lazy-vals
-Ylightweight-lazy-vals
2 changes: 1 addition & 1 deletion tests/printing/transformed/lazy-vals-new.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
object A {
lazy val x: Int = 2
}
}
2 changes: 1 addition & 1 deletion tests/run/lazyVals_c3.1.0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class Foo:
@main def Test =
val foo = new Foo
println(foo.x)
println(foo.y)
println(foo.y)

0 comments on commit f62ffd8

Please sign in to comment.