Skip to content

Out of memory error compiling macro example #7618

@machisuji

Description

@machisuji

environment

OS: Linux 5.0.0-36-generic / Ubuntu 19.04 and debian 9 (stretch)
Java: 11.0.5
SBT: 1.3.4
Dotty: 0.20.0-RC1

minimized code

The code is mostly taken from the documentation about macros.

package macros

import scala.quoted.{given, _}

enum Exp {
  case Num(n: Int)
  case Plus(e1: Exp, e2: Exp)
  case Var(x: String)
  case Let(x: String, e: Exp, in: Exp)
}

object Compiler {
  import Exp._

  inline def compile(e: Exp, env: Map[String, Expr[Int]])(given ctx: QuoteContext): Expr[Int] = e match {
    case Num(n) =>
      Expr(n)
    case Plus(e1, e2) =>
      '{ ${ compile(e1, env) } + ${ compile(e2, env) } }
    case Var(x) =>
      env(x)
    case Let(x, e, body) =>
      '{ val y = ${ compile(e, env) }; ${ compile(body, env + (x -> 'y)) } }
  }
}

object Example {
  def run(): Unit = {
    import Exp._

    val exp = Plus(Plus(Num(2), Var("x")), Num(4))
    val letExp = Let("x", Num(3), exp)

    Compiler.compile(letExp, Map.empty)(given QuoteContext.macroContext)
  }
}

the problem

I have the code in a SBT project created using the g8 template. Trying to compile the code results in the the compiler getting stuck and running out of memory. The process never finishes. I have to kill it.

Obviously I have not the slightest idea what I'm doing with regard to macros but either way I think the compiler should be able to handle it.

sbt:macro-example> compile
[info] Compiling 1 Scala source to /usr/src/dotty-project/target/scala-0.20/classes ...

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "classloader-cache-cleanup-0"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "task-progress-report-thread"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "pool-11-thread-3"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "pool-11-thread-7"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "pool-11-thread-9"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "pool-11-thread-2"

reproduction

If you happen to have docker installed you should be able to reproduce the issue with this one line:

docker run --rm -it machisuji/dotty-project:latest sbt compile

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions