Skip to content

Commit

Permalink
Stabilize new lazy vals (#16614)
Browse files Browse the repository at this point in the history
Resolve #16555
  • Loading branch information
szymon-rd authored Jan 9, 2023
2 parents 7337b6f + cd5e644 commit f56089b
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 38 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ private sealed trait YSettings:
val YshowTreeIds: Setting[Boolean] = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
val YfromTastyIgnoreList: Setting[List[String]] = MultiStringSetting("-Yfrom-tasty-ignore-list", "file", "List of `tasty` files in jar files that will not be loaded when using -from-tasty")
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features")
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals")

val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")
val YprofileDestination: Setting[String] = StringSetting("-Yprofile-destination", "file", "Where to send profiling output - specify a file, default is to the console.", "")
Expand All @@ -382,7 +383,6 @@ private sealed trait YSettings:
val YrecheckTest: Setting[Boolean] = BooleanSetting("-Yrecheck-test", "Run basic rechecking (internal test only)")
val YccDebug: Setting[Boolean] = BooleanSetting("-Ycc-debug", "Used in conjunction with captureChecking language import, debug info for captured references")
val YccNoAbbrev: Setting[Boolean] = BooleanSetting("-Ycc-no-abbrev", "Used in conjunction with captureChecking language import, suppress type abbreviations")
val YlightweightLazyVals: Setting[Boolean] = BooleanSetting("-Ylightweight-lazy-vals", "Use experimental lightweight implementation of lazy vals")

/** Area-specific debug output */
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {

def transformMemberDefThreadSafe(x: ValOrDefDef)(using Context): Thicket = {
assert(!(x.symbol is Mutable))
if ctx.settings.YlightweightLazyVals.value then
transformMemberDefThreadSafeNew(x)
else
if ctx.settings.YlegacyLazyVals.value then
transformMemberDefThreadSafeLegacy(x)
else
transformMemberDefThreadSafeNew(x)
}

def transformMemberDefThreadSafeNew(x: ValOrDefDef)(using Context): Thicket = {
Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotc/run-lazy-vals-tests.allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ null-lazy-val.scala
patmatch-classtag.scala
priorityQueue.scala
serialization-new-legacy.scala
serialization-new.scala
singletons.scala
statics.scala
stream_flatmap_odds.scala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class DottyBytecodeTests extends DottyBytecodeTest {
val clsIn = dir.lookupName("Test.class", directory = false).input
val clsNode = loadClassNode(clsIn)
val method = getMethod(clsNode, "test")
assertEquals(88, instructionsFromMethod(method).size)
assertEquals(23, instructionsFromMethod(method).size)
}
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CompilationTests {
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-language:experimental.captureChecking")),
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),
// Run tests for experimental lightweight lazy vals
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylightweight-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
// Run tests for legacy lazy vals
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/pos-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")),
compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")),
Expand Down Expand Up @@ -212,9 +212,9 @@ class CompilationTests {
compileDir("tests/run-custom-args/Xmacro-settings/compileTimeEnv", defaultOptions.and("-Xmacro-settings:a,b=1,c.b.a=x.y.z=1,myLogger.level=INFO")),
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-language:experimental.captureChecking")),
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init"), FileFilter.exclude("serialization-new.scala")),
// Run tests for experimental lightweight lazy vals and stable lazy vals.
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init", "-Ylightweight-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)),
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init")),
// Run tests for legacy lazy vals.
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)),
).checkRuns()
}

Expand Down
6 changes: 0 additions & 6 deletions library/src/scala/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,24 @@ object LazyVals {

/* ------------- Start of public API ------------- */

@experimental
sealed trait LazyValControlState

/**
* Used to indicate the state of a lazy val that is being
* evaluated and of which other threads await the result.
*/
@experimental
final class Waiting extends CountDownLatch(1) with LazyValControlState

/**
* Used to indicate the state of a lazy val that is currently being
* evaluated with no other thread awaiting its result.
*/
@experimental
object Evaluating extends LazyValControlState

/**
* Used to indicate the state of a lazy val that has been evaluated to
* `null`.
*/
@experimental
object NullValue extends LazyValControlState

final val BITS_PER_LAZY_VAL = 2L
Expand All @@ -86,7 +82,6 @@ object LazyVals {
unsafe.compareAndSwapLong(t, offset, e, n)
}

@experimental
def objCAS(t: Object, offset: Long, exp: Object, n: Object): Boolean = {
if (debug)
println(s"objCAS($t, $exp, $n)")
Expand Down Expand Up @@ -147,7 +142,6 @@ object LazyVals {
r
}

@experimental
def getStaticFieldOffset(field: java.lang.reflect.Field): Long = {
@nowarn
val r = unsafe.staticFieldOffset(field)
Expand Down
9 changes: 0 additions & 9 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ object MiMaFilters {
val Library: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.MappedAlternative"),

ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticFieldOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$LazyValControlState"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Evaluating$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NullValue$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.Evaluating"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.NullValue"),

ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language#experimental.into"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$experimental$into$"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language#experimental.pureFunctions"),
Expand Down
1 change: 1 addition & 0 deletions tests/printing/transformed/lazy-vals-legacy.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Ylegacy-lazy-vals
1 change: 0 additions & 1 deletion tests/printing/transformed/lazy-vals-new.flags

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ val experimentalDefinitionInLibrary = Set(
"scala.quoted.Quotes.reflectModule.SymbolModule.newClass",
"scala.quoted.Quotes.reflectModule.SymbolModule.freshName",
"scala.quoted.Quotes.reflectModule.SymbolMethods.info",

// New APIs: Lightweight lazy vals. Can be stabilized in 3.3.0
"scala.runtime.LazyVals$.Evaluating",
"scala.runtime.LazyVals$.Evaluating$",
"scala.runtime.LazyVals$.LazyValControlState",
"scala.runtime.LazyVals$.NullValue",
"scala.runtime.LazyVals$.NullValue$",
"scala.runtime.LazyVals$.Waiting",
"scala.runtime.LazyVals$.getStaticFieldOffset",
"scala.runtime.LazyVals$.objCAS"
)


Expand Down

0 comments on commit f56089b

Please sign in to comment.