Skip to content

Commit 270832c

Browse files
authored
Scala.js: Upgrade to Scala.js 1.18.1. (#22397)
And port the changes that were made to the compiler backend. Most notably, the changes from the following upstream PRs: * scala-js/scala-js#5018 * scala-js/scala-js#5092 * scala-js/scala-js#5090 * scala-js/scala-js#5088 * scala-js/scala-js#5059 * scala-js/scala-js#5074 * scala-js/scala-js#5061
2 parents 8c5b00d + 1b30bdc commit 270832c

File tree

11 files changed

+123
-126
lines changed

11 files changed

+123
-126
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

+82-89
Large diffs are not rendered by default.

compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala

-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ final class JSDefinitions()(using Context) {
179179
def Runtime_createLocalJSClass(using Context) = Runtime_createLocalJSClassR.symbol
180180
@threadUnsafe lazy val Runtime_withContextualJSClassValueR = RuntimePackageClass.requiredMethodRef("withContextualJSClassValue")
181181
def Runtime_withContextualJSClassValue(using Context) = Runtime_withContextualJSClassValueR.symbol
182-
@threadUnsafe lazy val Runtime_linkingInfoR = RuntimePackageClass.requiredMethodRef("linkingInfo")
183-
def Runtime_linkingInfo(using Context) = Runtime_linkingInfoR.symbol
184182
@threadUnsafe lazy val Runtime_dynamicImportR = RuntimePackageClass.requiredMethodRef("dynamicImport")
185183
def Runtime_dynamicImport(using Context) = Runtime_dynamicImportR.symbol
186184

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

+13-15
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,13 @@ object JSEncoding {
135135
def freshLabelName(base: String): LabelName =
136136
freshLabelName(LabelName(base))
137137

138-
def freshLabelIdent(base: String)(implicit pos: ir.Position): js.LabelIdent =
139-
js.LabelIdent(freshLabelName(base))
140-
141138
def labelSymbolName(sym: Symbol)(using Context): LabelName =
142139
labelSymbolNames.getOrElseUpdate(sym, freshLabelName(sym.javaSimpleName))
143140

144-
def getEnclosingReturnLabel()(implicit pos: ir.Position): js.LabelIdent = {
141+
def getEnclosingReturnLabel(): LabelName = {
145142
if (returnLabelName.isEmpty)
146143
returnLabelName = Some(freshLabelName("_return"))
147-
js.LabelIdent(returnLabelName.get)
144+
returnLabelName.get
148145
}
149146

150147
/* If this `LocalNameGenerator` has a `returnLabelName` (often added in the
@@ -155,7 +152,7 @@ object JSEncoding {
155152
case None =>
156153
body
157154
case Some(labelName) =>
158-
js.Labeled(js.LabelIdent(labelName), tpe, body)
155+
js.Labeled(labelName, tpe, body)
159156
}
160157
}
161158
}
@@ -166,10 +163,9 @@ object JSEncoding {
166163

167164
// Encoding methods ----------------------------------------------------------
168165

169-
def encodeLabelSym(sym: Symbol)(
170-
implicit ctx: Context, pos: ir.Position, localNames: LocalNameGenerator): js.LabelIdent = {
166+
def encodeLabelSym(sym: Symbol)(implicit ctx: Context, localNames: LocalNameGenerator): LabelName = {
171167
require(sym.is(Flags.Label), "encodeLabelSym called with non-label symbol: " + sym)
172-
js.LabelIdent(localNames.labelSymbolName(sym))
168+
localNames.labelSymbolName(sym)
173169
}
174170

175171
def encodeFieldSym(sym: Symbol)(implicit ctx: Context, pos: ir.Position): js.FieldIdent =
@@ -248,11 +244,13 @@ object JSEncoding {
248244
private def paramOrResultTypeRef(tpe: Type)(using Context): jstpe.TypeRef =
249245
toParamOrResultTypeRef(toTypeRef(tpe))
250246

251-
def encodeLocalSym(sym: Symbol)(
252-
implicit ctx: Context, pos: ir.Position, localNames: LocalNameGenerator): js.LocalIdent = {
247+
def encodeLocalSym(sym: Symbol)(using Context, ir.Position, LocalNameGenerator): js.LocalIdent =
248+
js.LocalIdent(encodeLocalSymName(sym))
249+
250+
def encodeLocalSymName(sym: Symbol)(using ctx: Context, localNames: LocalNameGenerator): LocalName = {
253251
require(!sym.owner.isClass && sym.isTerm && !sym.is(Flags.Method) && !sym.is(Flags.Module),
254252
"encodeLocalSym called with non-local symbol: " + sym)
255-
js.LocalIdent(localNames.localSymbolName(sym))
253+
localNames.localSymbolName(sym)
256254
}
257255

258256
def encodeClassType(sym: Symbol)(using Context): jstpe.Type = {
@@ -261,7 +259,7 @@ object JSEncoding {
261259
else {
262260
assert(sym != defn.ArrayClass,
263261
"encodeClassType() cannot be called with ArrayClass")
264-
jstpe.ClassType(encodeClassName(sym))
262+
jstpe.ClassType(encodeClassName(sym), nullable = true)
265263
}
266264
}
267265

@@ -324,10 +322,10 @@ object JSEncoding {
324322
else if (sym == defn.NullClass)
325323
jstpe.NullType
326324
else
327-
jstpe.ClassType(typeRef.className)
325+
jstpe.ClassType(typeRef.className, nullable = true)
328326

329327
case typeRef: jstpe.ArrayTypeRef =>
330-
jstpe.ArrayType(typeRef)
328+
jstpe.ArrayType(typeRef, nullable = true)
331329
}
332330
}
333331

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
652652
val superClass = {
653653
val superClassSym = currentClassSym.asClass.superClass
654654
if (superClassSym.isNestedJSClass)
655-
js.VarRef(js.LocalIdent(JSSuperClassParamName))(jstpe.AnyType)
655+
js.VarRef(JSSuperClassParamName)(jstpe.AnyType)
656656
else
657657
js.LoadJSConstructor(encodeClassName(superClassSym))
658658
}
@@ -793,7 +793,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
793793
}
794794

795795
// #15419 If the getter returns void, we must "box" it by returning undefined
796-
if (callGetter.tpe == jstpe.NoType)
796+
if (callGetter.tpe == jstpe.VoidType)
797797
js.Block(callGetter, js.Undefined())
798798
else
799799
callGetter
@@ -837,7 +837,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
837837
}
838838

839839
private def genThrowTypeError(msg: String = "No matching overload")(implicit pos: Position): js.Tree =
840-
js.Throw(js.JSNew(js.JSGlobalRef("TypeError"), js.StringLiteral(msg) :: Nil))
840+
js.UnaryOp(js.UnaryOp.Throw, js.JSNew(js.JSGlobalRef("TypeError"), js.StringLiteral(msg) :: Nil))
841841

842842
abstract class Exported(
843843
val sym: Symbol,
@@ -935,9 +935,9 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
935935
import dotty.tools.sjs.ir.Names
936936

937937
(toIRType(tpe): @unchecked) match {
938-
case jstpe.AnyType => NoTypeTest
938+
case jstpe.AnyType | jstpe.AnyNotNullType => NoTypeTest
939939

940-
case jstpe.NoType => PrimitiveTypeTest(jstpe.UndefType, 0)
940+
case jstpe.VoidType => PrimitiveTypeTest(jstpe.UndefType, 0)
941941
case jstpe.BooleanType => PrimitiveTypeTest(jstpe.BooleanType, 1)
942942
case jstpe.CharType => PrimitiveTypeTest(jstpe.CharType, 2)
943943
case jstpe.ByteType => PrimitiveTypeTest(jstpe.ByteType, 3)
@@ -947,11 +947,11 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
947947
case jstpe.FloatType => PrimitiveTypeTest(jstpe.FloatType, 7)
948948
case jstpe.DoubleType => PrimitiveTypeTest(jstpe.DoubleType, 8)
949949

950-
case jstpe.ClassType(Names.BoxedUnitClass) => PrimitiveTypeTest(jstpe.UndefType, 0)
951-
case jstpe.ClassType(Names.BoxedStringClass) => PrimitiveTypeTest(jstpe.StringType, 9)
952-
case jstpe.ClassType(_) => InstanceOfTypeTest(tpe)
950+
case jstpe.ClassType(Names.BoxedUnitClass, _) => PrimitiveTypeTest(jstpe.UndefType, 0)
951+
case jstpe.ClassType(Names.BoxedStringClass, _) => PrimitiveTypeTest(jstpe.StringType, 9)
952+
case jstpe.ClassType(_, _) => InstanceOfTypeTest(tpe)
953953

954-
case jstpe.ArrayType(_) => InstanceOfTypeTest(tpe)
954+
case jstpe.ArrayType(_, _) => InstanceOfTypeTest(tpe)
955955
}
956956
}
957957
}
@@ -998,7 +998,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
998998

999999
def genArgRef(index: Int)(implicit pos: Position): js.Tree = {
10001000
if (index < minArgc)
1001-
js.VarRef(js.LocalIdent(fixedParamNames(index)))(jstpe.AnyType)
1001+
js.VarRef(fixedParamNames(index))(jstpe.AnyType)
10021002
else
10031003
js.JSSelect(genRestArgRef(), js.IntLiteral(index - minArgc))
10041004
}
@@ -1014,16 +1014,16 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
10141014

10151015
def genRestArgRef()(implicit pos: Position): js.Tree = {
10161016
assert(needsRestParam, s"trying to generate a reference to non-existent rest param at $pos")
1017-
js.VarRef(js.LocalIdent(restParamName))(jstpe.AnyType)
1017+
js.VarRef(restParamName)(jstpe.AnyType)
10181018
}
10191019

10201020
def genAllArgsRefsForForwarder()(implicit pos: Position): List[js.TreeOrJSSpread] = {
10211021
val fixedArgRefs = fixedParamNames.toList.map { paramName =>
1022-
js.VarRef(js.LocalIdent(paramName))(jstpe.AnyType)
1022+
js.VarRef(paramName)(jstpe.AnyType)
10231023
}
10241024

10251025
if (needsRestParam) {
1026-
val restArgRef = js.VarRef(js.LocalIdent(restParamName))(jstpe.AnyType)
1026+
val restArgRef = js.VarRef(restParamName)(jstpe.AnyType)
10271027
fixedArgRefs :+ js.JSSpread(restArgRef)
10281028
} else {
10291029
fixedArgRefs

compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ object JSPrimitives {
3434
inline val CREATE_INNER_JS_CLASS = CONSTRUCTOROF + 1 // runtime.createInnerJSClass
3535
inline val CREATE_LOCAL_JS_CLASS = CREATE_INNER_JS_CLASS + 1 // runtime.createLocalJSClass
3636
inline val WITH_CONTEXTUAL_JS_CLASS_VALUE = CREATE_LOCAL_JS_CLASS + 1 // runtime.withContextualJSClassValue
37-
inline val LINKING_INFO = WITH_CONTEXTUAL_JS_CLASS_VALUE + 1 // runtime.linkingInfo
38-
inline val DYNAMIC_IMPORT = LINKING_INFO + 1 // runtime.dynamicImport
37+
inline val DYNAMIC_IMPORT = WITH_CONTEXTUAL_JS_CLASS_VALUE + 1 // runtime.dynamicImport
3938

4039
inline val STRICT_EQ = DYNAMIC_IMPORT + 1 // js.special.strictEquals
4140
inline val IN = STRICT_EQ + 1 // js.special.in
@@ -122,7 +121,6 @@ class JSPrimitives(ictx: Context) extends DottyPrimitives(ictx) {
122121
addPrimitive(jsdefn.Runtime_createInnerJSClass, CREATE_INNER_JS_CLASS)
123122
addPrimitive(jsdefn.Runtime_createLocalJSClass, CREATE_LOCAL_JS_CLASS)
124123
addPrimitive(jsdefn.Runtime_withContextualJSClassValue, WITH_CONTEXTUAL_JS_CLASS_VALUE)
125-
addPrimitive(jsdefn.Runtime_linkingInfo, LINKING_INFO)
126124
addPrimitive(jsdefn.Runtime_dynamicImport, DYNAMIC_IMPORT)
127125

128126
addPrimitive(jsdefn.Special_strictEquals, STRICT_EQ)

project/Build.scala

+1
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ object Build {
16731673
"productionMode" -> sems.productionMode,
16741674
"esVersion" -> linkerConfig.esFeatures.esVersion.edition,
16751675
"useECMAScript2015Semantics" -> linkerConfig.esFeatures.useECMAScript2015Semantics,
1676+
"isWebAssembly" -> linkerConfig.experimentalUseWebAssembly,
16761677
)
16771678
}.taskValue,
16781679

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
libraryDependencySchemes +=
77
"org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
88

9-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
9+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.18.1")
1010

1111
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
1212

sjs-compiler-tests/test/scala/dotty/tools/dotc/ScalaJSLink.scala

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ object ScalaJSLink:
1717
Semantics.Defaults
1818
.withAsInstanceOfs(CheckedBehavior.Compliant)
1919
.withArrayIndexOutOfBounds(CheckedBehavior.Compliant)
20+
.withArrayStores(CheckedBehavior.Compliant)
21+
.withNegativeArraySizes(CheckedBehavior.Compliant)
22+
.withNullPointers(CheckedBehavior.Compliant)
23+
.withStringIndexOutOfBounds(CheckedBehavior.Compliant)
2024
.withModuleInit(CheckedBehavior.Compliant)
2125
end compliantSemantics
2226

tests/run/exceptions-2.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalajs: --skip
1+
// scalajs: --compliant-semantics
22

33
/*
44
* Try exception handling and finally blocks.

tests/run/exceptions-nest.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalajs: --skip
1+
// scalajs: --compliant-semantics
22

33
object Test extends App {
44

@@ -12,9 +12,12 @@ object Test extends App {
1212
try { println(test8) } catch { case _: Throwable => println("OK") }
1313
println(test9)
1414
println(test10)
15-
println(test11)
15+
portablePrintln(test11)
1616
println(test12)
1717

18+
def portablePrintln(x: Any): Unit =
19+
println(if (x == ()) "()" else x)
20+
1821
def test1 = {
1922
var x = 1
2023
try {

tests/run/t8601d.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// scalajs: --compliant-semantics
2+
13
object Test {
24
def monitor(x: AnyRef): Unit = {x.synchronized(()); ()}
35
def check(x: => Any) = try { x; sys.error("failed to throw NPE") } catch { case _: NullPointerException => }

0 commit comments

Comments
 (0)