Skip to content

Fixing #7140: Implementing new lazy vals scheme #14545

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

Closed
wants to merge 1,248 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1248 commits
Select commit Hold shift + click to select a range
54a9d0e
Change `-scala-release` flag into proper VersionSetting
Kordyjan Nov 15, 2021
7b7498a
Add `since` annotation
Kordyjan Nov 16, 2021
e535c85
Add since annotations to all symbols added in 3.1
Kordyjan Nov 16, 2021
d03c327
Restrict scope of `since` annotation
Kordyjan Nov 16, 2021
68017a3
Check for types with `since` annotation
Kordyjan Nov 17, 2021
6e04111
wip
Kordyjan Nov 22, 2021
99080ed
Finalize work on @since and -scala-release:
prolativ Dec 20, 2021
e99a524
Reworks for forward compat:
prolativ Dec 28, 2021
f88395d
Use a more portable way to download an old compiler for tests
prolativ Dec 29, 2021
3104401
scala-release: Adjust MiMa filters; Revert changes to tasty module
prolativ Dec 29, 2021
b7276ee
-Yscala-release support: extend community build with basic forward-co…
prolativ Jan 12, 2022
91fb1c5
-Yscala-release support: test cats-effect compiled with scala 3.0.2 w…
prolativ Jan 13, 2022
0bf15e7
-Yscala-release support: Improve caching artifacts downloaded for tests
prolativ Jan 14, 2022
f72265d
-Yscala-release support: temporarily enable forward compat community …
prolativ Jan 14, 2022
c7f02ea
-Yscala-release support: checking if classes come from stdlib based o…
prolativ Jan 17, 2022
59444de
-Yscala-release support: checking if classes come from stdlib based o…
prolativ Jan 18, 2022
b3facbd
-Yscala-release support: fix documentation; run extended CI only for …
prolativ Jan 19, 2022
ea48747
Add regression test
nicolasstucki Jan 17, 2022
a67f1df
Fix #7512: Normalize match type arguments
OlivierBlanvillain Jan 12, 2022
b181b8a
Parse splices inside patterns as patterns
adampauls Jan 15, 2022
18309fc
PR comments.
adampauls Jan 17, 2022
70ed013
Allow return in tailrec position
mbovel Dec 23, 2021
3709750
Visit all trees
mbovel Dec 29, 2021
06468db
Add compiletime benchmarks
mbovel Jan 14, 2022
54c033d
Avoid creating set on each call
mbovel Jan 17, 2022
1eedc4a
add -e <expression> eval to command line
philwalk Jan 13, 2022
1edb47c
no source file created ; add more tests
philwalk Jan 16, 2022
2cb2554
Split dotty.tests.filter by comma, to select multiple
dwijnand Jan 14, 2022
170582b
Format compiler crash stack traces
dwijnand Jan 14, 2022
7d6e65b
fixed byte code generation for expr types to include type parameters
gagandeepkalra Jan 20, 2022
a3f04b8
Fix vulnerable dependency
BarkingBad Jan 20, 2022
114811f
Avoid cyclic error in checkNoModuleClash
dwijnand Jan 14, 2022
643b1d1
Extract effectiveOwner
dwijnand Jan 17, 2022
4a24edd
Fix type avoidance in nested Array case
dwijnand Jan 17, 2022
9ac8226
Avoid weird Ranges of TypeBounds??
dwijnand Jan 17, 2022
3ef2f2f
Improve typer traces
dwijnand Jan 14, 2022
529e057
Scala 2.13.8 (was 2.13.6)
SethTisue Jan 12, 2022
d05f093
Don't lift try-catch statements that are already in local functions
KacperFKorban Nov 13, 2021
e362e22
Fix scalatest community-build
KacperFKorban Dec 21, 2021
cfe8654
Fix #12260: Add underscore to match type syntax
OlivierBlanvillain Apr 28, 2021
3405682
Fix #9171: treat _ as _:Any in isMatchTypeShaped
OlivierBlanvillain Sep 22, 2021
7ef5b51
Parse 'case _' as 'Ident(_)'
OlivierBlanvillain May 27, 2021
c809bcb
Printing hack for `case _ =>`
OlivierBlanvillain Aug 3, 2021
a5e41a7
Fix #13223: Disalow ? in match types pats/bodies
OlivierBlanvillain Jul 30, 2021
39c2195
Also disalow unbound wildcard type in pattern expr
OlivierBlanvillain Jul 31, 2021
a938020
Update community build (scodec)
OlivierBlanvillain Aug 3, 2021
36d94f3
Avoid misleading error message
odersky Jan 23, 2022
e24a40e
Extract GADT constraints from wildcard type arguments
dwijnand Dec 18, 2021
b0e0385
Fix test output
nicolasstucki Jan 24, 2022
0f5ca2e
Don't retypecheck erroneous arguments when fixing function
odersky Dec 5, 2021
8585213
Refine condition when to not typecheck again
odersky Dec 5, 2021
b224c4b
Further refine condition when not to typecheck again
odersky Dec 6, 2021
9917672
Disable protoquill
odersky Dec 6, 2021
8813755
Harden `hasInnerErrors` and fix tests
odersky Dec 6, 2021
13e4d05
Revert "Disable protoquill"
odersky Jan 23, 2022
71ea89f
Fix protoquill
nicolasstucki Jan 24, 2022
6855da3
Treat synthetic apply of case class as new expression
liufengyun Jan 17, 2022
9bc38a8
Fix outer selection
liufengyun Jan 17, 2022
23cb950
Fix test: synthetic apply is now transparent
liufengyun Jan 17, 2022
c94d2d6
Lazily use synthetic apply
liufengyun Jan 17, 2022
c12044b
Fix outer for calling instantiate
liufengyun Jan 21, 2022
3436ec7
Add assertion to make sure selection makes sense
liufengyun Jan 21, 2022
06d7e87
Use extension method syntax
liufengyun Jan 24, 2022
0d34788
REPL class loader is context class loader
som-snytt Jan 18, 2022
3aeeba3
Prefer context functions for ReplTests
som-snytt Jan 18, 2022
5d14ab7
Update Scala CLA url
xuwei-k Jan 22, 2022
622310b
Update issue templates
anatoliykmetyuk Jan 25, 2022
5408287
Output other compiler errors
nicolasstucki Jan 24, 2022
176ecf5
Make errors from other compilers simpler to read
nicolasstucki Jan 25, 2022
447ff08
Do not report warnings
nicolasstucki Jan 25, 2022
3607de0
Do not harcode other compile -pagewidth
nicolasstucki Jan 25, 2022
f4758db
Properly report errors
nicolasstucki Jan 25, 2022
b45a421
Show broken source file errors
nicolasstucki Jan 25, 2022
2a92e12
Change error message text from "fully-initialized" to "fully initiali…
Xavientois Feb 2, 2022
101893f
Fix windows CI; use coursier as tests dependency; conditionally enabl…
prolativ Jan 20, 2022
e285014
suppress warning when compiling sbt bridge
SethTisue Jan 21, 2022
30dd394
Decrease DelegatingReporter suppression zone
dwijnand Jan 25, 2022
de3294b
Update wording of uninitialized value error to be grammatically correct.
Xavientois Jan 18, 2022
904a16f
tests: Allow "//scalac: args"
dwijnand Jan 14, 2022
06d8e1a
tests: Read tool args in test files
dwijnand Jan 14, 2022
e620066
Add forward compat tests for macros
nicolasstucki Jan 20, 2022
de12bde
Add backwards compat tests for macros
nicolasstucki Jan 20, 2022
2cdbb55
Add version of compat test that compiles on current version
nicolasstucki Jan 20, 2022
e965114
Disable tests/pos-macros/backwardCompat-3.1
nicolasstucki Jan 20, 2022
4334dca
Remove #14306 test
nicolasstucki Jan 21, 2022
b4ee584
Reverse test naming backward/forward
nicolasstucki Jan 26, 2022
bb225d6
Fix #13855: Add regression test
OlivierBlanvillain Jan 26, 2022
0fe4ded
Avoid unnecessary under-constrained implicit searches
smarter Jan 25, 2022
bf76b96
Fix #14240: Fix off-by-1 when emitting Scala.js IR Positions.
sjrd Jan 21, 2022
7c21ea9
Move elim repeated earlier
odersky Jan 19, 2022
73e0689
Update analyzer plugin
odersky Jan 19, 2022
d4c8765
Fix import in analyzer plugin
odersky Jan 19, 2022
583b712
Trial: New ElimByName phase
odersky Jan 20, 2022
01da866
Install the new ElimByName in place of ByNameClosures
odersky Jan 20, 2022
545f4b7
Specialize byname functions
odersky Jan 20, 2022
610fda2
Fix typos in comment
odersky Jan 20, 2022
fba3dbf
Make isSubArg symmetric again
odersky Jan 20, 2022
50b9927
Reorganize RefChecks tasks
odersky Jan 20, 2022
8dfcf54
Fix "have same type after erasure" check
odersky Jan 21, 2022
8d9ed1c
Change versions after the release of 3.1.1
Kordyjan Jan 26, 2022
4f7327a
Fix chat link in README
KacperFKorban Jan 26, 2022
eee261e
Fix approximating RefinedTypes (n>1)
dwijnand Jan 26, 2022
3ff1fc2
Properly desugar `inline given .. with ..`
nicolasstucki Jan 17, 2022
391c29a
Disallow `transparent inline given .. with ..`
nicolasstucki Jan 18, 2022
6968ee1
Add documentation on inline given instances
nicolasstucki Jan 18, 2022
9280bcf
Expand inline given instance docs
nicolasstucki Jan 18, 2022
dc7f13a
Add example
nicolasstucki Jan 26, 2022
7753832
Parameter untupling is not a conversion of functions
som-snytt Jan 20, 2022
a92007c
Scala2Unpickler: Fix annotation argument handling
smarter Jan 6, 2022
a8c8a8a
Correctly handle context functions in scaladoc
KacperFKorban Jan 27, 2022
fc17123
addresses compile error mentioned in #14332
philwalk Jan 26, 2022
269dae2
remove unused code; eliminate quotes in eval expression
philwalk Jan 27, 2022
c296385
remove unused code, cleanup old-style syntax, add main method to Expr…
philwalk Jan 28, 2022
63c7fa2
Close Files.lines stream
nicolasstucki Jan 28, 2022
2282b1d
Use `Using.resource`
nicolasstucki Jan 28, 2022
37dae0f
Keep language imports around longer
odersky Jan 26, 2022
7da757c
Make import contexts visible in macro transforms
odersky Jan 28, 2022
b7f063d
A version of transformStats that avoids stack overflows
odersky Jan 28, 2022
d1c32f2
Use a single "mapStatements" implementation in three places
odersky Jan 28, 2022
e93f515
Update experimental overview page
odersky Jan 29, 2022
1b4a89d
Reorganize side bar and overview page
odersky Jan 29, 2022
fc885f9
Move explicit-nulls page to experimental section
odersky Jan 29, 2022
c5d2be7
refactor: improve output of -Xshow-phases
ckipp01 Jan 31, 2022
44aae2a
Fix - after cleanup run checkout to back to repo directory
lwronski Feb 1, 2022
8073e52
Rename master branch to main in CI
anatoliykmetyuk Feb 2, 2022
bd6ce70
Rename master branch to main in scaladoc tasks
anatoliykmetyuk Feb 2, 2022
f745fa6
Rename master branch to main in benchmark profiles
anatoliykmetyuk Feb 2, 2022
e281a87
Rename master branch to main in the documentation
anatoliykmetyuk Feb 2, 2022
106b0d8
Show inlined positions with source code
nicolasstucki Nov 25, 2021
a504e15
Keep softness when widening unions
mbovel Feb 1, 2022
7e12ed5
Add special case to init checker to always allow certain methods
Xavientois Feb 2, 2022
7262f10
fix #14393
rssh Feb 1, 2022
064e46d
Update protoquill to latest build
deusaquilus Jan 30, 2022
434fc6c
community build: update stdLib213 to current 2.13.x head
SethTisue Jan 21, 2022
84eb162
Revert "Show inlined positions with source code"
smarter Feb 5, 2022
d020b9f
Scaladoc: Unescaped special characters in Quotes documentation
KacperFKorban Jan 28, 2022
2d8e4a5
Add draft as regression tests
nicolasstucki Feb 4, 2022
bf18a57
Update higher-order-quoted-expressions.scala
nicolasstucki Feb 4, 2022
d39dbcf
Fix invariant quote type holes
dwijnand Feb 7, 2022
a989137
Revert "Revert "Show inlined positions with source code""
nicolasstucki Feb 7, 2022
2316fc3
Check if source exists for inline positions
nicolasstucki Feb 7, 2022
03abded
Re-enable missing cmdTests
nicolasstucki Feb 7, 2022
ebafbef
Comment out debug code
nicolasstucki Feb 8, 2022
43d9e10
Port Scala 2 f-interpolator
som-snytt Mar 20, 2021
be59cfa
Cleanup dispatch to interpolations
som-snytt Aug 26, 2021
96eed43
Brace reduction and remove dead code
som-snytt Nov 23, 2021
9a2e42a
Simplify Conversion
som-snytt Jan 21, 2022
d92e36c
Simplify TypedFormatChecker
som-snytt Jan 22, 2022
c6eee0c
Drop special reporter
som-snytt Jan 22, 2022
6ced168
Improve error position and recovery for bad dollar
som-snytt Jan 23, 2022
84f3190
Pretty print type on f-interpolator, improve caret
som-snytt Jan 25, 2022
2eb3942
Use normal string escaping for f
som-snytt Feb 3, 2022
563241f
Collect error comments
som-snytt Jan 28, 2022
df5f0c0
Add doc page for capture checking.
odersky Feb 8, 2022
aec53c6
Revert eager use of escape in interpolator
som-snytt Feb 8, 2022
e546a7e
fix typos in capture checking doc page
olhotak Feb 9, 2022
2ba981f
Infer parameters of eta applications with vararg parameters
odersky Feb 1, 2022
51279e7
Drop invalid test
odersky Feb 1, 2022
0868c9b
Update compiler/src/dotty/tools/dotc/typer/Typer.scala
odersky Feb 1, 2022
922f9c0
For generic tuples, call Tuples.apply instead of _1/_2/..
dwijnand Jan 19, 2022
e2986a4
Capture checking doc page changes
odersky Feb 9, 2022
214f8b4
Fix more typos in CC doc page
odersky Feb 10, 2022
0ed6f11
Interactive: fix `contextOfPath` for Template
dos65 Jun 10, 2021
90f952f
Add regression test
nicolasstucki Feb 10, 2022
5728066
Issue Tsardom role specification
anatoliykmetyuk Jan 28, 2022
c3c561d
Fix typo
anatoliykmetyuk Jan 31, 2022
5504dbf
Tsardom role spec updated according to the Dotty meeting of 31/01/22
anatoliykmetyuk Jan 31, 2022
e1471b7
Maintenance list added
anatoliykmetyuk Feb 8, 2022
146d50d
Fix typo
anatoliykmetyuk Feb 9, 2022
2d69c2b
Fix typo
anatoliykmetyuk Feb 9, 2022
baa99ed
Make JVM backed maintenance more precise
anatoliykmetyuk Feb 9, 2022
1e66185
Typo fix
anatoliykmetyuk Feb 10, 2022
9426340
Typo fix
anatoliykmetyuk Feb 10, 2022
9b85dc1
Typo fix
anatoliykmetyuk Feb 10, 2022
2d4042c
Reword MAINTENANCE
anatoliykmetyuk Feb 10, 2022
f9a347c
Update MAINTENANCE.md
anatoliykmetyuk Feb 10, 2022
d9ef712
Improve -explain rendering
nicolasstucki Nov 25, 2021
550f14a
Refactor static-site loading
pikinier20 Jan 11, 2022
ae65e83
Change static site directory structure. Adjust Dotty static site dire…
pikinier20 Jan 27, 2022
9e7e8a4
Refactor blog handling
pikinier20 Jan 28, 2022
ba8c55e
Adjust testcases static site to the new structure. Change assets copy…
pikinier20 Jan 28, 2022
8dae666
CRs from review. Add `hidden` property to hide page configured throug…
pikinier20 Feb 8, 2022
338e73d
Change requests: Uniformize property names in YAML config
pikinier20 Feb 10, 2022
0da41f6
Fix explain rendering with Windows EOL
mbovel Feb 11, 2022
b24de89
Fix backend assertion when using an exported enum
dwijnand Feb 11, 2022
09f325d
Alternative fix based on tpd.desugarIdent
odersky Feb 12, 2022
bfb103b
Reposition assertion to respect safe initialization
Xavientois Feb 13, 2022
4d41156
Fix safe-init error in MegaPhase
Xavientois Feb 13, 2022
6d1a990
Scaladoc: Repair links
pikinier20 Feb 14, 2022
303d519
Document that inline methods are not eta expanded
odersky Feb 14, 2022
35e5df6
Avoid using · character
mbovel Feb 11, 2022
17653ec
Fix #11008: Support generic tuples as a valid unapply result
anatoliykmetyuk Feb 8, 2022
ab4c803
Support generic tuples as a valid unapplySeq return type
anatoliykmetyuk Feb 10, 2022
09c2a6f
Add test for the generic tuples as result types of unapplySeq
anatoliykmetyuk Feb 14, 2022
d668013
Supress safe initialization warning in Run class
Xavientois Feb 13, 2022
bddcabe
Change default blog directory to 'blog'
pikinier20 Feb 15, 2022
0ff3a33
Make member filtering case-insensitive in scaladoc
jchyb Feb 8, 2022
42025d6
Add id attributes to anchors of members in Scaladoc searchbar
jchyb Feb 11, 2022
233ffe9
Close searchbar after clicking a result in Scaladoc
jchyb Feb 11, 2022
3f7e688
Fix anchors in Inkuire results in Scaladoc
jchyb Feb 11, 2022
f4eaa2e
Add problematic test
Sporarum Jan 22, 2022
22d86a4
Fix dependent function types rendering
pikinier20 Feb 2, 2022
198f716
Add dependent function type testcase
pikinier20 Feb 15, 2022
fa565b9
Follow renames in content contributors script
pikinier20 Feb 14, 2022
5a1e828
Avoid stale import context during REPL parsing
griggt Feb 15, 2022
e1b2bdd
fix typo in docs example capability checking
bjornregnell Feb 15, 2022
c73ed36
Set zero span for synthetic enum import selector
tgodzik Feb 16, 2022
4a9f226
Propagate unreported features when flushing a reporter
odersky Feb 16, 2022
ba33e98
Fix what -Xlint should have reported if it existed
odersky Feb 16, 2022
7040145
Create errorTermTrees for more missing arguments to Apply nodes.
adampauls Feb 13, 2022
8690b61
Disable type simplify in unpickler
noti0na1 Feb 17, 2022
4b3287f
Rename test file
noti0na1 Feb 17, 2022
09e19d3
Search all source trees for a given span
tgodzik Feb 8, 2022
3aa1438
Tweak `pathTo` comment in NavigateAST
tgodzik Feb 17, 2022
816b1ad
Set zero span for synthetic tuple type
tgodzik Feb 16, 2022
0afcd76
Find inline calls inserted in synthetic members
nicolasstucki Feb 14, 2022
19fb504
Set proper position for ValDefs generated from tuples
tgodzik Feb 18, 2022
79f6ed9
Remove unnecessary newScope in newNormalizedClassSymbol
nicolasstucki Feb 18, 2022
a654314
Don't compute indents when in a string
som-snytt Feb 9, 2022
0217581
Fix space in unsafe nulls
noti0na1 Nov 19, 2021
98a0372
Add patman test
noti0na1 Nov 19, 2021
282d0f3
Fix tests in Ycheck
noti0na1 Nov 19, 2021
b6f6e81
Remove StickyKey
noti0na1 Jan 31, 2022
9cbc1fa
Relax overriding by stripping nulls deeply
noti0na1 Nov 23, 2021
4f346b4
move widenDealias
noti0na1 Nov 23, 2021
49c9b39
Testing new approach
noti0na1 Feb 4, 2022
6ef149c
Add comments
noti0na1 Feb 10, 2022
4d6668a
Fix typos
noti0na1 Feb 10, 2022
a82dcda
Add restriction
noti0na1 Feb 18, 2022
9b58d19
Move relaxed context to a function
noti0na1 Feb 19, 2022
1253563
fix(#11202): explicitly handle TypeTree in syntax highlighting
ckipp01 Feb 19, 2022
b7ea842
Better positions on errorTermTree
adampauls Feb 14, 2022
618d3e7
Thread context through block in transforms correctly and efficiently
odersky Feb 20, 2022
55f9808
Fix "forward reference from self constructor" checking
odersky Feb 20, 2022
105036d
Protected case class constructor -> private apply
dwijnand Jan 13, 2022
60fe22f
Set context when reporting summonInline errors
andrzejressel Feb 16, 2022
0133a3e
fix(parser): make empty catch an incomplete.
ckipp01 Feb 19, 2022
69ede37
Don't skip override tests when overridden is AbsOverride
odersky Feb 21, 2022
5bb036c
Introduce generation config for Scaladoc
pikinier20 Feb 14, 2022
6c8f21d
Add task generating Scala 3 language reference
pikinier20 Feb 15, 2022
bdbc32e
Edit unused imports
som-snytt Feb 22, 2022
d0bd3ba
Remove unused definitions
nicolasstucki Feb 22, 2022
76a1495
Implementing lazy vals
olsdavis Feb 23, 2022
20b5f0f
Reorder to avoid type erasure to Object issue + fix test
olsdavis Mar 12, 2022
6f1a43e
Keeping code for old release compatibility
olsdavis Apr 4, 2022
e4b37ba
Fix conflicts
olsdavis Apr 4, 2022
e9deb26
Merge branch 'main' into master
olsdavis Apr 18, 2022
6337421
fix null type
olsdavis Apr 18, 2022
8aa44a8
Merge branch 'master' of github.com:olsdavis/dotty
olsdavis Apr 18, 2022
ceb27ff
fix nn for union type
olsdavis Apr 18, 2022
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
17 changes: 11 additions & 6 deletions community-build/src/scala/dotty/communitybuild/projects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,19 @@ object projects:
dependencies = () => List(cats, disciplineMunit)
)

