From 906a55f2ba24a073f59e9e019fb294f993b057ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Mon, 12 Aug 2019 10:49:56 +0200 Subject: [PATCH 1/4] Fix JS code gen for Byte, Short and Char literals. They were all erroneously translated to `IntLiteral`s. --- compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index ae5c823a8e0b..e21983e5af7b 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -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) From 8397cafa4e791fe947548e0874817b08beb283d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Mon, 12 Aug 2019 10:57:50 +0200 Subject: [PATCH 2/4] Fix JS codegen for closures calling static methods. They had better pass the actual parameters, in addition to the captures. --- compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index e21983e5af7b..5677d10c6dba 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -2162,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, From f0fd5de6d06904107c2908c8175156f78ee0a85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Mon, 12 Aug 2019 11:04:04 +0200 Subject: [PATCH 3/4] Fix `toIRType` for Chars, Bytes and Shorts. They were all erroneously translated to `jstpe.IntType`. --- .../src/dotty/tools/backend/sjs/JSEncoding.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSEncoding.scala b/compiler/src/dotty/tools/backend/sjs/JSEncoding.scala index d761543fa1cf..67198cfdf7ea 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSEncoding.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSEncoding.scala @@ -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 From 5e9891ec8e7a6516b50dac1209641214438cf00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Mon, 12 Aug 2019 11:04:49 +0200 Subject: [PATCH 4/4] In Scala.js mode, compile all lazy vals as thread-unsafe. 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. --- compiler/src/dotty/tools/dotc/transform/LazyVals.scala | 7 ++----- project/Build.scala | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index ea3b1e02f3cd..e0f432e1ebc5 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -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) } @@ -453,6 +453,3 @@ object LazyVals { val retry: TermName = "retry".toTermName } } - - - diff --git a/project/Build.scala b/project/Build.scala index a73da9de6784..11985ef9ca4d 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -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 ) }