Skip to content

Commit 09775c5

Browse files
committed
Experimental & Tests
1 parent 4629ec1 commit 09775c5

File tree

155 files changed

+768
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+768
-18
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ private sealed trait YSettings:
331331
val Ycc: Setting[Boolean] = BooleanSetting("-Ycc", "Check captured references (warning: extremely experimental and unstable)")
332332
val YccDebug: Setting[Boolean] = BooleanSetting("-Ycc-debug", "Used in conjunction with -Ycc, debug info for captured references")
333333
val YccNoAbbrev: Setting[Boolean] = BooleanSetting("-Ycc-no-abbrev", "Used in conjunction with -Ycc, suppress type abbreviations")
334+
val YlightweightLazyVals: Setting[Boolean] = BooleanSetting("-Ylightweight-lazy-vals", "Use experimental lightweight implementation of lazy vals")
334335

335336
/** Area-specific debug output */
336337
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ package dotty.tools.dotc
22
package transform
33

44
import java.util.IdentityHashMap
5-
65
import ast.tpd
76
import core.Annotations.Annotation
87
import core.Constants.Constant
9-
import core.Contexts._
10-
import core.Decorators._
8+
import core.Contexts.*
9+
import core.Decorators.*
1110
import core.DenotTransformers.IdentityDenotTransformer
12-
import core.Flags._
13-
import core.NameKinds.{LazyBitMapName, LazyLocalInitName, LazyLocalName, ExpandedName}
11+
import core.Flags.*
12+
import core.NameKinds.{ExpandedName, LazyBitMapName, LazyLocalInitName, LazyLocalName}
1413
import core.StdNames.nme
15-
import core.Symbols._
16-
import core.Types._
14+
import core.Symbols.*
15+
import core.Types.*
1716
import core.{Names, StdNames}
17+
import dotty.tools.dotc.config.Feature
1818
import transform.MegaPhase.MiniPhase
19-
import transform.SymUtils._
19+
import transform.SymUtils.*
20+
2021
import scala.collection.mutable
2122

2223
class LazyVals extends MiniPhase with IdentityDenotTransformer {
@@ -59,9 +60,6 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
5960
else nullables.toList
6061
}
6162

62-
private inline def isLegacyLazyVals(using ctx: Context): Boolean =
63-
ctx.settings.XlegacyLazyVals.value
64-
6563
private def needsBoxing(tp: Type)(using Context): Boolean = tp != NoType && tp != defn.UnitType && tp.classSymbol.isPrimitiveValueClass
6664

6765
private def boxIfCan(tp: Type)(using Context): Type =
@@ -120,7 +118,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
120118
*/
121119
override def transformTemplate(template: Template)(using Context): Tree = {
122120
val cls = ctx.owner.asClass
123-
(if isLegacyLazyVals then oldAppendOffsetDefs else appendOffsetDefs).get(cls) match {
121+
(if !ctx.settings.YlightweightLazyVals.value then oldAppendOffsetDefs else appendOffsetDefs).get(cls) match {
124122
case None => template
125123
case Some(data) =>
126124
data.defs.foreach(_.symbol.addAnnotation(Annotation(defn.ScalaStaticAnnot)))
@@ -496,10 +494,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
496494

497495
def transformMemberDefThreadSafe(x: ValOrDefDef)(using Context): Thicket = {
498496
assert(!(x.symbol is Mutable))
499-
if isLegacyLazyVals then
500-
transformMemberDefThreadSafeLegacy(x)
501-
else
497+
if ctx.settings.YlightweightLazyVals.value then
502498
transformMemberDefThreadSafeNew(x)
499+
else
500+
transformMemberDefThreadSafeLegacy(x)
503501
}
504502

505503
def transformMemberDefThreadSafeNew(x: ValOrDefDef)(using Context): Thicket = {

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ i4176-gadt.scala
8686
i13974a.scala
8787

8888
java-inherited-type1
89+
90+
lazy-vals-all

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ t6138
4444
t6138-2
4545
i12656.scala
4646
trait-static-forwarder
47+
lazy-vals-all

compiler/test/dotc/run-test-recheck.excludes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ tagless.scala
1111
safeThrowsStrawman2.scala
1212
t7584.scala
1313
function-arity.scala
14+
lazy-vals-all

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class CompilationTests {
4242
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
4343
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-Ycc")),
4444
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
45-
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),
45+
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init"), FileFilter.exclude("lazy-vals-all")),
46+
// Run tests for experimental lightweight lazy vals and stable lazy vals
47+
compileFilesInDir("tests/pos/lazy-vals-all", defaultOptions.and("-Ysafe-init", "-Ylightweight-lazy-vals")),
48+
compileFilesInDir("tests/pos/lazy-vals-all", defaultOptions.and("-Ysafe-init")),
4649
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
4750
compileFilesInDir("tests/pos-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")),
4851
compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")),
@@ -215,7 +218,10 @@ class CompilationTests {
215218
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")),
216219
compileFilesInDir("tests/run-custom-args/captures", allowDeepSubtypes.and("-Ycc")),
217220
compileFilesInDir("tests/run-deep-subtype", allowDeepSubtypes),
218-
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init"))
221+
compileFilesInDir("tests/run", defaultOptions.and("-Ysafe-init"), FileFilter.exclude("lazy-vals-all")),
222+
// Run tests for experimental lightweight lazy vals and stable lazy vals. serialization-new-legacy is kept to check all cases aside from not working transient (I removed the test that was not testing it)
223+
compileFilesInDir("tests/run/lazy-vals-all", defaultOptions.and("-Ysafe-init", "-Ylightweight-lazy-vals"), FileFilter.exclude("serialization-new-legacy.scala")),
224+
compileFilesInDir("tests/run/lazy-vals-all", defaultOptions.and("-Ysafe-init"), FileFilter.exclude("serialization-new.scala"))
219225
).checkRuns()
220226
}
221227

library/src/scala/runtime/LazyVals.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,28 @@ object LazyVals {
4343

4444
/* ------------- Start of public API ------------- */
4545

46+
@experimental
4647
sealed trait LazyValControlState
4748

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

5456
/**
5557
* Used to indicate the state of a lazy val that is currently being
5658
* evaluated with no other thread awaiting its result.
5759
*/
60+
@experimental
5861
object Evaluating extends LazyValControlState
5962

6063
/**
6164
* Used to indicate the state of a lazy val that has been evaluated to
6265
* `null`.
6366
*/
67+
@experimental
6468
object NullValue extends LazyValControlState
6569

6670
final val BITS_PER_LAZY_VAL = 2L
@@ -80,6 +84,7 @@ object LazyVals {
8084
unsafe.compareAndSwapLong(t, offset, e, n)
8185
}
8286

87+
@experimental
8388
def objCAS(t: Object, offset: Long, exp: Object, n: Object): Boolean = {
8489
if (debug)
8590
println(s"objCAS($t, $exp, $n)")
@@ -140,6 +145,7 @@ object LazyVals {
140145
r
141146
}
142147

148+
@experimental
143149
def getStaticFieldOffset(field: java.lang.reflect.Field): Long = {
144150
@nowarn
145151
val r = unsafe.staticFieldOffset(field)
File renamed without changes.

0 commit comments

Comments
 (0)