lazy val http4s = SbtCommunityProject(
project = "http4s",
sbtTestCommand = "tests/test; server/test; client/test; ember-core/test; ember-server/test; ember-client/test; circe/test",
sbtPublishCommand = "publishLocal",
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ysafe-init"),
dependencies = () => List(cats, catsEffect3, fs2, disciplineMunit, scalacheckEffect)
lazy val specs2 = SbtCommunityProject(
project = "specs2",
sbtTestCommand = "core/testOnly -- exclude ci",
sbtPublishCommand = "core/publishLocal",
dependencies = () => List()
)

lazy val spire = SbtCommunityProject(
project = "spire",
sbtTestCommand = "test",
sbtPublishCommand = "publishLocal",
dependencies = () => List(cats, disciplineMunit)
)
end projects

lazy val forwardCompatMapping = Map[CommunityProject, CommunityProject](
Expand Down
296 changes: 272 additions & 24 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions compiler/test-resources/scripting/scriptPath.sc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
val pathEntries = System.getenv("PATH").split(psep).toList
System.err.printf("sun.java.command: %s\n", sys.props("sun.java.command"))
System.err.printf("first 5 PATH entries:\n%s\n",pathEntries.take(5).mkString("\n"))
printf("script.path: %s\n",path.norm)
assert(path.endsWith("scriptPath.sc"),s"actual path [$path]")
}

extension(s: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class TestBCode extends DottyBytecodeTest {
val clsIn = dir.lookupName("Test.class", directory = false).input
val clsNode = loadClassNode(clsIn)
val method = getMethod(clsNode, "test")
assertEquals(93, instructionsFromMethod(method).size)
assertEquals(122, instructionsFromMethod(method).size)
}
}

Expand Down
58 changes: 58 additions & 0 deletions library/src/scala/runtime/LazyVals.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scala.runtime

import java.lang.reflect.Modifier

/**
* Helper methods used in thread-safe lazy vals.
*/
Expand All @@ -22,6 +24,7 @@ object LazyVals {
val processors = java.lang.Runtime.getRuntime.nn.availableProcessors()
8 * processors * processors
}

private[this] val monitors: Array[Object] =
Array.tabulate(base)(_ => new Object)

Expand All @@ -37,6 +40,41 @@ object LazyVals {

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

/**
* Used to indicate the state of a lazy val that is being
* evaluated and of which other threads await the result.
*/
final class Waiting:
Copy link
Contributor

Choose a reason for hiding this comment

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

All new definitions in this class should be added to

  • project/MiMaFilters.scala
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
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.nullValued"),
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$Evaluating$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NULL$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.Evaluating"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.NULL"),

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be tested with

sbt:scala3> reload;scala3-interfaces/mimaReportBinaryIssues;scala3-library-bootstrapped/mimaReportBinaryIssues

private var done = false

/**
* Wakes up waiting threads. Called on completion of the evaluation
* of lazy val's right-hand side.
*/
def release(): Unit = synchronized {
done = true
notifyAll()
}

/**
* Awaits the completion of the evaluation of lazy val's right-hand side.
*/
def awaitRelease(): Unit = synchronized {
while !done do wait()
}

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

/**
* Used to indicate the state of a lazy val that has been evaluated to
* `null`.
*/
object NULL

final val BITS_PER_LAZY_VAL = 2L

def STATE(cur: Long, ord: Int): Long = {
Expand All @@ -54,6 +92,12 @@ object LazyVals {
unsafe.compareAndSwapLong(t, offset, e, n)
}

def objCAS(t: Object, offset: Long, exp: Object, n: Object): Boolean = {
if (debug)
println(s"objCAS($t, $exp, $n)")
unsafe.compareAndSwapObject(t, offset, exp, n)
}

def setFlag(t: Object, offset: Long, v: Int, ord: Int): Unit = {
if (debug)
println(s"setFlag($t, $offset, $v, $ord)")
Expand Down Expand Up @@ -106,12 +150,26 @@ object LazyVals {
r
}

def getStaticOffset(clz: Class[_], name: String): Long = {
val r = unsafe.staticFieldOffset(clz.getDeclaredField(name))
if (debug)
println(s"getStaticOffset($clz, $name) = $r")
r
}

object Names {
final val waiting = "Waiting"
final val evaluating = "Evaluating"
final val nullValued = "NULL"
final val waitingAwaitRelease = "awaitRelease"
final val waitingRelease = "release"
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 getStaticOffset = "getStaticOffset"
}
}
26 changes: 19 additions & 7 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ object MiMaFilters {
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#SymbolMethods.termRef"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeTreeModule.ref"),

// Experimental `MainAnnotation` APIs. Can be added in 3.3.0 or later.
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$Command"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$CommandInfo"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$ParameterInfo"),
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.MainAnnotation$ParameterAnnotation"),
// Private to the compiler - needed for forward binary compatibility
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.since"),

ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.getStaticOffset"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.LazyVals.objCAS"),
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.nullValued"),
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$Evaluating$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$NULL$"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.LazyVals$Waiting"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.Evaluating"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.LazyVals.NULL")
)
}
4 changes: 4 additions & 0 deletions tests/init/neg/promotion-loop.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
-- Error: tests/init/neg/promotion-loop.scala:16:10 --------------------------------------------------------------------
16 | println(b) // error
| ^
<<<<<<< HEAD
| Cannot prove that the value is fully-initialized. Only initialized values may be used as arguments.
=======
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
>>>>>>> 91c03b1f7835d574290eba1ecf236e0f59fc2bf0
|
| The unsafe promotion may cause the following problem:
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
4 changes: 2 additions & 2 deletions tests/init/neg/t3273.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Error: tests/init/neg/t3273.scala:4:42 ------------------------------------------------------------------------------
4 | val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error
| ^^^^^^^^^^^^^^^
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
| Cannot prove that the value is fully-initialized. Only initialized values may be used as arguments.
|
| The unsafe promotion may cause the following problem:
| Access non-initialized value num1. Calling trace:
Expand All @@ -10,7 +10,7 @@
-- Error: tests/init/neg/t3273.scala:5:61 ------------------------------------------------------------------------------
5 | val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
| Cannot prove that the value is fully-initialized. Only initialized values may be used as arguments.
|
| The unsafe promotion may cause the following problem:
| Access non-initialized value num2. Calling trace:
Expand Down
4 changes: 4 additions & 0 deletions tests/run/lazyVals_c3.0.0.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
computing x
x
computing y
y
13 changes: 13 additions & 0 deletions tests/run/lazyVals_c3.0.0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Compiled with 3.0.0 and run with current compiler
class Foo:
lazy val x =
println("computing x")
"x"
lazy val y =
println("computing y")
"y"

@main def Test =
val foo = new Foo
println(foo.x)
println(foo.y)
4 changes: 4 additions & 0 deletions tests/run/lazyVals_c3.1.0.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
computing x
x
computing y
y
13 changes: 13 additions & 0 deletions tests/run/lazyVals_c3.1.0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Compiled with 3.1.0 and run with current compiler
class Foo:
lazy val x =
println("computing x")
"x"
lazy val y =
println("computing y")
"y"

@main def Test =
val foo = new Foo
println(foo.x)
println(foo.y)