scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Crash while compiling ScalaJS #20255

Open cornim opened 6 months ago

cornim commented 6 months ago

Compiler version

3.3.1

Minimized code

package scalajs

import java.nio.ByteBuffer
import org.scalajs.dom
import org.scalajs.dom.{Blob, FormData}

import scala.concurrent.{Future, Promise}
import scala.language.implicitConversions
import scala.scalajs.js
import scala.scalajs.js.typedarray.ArrayBufferView
import scala.scalajs.js.typedarray.TypedArrayBufferOps._

/** Wraps an XMLHttpRequest to provide an easy one-line way of making an Ajax call, returning a Future. */
object Ajax {

  /** Supported data formats for Ajax are implicitly converted to InputData */
  @js.native
  sealed trait InputData extends js.Any

  object InputData {
    implicit def str2ajax(s: String): InputData = s.asInstanceOf[InputData]

    implicit def arrayBufferView2ajax(b: ArrayBufferView): InputData =
      b.asInstanceOf[InputData]

    implicit def blob2ajax(b: Blob): InputData = b.asInstanceOf[InputData]

    implicit def formdata2ajax(b: FormData): InputData =
      b.asInstanceOf[InputData]

    implicit def byteBuffer2ajax(data: ByteBuffer): InputData = {
      if (data.hasTypedArray()) {
        // get relevant part of the underlying typed array
        data.typedArray().subarray(data.position, data.limit)
      } else {
        // fall back to copying the data
        val tempBuffer = ByteBuffer.allocateDirect(data.remaining)
        val origPosition = data.position()
        tempBuffer.put(data)
        data.position(origPosition)
        tempBuffer.typedArray()
      }
    }
  }

  def get(url: String, data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty,
          withCredentials: Boolean = false, responseType: String = ""): Future[dom.XMLHttpRequest] = {
    apply("GET", url, data, timeout, headers, withCredentials, responseType)
  }

  def post(url: String, data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty,
           withCredentials: Boolean = false, responseType: String = ""): Future[dom.XMLHttpRequest] = {
    apply("POST", url, data, timeout, headers, withCredentials, responseType)
  }

  def put(url: String, data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty,
          withCredentials: Boolean = false, responseType: String = ""): Future[dom.XMLHttpRequest] = {
    apply("PUT", url, data, timeout, headers, withCredentials, responseType)
  }

  def patch(url: String, data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty,
            withCredentials: Boolean = false, responseType: String = ""): Future[dom.XMLHttpRequest] = {
    apply("PATCH", url, data, timeout, headers, withCredentials, responseType)
  }

  def delete(url: String, data: InputData = null, timeout: Int = 0, headers: Map[String, String] = Map.empty,
             withCredentials: Boolean = false, responseType: String = ""): Future[dom.XMLHttpRequest] = {
    apply("DELETE", url, data, timeout, headers, withCredentials, responseType)
  }

  def apply(method: String, url: String, data: InputData, timeout: Int, headers: Map[String, String],
            withCredentials: Boolean, responseType: String): Future[dom.XMLHttpRequest] = {
    val req = new dom.XMLHttpRequest()
    val promise = Promise[dom.XMLHttpRequest]()

    req.onreadystatechange = { _ =>
      if (req.readyState == 4) {
        if ((req.status >= 200 && req.status < 300) || req.status == 304)
          promise.success(req)
        else
          promise.failure(AjaxException(req))
      }
    }
    req.open(method, url)
    req.responseType = responseType
    req.timeout = timeout
    req.withCredentials = withCredentials
    headers.foreach(x => req.setRequestHeader(x._1, x._2))
    if (data == null)
      req.send()
    else
      req.send(data)
    promise.future
  }
}

/** Thrown when `Ajax.get` or `Ajax.post` receives a non-20X response code. Contains the XMLHttpRequest that resulted in
 * that response
 */
case class AjaxException(xhr: dom.XMLHttpRequest) extends Exception {
  def isTimeout: Boolean = xhr.status == 0 && xhr.readyState == 4
}

// This is just there to work around some weird warnings in Scala 3.x
object AjaxException extends (dom.XMLHttpRequest => AjaxException)

Output (click arrow to expand)

