Skip to content

Commit

Permalink
In Scala.js mode, compile all lazy vals as thread-unsafe.
Browse files Browse the repository at this point in the history
Since JS is a single-threaded environment, there is no point going
through all the machinery of thread-safe lazy vals.

This fixes lazy vals for JS, which would previously fail to link
because of the dependency on `Unsafe`, which is not supported in
Scala.js.
  • Loading branch information
sjrd committed Aug 12, 2019
1 parent f0fd5de commit 5e9891e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
if (isField) {
if (sym.isAllOf(SyntheticModule))
transformSyntheticModule(tree)
else if (sym.isThreadUnsafe) {
if (sym.is(Module)) {
else if (sym.isThreadUnsafe || ctx.settings.scalajs.value) {
if (sym.is(Module) && !ctx.settings.scalajs.value) {
ctx.error(em"@threadUnsafe is only supported on lazy vals", sym.sourcePos)
transformMemberDefThreadSafe(tree)
}
Expand Down Expand Up @@ -453,6 +453,3 @@ object LazyVals {
val retry: TermName = "retry".toTermName
}
}



1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ object Build {
val dir = fetchScalaJSSource.value / "test-suite"
(
(dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** "IntTest.scala").get
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/util" ** "Base64Test.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
)
}
Expand Down

0 comments on commit 5e9891e

Please sign in to comment.