8000 Add a compiler option not to optimize Scala varargs as JS arrays. · scala-js/scala-js@3128869 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3128869

Browse files
committed
Add a compiler option not to optimize Scala varargs as JS arrays.
We use it in the scalalib, so that we do not generate references to `toScalaVarArgs`, which uses custom collections from the Scala.js library.
1 parent 9017d14 commit 3128869

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

compiler/src/main/scala/org/scalajs/nscplugin/GenJSCode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5487,7 +5487,7 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
54875487
* the extension to `false`.
54885488
*/
54895489
for ((arg, wasRepeated) <- args.zipAll(wereRepeated, EmptyTree, false)) yield {
5490-
if (wasRepeated) {
5490+
if (wasRepeated && !scalaJSOpts.avoidOptimizingScalaVarargsAsJSArray) {
54915491
tryGenRepeatedParamAsJSArray(arg, handleNil = false).fold {
54925492
genExpr(arg)
54935493
} { genArgs =>

compiler/src/main/scala/org/scalajs/nscplugin/ScalaJSOptions.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ trait ScalaJSOptions {
2626
* If false, bad calls to classOf will cause an error. */
2727
def fixClassOf: Boolean
2828

29+
/** Should we avoid optimizing Scala varargs as js.Array-based seqs?
30+
*
31+
* This is normally only used when compiling the scalalib.
32+
*/
33+
def avoidOptimizingScalaVarargsAsJSArray: Boolean
34+
2935
/** Should static forwarders be emitted for non-top-level objects.
3036
*
3137
* Scala/JVM does not do that. Since Scala.js 1.2.0, we do not do it by

compiler/src/main/scala/org/scalajs/nscplugin/ScalaJSPlugin.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ScalaJSPlugin(val global: Global) extends NscPlugin {
5555
object scalaJSOpts extends ScalaJSOptions {
5656
import ScalaJSOptions.URIMap
5757
var fixClassOf: Boolean = false
58+
var avoidOptimizingScalaVarargsAsJSArray: Boolean = false
5859
var genStaticForwardersForNonTopLevelObjects: Boolean = false
5960
lazy val sourceURIMaps: List[URIMap] = {
6061
if (_sourceURIMaps.nonEmpty)
@@ -109,6 +110,8 @@ class ScalaJSPlugin(val global: Global) extends NscPlugin {
109110
for (option <- options) {
110111
if (option == "fixClassOf") {
111112
fixClassOf = true
113+
} else if (option == "avoidOptimizingScalaVarargsAsJSArray") {
114+
avoidOptimizingScalaVarargsAsJSArray = true
112115
} else if (option == "genStaticForwardersForNonTopLevelObjects") {
113116
genStaticForwardersForNonTopLevelObjects = true
114117
} else if (option == "nowarnGlobalExecutionContext") {

project/Build.scala

Lines changed: 7 additions & 5 deletions
< 7009 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,8 @@ object Build {
14011401

14021402
// Tell the plugin to hack-fix bad classOf trees
14031403
scalacOptions ++= scalaJSCompilerOption("fixClassOf"),
1404+
// And not to optimize Scala varargs as js.Array-based seqs
1405+
scalacOptions ++= scalaJSCompilerOption("avoidOptimizingScalaVarargsAsJSArray"),
14041406

14051407
libraryDependencies +=
14061408
"org.scala-lang" % "scala-library" % scalaVersion.value classifier "sources",
@@ -1782,16 +1784,16 @@ object Build {
17821784
scalaVersion.value match {
17831785
case Default2_12ScalaVersion =>
17841786
Some(ExpectedSizes(
1785-
fastLink = 772000 to 773000,
1786-
fullLink = 145000 to 146000,
1787-
fastLinkGz = 91000 to 92000,
1787+
fastLink = 766000 to 767000,
1788+
fullLink = 144000 to 145000,
1789+
fastLinkGz = 90000 to 91000,
17881790
fullLinkGz = 35000 to 36000,
17891791
))
17901792

17911793
case Default2_13ScalaVersion =>
17921794
Some(ExpectedSizes(
1793-
fastLink = 456000 to 457000,
1794-
fullLink = 97000 to 98000,
1795+
fastLink = 458000 to 459000,
1796+
fullLink = 98000 to 99000,
17951797
fastLinkGz = 59000 to 60000,
17961798
fullLinkGz = 26000 to 27000,
17971799
))

0 commit comments

Comments
 (0)
0