Skip to content

In Scala.js mode, compile all lazy vals as thread-unsafe. #7026

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

Merged
merged 4 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,13 @@ class JSCodeGen()(implicit ctx: Context) {
js.Skip()
case BooleanTag =>
js.BooleanLiteral(value.booleanValue)
case ByteTag | ShortTag | CharTag | IntTag =>
case ByteTag =>
js.ByteLiteral(value.byteValue)
case ShortTag =>
js.ShortLiteral(value.shortValue)
case CharTag =>
js.CharLiteral(value.charValue)
case IntTag =>
js.IntLiteral(value.intValue)
case LongTag =>
js.LongLiteral(value.longValue)
Expand Down Expand Up @@ -2156,7 +2162,7 @@ class JSCodeGen()(implicit ctx: Context) {

val genBody = {
val call = if (isStaticCall) {
genApplyStatic(sym, formalCaptures.map(_.ref))
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
} else {
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
genApplyMethodMaybeStatically(thisCaptureRef, sym,
Expand Down
14 changes: 11 additions & 3 deletions compiler/src/dotty/tools/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,24 @@ object JSEncoding {
if (sym.asClass.isPrimitiveValueClass) {
if (sym == defn.BooleanClass)
jstpe.BooleanType
else if (sym == defn.CharClass)
jstpe.CharType
else if (sym == defn.ByteClass)
jstpe.ByteType
else if (sym == defn.ShortClass)
jstpe.ShortType
else if (sym == defn.IntClass)
jstpe.IntType
else if (sym == defn.LongClass)
jstpe.LongType
else if (sym == defn.FloatClass)
jstpe.FloatType
else if (sym == defn.DoubleClass)
jstpe.DoubleType
else if (sym == defn.LongClass)
jstpe.LongType
else if (sym == defn.UnitClass)
jstpe.NoType
else
jstpe.IntType
throw new AssertionError(s"unknown primitive value class $sym")
} else {
if (sym == defn.ObjectClass || isJSType(sym))
jstpe.AnyType
Expand Down
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