``` unhandled exception while running genSJSIR on /builds/ProjectForecast/project-forecast/scalajs/src/main/scala/scalajs/Ajax.scala An unhandled exception was thrown in the compiler. Please file a crash report here: https://github.com/lampepfl/dotty/issues/new/choose while compiling: during phase: mode: Mode(ImplicitsEnabled) library version: version 2.13.10 compiler version: version 3.3.1 settings: -Xplugin List(target/scala-3.3.1/compiler_plugins/wartremover_3.3.1-3.1.6.jar) -bootclasspath /builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar -classpath /builds/ProjectForecast/project-forecast/scalajs/target/scala-3.3.1/classes:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_sjs1_3/3.3.1/scala3-library_sjs1_3-3.3.1.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-js/scalajs-library_2.13/1.16.0/scalajs-library_2.13-1.16.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-js/scalajs-dom_sjs1_3/2.6.0/scalajs-dom_sjs1_3-2.6.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/io/lemonlabs/scala-uri_sjs1_3/4.0.0/scala-uri_sjs1_3-4.0.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-js/scalajs-javalib/1.16.0/scalajs-javalib-1.16.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-js/scalajs-scalalib_2.13/2.13.13%2B1.16.0/scalajs-scalalib_2.13-2.13.13%2B1.16.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/typelevel/cats-core_sjs1_3/2.7.0/cats-core_sjs1_3-2.7.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/typelevel/cats-parse_sjs1_3/0.3.6/cats-parse_sjs1_3-0.3.6.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/typelevel/cats-kernel_sjs1_3/2.7.0/cats-kernel_sjs1_3-2.7.0.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/typelevel/simulacrum-scalafix-annotations_3/0.5.4/simulacrum-scalafix-annotations_3-0.5.4.jar:/builds/ProjectForecast/project-forecast/sbt-cache/.coursier/cache/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.0.0/scala3-library_3-3.0.0.jar -coverage-out /builds/ProjectForecast/project-forecast/scalajs/target/scala-3.3.1/scoverage-data -d /builds/ProjectForecast/project-forecast/scalajs/target/scala-3.3.1/classes -scalajs true tree: EmptyTree tree position: : tree type: symbol: val call site: package in module class == Source file context for tree position == [error] ## Exception when compiling 4 sources to /builds/ProjectForecast/project-forecast/scalajs/target/scala-3.3.1/classes [error] org.scalajs.ir.InvalidIRException: Cannot hash a transient IR node (its value is of class class dotty.tools.backend.sjs.JSCodeGen$UndefinedParam$) [error] org.scalajs.ir.Hashers$TreeHasher.mixTree(Hashers.scala:552) [error] org.scalajs.ir.Hashers$TreeHasher.mixTrees$$anonfun$1(Hashers.scala:560) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.immutable.List.foreach(List.scala:333) [error] org.scalajs.ir.Hashers$TreeHasher.mixTrees(Hashers.scala:560) [error] org.scalajs.ir.Hashers$TreeHasher.mixTree(Hashers.scala:170) [error] org.scalajs.ir.Hashers$TreeHasher.mixTrees$$anonfun$1(Hashers.scala:560) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.immutable.List.foreach(List.scala:333) [error] org.scalajs.ir.Hashers$TreeHasher.mixTrees(Hashers.scala:560) [error] org.scalajs.ir.Hashers$TreeHasher.mixTree(Hashers.scala:170) [error] org.scalajs.ir.Hashers$.hashMethodDef$$anonfun$1(Hashers.scala:38) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.Option.foreach(Option.scala:437) [error] org.scalajs.ir.Hashers$.hashMethodDef(Hashers.scala:38) [error] org.scalajs.ir.Hashers$.hashMemberDefs$$anonfun$1(Hashers.scala:93) [error] scala.collection.immutable.List.map(List.scala:250) [error] org.scalajs.ir.Hashers$.hashMemberDefs(Hashers.scala:97) [error] dotty.tools.backend.sjs.JSCodeGen.genScalaClass(JSCodeGen.scala:463) [error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit$$anonfun$3$$anonfun$1(JSCodeGen.scala:245) [error] dotty.tools.backend.sjs.ScopedVar$.withScopedVars(ScopedVar.scala:33) [error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit$$anonfun$3(JSCodeGen.scala:249) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.immutable.List.foreach(List.scala:333) [error] dotty.tools.backend.sjs.JSCodeGen.genCompilationUnit(JSCodeGen.scala:251) [error] dotty.tools.backend.sjs.JSCodeGen.run(JSCodeGen.scala:163) [error] dotty.tools.backend.sjs.GenSJSIR.run(GenSJSIR.scala:18) [error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327) [error] scala.collection.immutable.List.map(List.scala:246) [error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331) [error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321) [error] dotty.tools.dotc.Run.runPhases$1(Run.scala:262) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279) [error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67) [error] dotty.tools.dotc.Run.compileUnits(Run.scala:279) [error] dotty.tools.dotc.Run.compileSources(Run.scala:194) [error] dotty.tools.dotc.Run.compile(Run.scala:179) [error] dotty.tools.dotc.Driver.doCompile(Driver.scala:37) [error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88) [error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) [error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:192) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:182) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) [error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:177) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:175) [error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:461) [error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) [error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) [error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:416) [error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:503) [error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:403) [error] sbt.internal.inc.Incremental$.apply(Incremental.scala:169) [error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:482) [error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) [error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420) [error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) [error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2366) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2316) [error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30) [error] sbt.internal.io.Retry$.apply(Retry.scala:46) [error] sbt.internal.io.Retry$.apply(Retry.scala:28) [error] sbt.internal.io.Retry$.apply(Retry.scala:23) [error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2314) [error] scala.Function1.$anonfun$compose$1(Function1.scala:49) [error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) [error] sbt.std.Transform$$anon$4.work(Transform.scala:68) [error] sbt.Execute.$anonfun$submit$2(Execute.scala:282) [error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) [error] sbt.Execute.work(Execute.scala:291) [error] sbt.Execute.$anonfun$submit$1(Execute.scala:282) [error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) [error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64) [error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) [error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [error] java.base/java.lang.Thread.run(Thread.java:[840](https://gitlab.internal.d-fine.dev/ProjectForecast/project-forecast/-/jobs/302920#L840)) [error] ```

I'm happy to provide additional infos. Just let me know what you need.

cornim commented 6 months ago

I couldn't figure out, why this was only happening in my pipeline and locally everything compiled fine until I tried something which seemed unreasonable to me at first glance.

Locally I ran sbt clean test.

The pipelline runs sbt clean coverage test using addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11") and this apperantly is exactly what is causing the issue. I hope this helps.

sjrd commented 6 months ago

Is this https://github.com/scoverage/scalac-scoverage-plugin/issues/447 yet again?