From 134c006856ccc88b12fdb269b1ff32eccc656290 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Wed, 4 Jan 2023 13:36:35 +0100 Subject: [PATCH 1/6] Set new lazy vals impl as default --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 2 +- compiler/src/dotty/tools/dotc/transform/LazyVals.scala | 6 +++--- compiler/test/dotty/tools/dotc/CompilationTests.scala | 4 ++-- tests/printing/transformed/lazy-vals-legacy.flags | 1 + tests/printing/transformed/lazy-vals-new.flags | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 tests/printing/transformed/lazy-vals-legacy.flags delete mode 100644 tests/printing/transformed/lazy-vals-new.flags diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 64b8a91e9096..00bd0d168158 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -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.", "") @@ -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.") diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index c428adbaebda..0a9a2b1214b2 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -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 = { diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 20daa2d24406..49fe8f680ec8 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -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)), 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")), @@ -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() } diff --git a/tests/printing/transformed/lazy-vals-legacy.flags b/tests/printing/transformed/lazy-vals-legacy.flags new file mode 100644 index 000000000000..e785b42309f3 --- /dev/null +++ b/tests/printing/transformed/lazy-vals-legacy.flags @@ -0,0 +1 @@ +-Ylegacy-lazy-vals \ No newline at end of file diff --git a/tests/printing/transformed/lazy-vals-new.flags b/tests/printing/transformed/lazy-vals-new.flags deleted file mode 100644 index 51b77a4da919..000000000000 --- a/tests/printing/transformed/lazy-vals-new.flags +++ /dev/null @@ -1 +0,0 @@ --Ylightweight-lazy-vals From c8402b83c5d3838725866299a4a0969cbf592ac0 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Wed, 4 Jan 2023 13:38:44 +0100 Subject: [PATCH 2/6] Stabilize experimental runtime functions --- library/src/scala/runtime/LazyVals.scala | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/library/src/scala/runtime/LazyVals.scala b/library/src/scala/runtime/LazyVals.scala index 98f67e804e3c..2da8a9438497 100644 --- a/library/src/scala/runtime/LazyVals.scala +++ b/library/src/scala/runtime/LazyVals.scala @@ -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 - /** - * 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 @@ -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)") @@ -147,7 +138,6 @@ object LazyVals { r } - @experimental def getStaticFieldOffset(field: java.lang.reflect.Field): Long = { @nowarn val r = unsafe.staticFieldOffset(field) From 5863562b84ee7c91149aa3e22de7cf511ea868ab Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Wed, 4 Jan 2023 14:59:22 +0100 Subject: [PATCH 3/6] Remove mima filter exclusions and stdlibExpDefs --- project/MiMaFilters.scala | 9 --------- .../stdlibExperimentalDefinitions.scala | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/project/MiMaFilters.scala b/project/MiMaFilters.scala index cceffaf53279..ed1d11c66fd8 100644 --- a/project/MiMaFilters.scala +++ b/project/MiMaFilters.scala @@ -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"), diff --git a/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala b/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala index 422d88efc095..ca379c97141b 100644 --- a/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala +++ b/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala @@ -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" ) From b0690ca5bc4cfa599bec430f482bedf55dcd8483 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Thu, 5 Jan 2023 12:34:15 +0100 Subject: [PATCH 4/6] Review fixes --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 4 ++-- library/src/scala/runtime/LazyVals.scala | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 49fe8f680ec8..d28d4b7f909c 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -44,7 +44,7 @@ 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 + // 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")), @@ -212,7 +212,7 @@ class CompilationTests { 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. + // Run tests for legacy lazy vals. compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.runLazyValsAllowlist)), ).checkRuns() } diff --git a/library/src/scala/runtime/LazyVals.scala b/library/src/scala/runtime/LazyVals.scala index 2da8a9438497..5d1e8e74b89d 100644 --- a/library/src/scala/runtime/LazyVals.scala +++ b/library/src/scala/runtime/LazyVals.scala @@ -59,6 +59,10 @@ object LazyVals { */ object Evaluating extends LazyValControlState + /** + * Used to indicate the state of a lazy val that has been evaluated to + * `null`. + */ object NullValue extends LazyValControlState final val BITS_PER_LAZY_VAL = 2L From c27fe5d24fb7eb8626738e7b5c2601e28fd86d48 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Mon, 9 Jan 2023 13:36:40 +0100 Subject: [PATCH 5/6] Fix tests after stabilizing lazy vals --- compiler/test/dotc/run-lazy-vals-tests.allowlist | 1 - compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala | 2 +- compiler/test/dotty/tools/dotc/CompilationTests.scala | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/test/dotc/run-lazy-vals-tests.allowlist b/compiler/test/dotc/run-lazy-vals-tests.allowlist index 98973dc2893d..361795bcc5fd 100644 --- a/compiler/test/dotc/run-lazy-vals-tests.allowlist +++ b/compiler/test/dotc/run-lazy-vals-tests.allowlist @@ -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 diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala index 2c618ea91e96..71bf530fcda5 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala @@ -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) } } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index d28d4b7f909c..f1042be4839d 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -211,7 +211,7 @@ 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")), + 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() From cd5e644b3c900c404956669c06480b6eb95c7939 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Mon, 9 Jan 2023 15:30:44 +0100 Subject: [PATCH 6/6] Update Scala Parallel Collection for new lazy vals --- community-build/community-projects/scala-parallel-collections | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community-build/community-projects/scala-parallel-collections b/community-build/community-projects/scala-parallel-collections index a6bd648bb188..7d0e41ae4d09 160000 --- a/community-build/community-projects/scala-parallel-collections +++ b/community-build/community-projects/scala-parallel-collections @@ -1 +1 @@ -Subproject commit a6bd648bb188a65ab36be07e956e52fe25f64d67 +Subproject commit 7d0e41ae4d09e1ddf063651e377921ec493fc5bf