Skip to content
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

Stabilize new lazy vals #16614

Merged
merged 6 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -314,6 +314,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 @@ -331,7 +332,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
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CompilationTests {
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)),
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the comment above.
Also would we now want to run all the pos and run tests instead of just the ones from the lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that no, we still want to run these tests, but now for legacy instead of the new lazy vals. New lazy vals will be now tested in standard pos and run tests. But the comment should be updated ofc.

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 @@ -213,7 +213,7 @@ class CompilationTests {
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", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)),
).checkRuns()
}

Expand Down
10 changes: 0 additions & 10 deletions library/src/scala/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,20 @@ 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

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't the comment supposed to stay?

* 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 +78,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 +138,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need that? I thought .flag files in tests are deprecated and vulpix doesn't even take them into consideration

Copy link
Contributor Author

@szymon-rd szymon-rd Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work, the generated code differs. Mainly because the previous PR on lazy vals implemented .flag files for printing tests 😄 Is it the direction we are taking - to deprecate .flag files?

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