From 153c70b5b64344db5a97a3de23e91e49f57ac337 Mon Sep 17 00:00:00 2001 From: wpopielarski Date: Wed, 21 Oct 2015 16:58:20 +0200 Subject: Multi output problem with delambdafied compilation User code compilation with -Ybackend:GenBCode -Ydelambdafy:method fails for projects with multiple output directories. The problem has its root in a fact that some `lambdaClass` symbols the `associatedFile` field is not set. It can be done in Delambdafy.scala (`makeAnonymousClass` method) and is working for following lambda examples: {{{ package acme object Delambdafy { type -->[D, I] = PartialFunction[D, I] def main(args: Array[String]): Unit = { val result = List(1, 2, 4).map { a => val list = List("1", "2", "3").map { _ + "test" } list.find { _ == a.toString + "test" } } lazy val _foo = foo(result) { case x::xs if x isDefined => x.get.length case _ => 0 } lazy val bar: Int => Int = { case 2 => 13 case _ => val v = List(1).map(_ + 42).head v + 1 } } def foo(b: List[Option[String]])(a: List[Option[String]] => Int): Int = a(b) } }}} but is NOT working for following lambda: {{{ package acme object Delambdafy { type -->[D, I] = PartialFunction[D, I] def main(args: Array[String]): Unit = { lazy val _baz = baz { case 1 => val local = List(1).map(_ + 1) local.head } } def baz[T](f: Any --> Any): Any => Any = f } }}} so that's why source of compilation unit is used to determine output directory in case when source file is not found for symbol. --- .../scala/tools/nsc/backend/jvm/BCodeHelpers.scala | 29 +++++++++++++++------- .../tools/nsc/backend/jvm/BytecodeWriters.scala | 3 +++ 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala index 65a6b82570..813180a8c7 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala @@ -35,15 +35,26 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters { /* * must-single-thread */ - def getOutFolder(csym: Symbol, cName: String, cunit: CompilationUnit): _root_.scala.tools.nsc.io.AbstractFile = { - try { - outputDirectory(csym) - } catch { - case ex: Throwable => - reporter.error(cunit.body.pos, s"Couldn't create file for class $cName\n${ex.getMessage}") - null - } - } + def getOutFolder(csym: Symbol, cName: String, cunit: CompilationUnit): _root_.scala.tools.nsc.io.AbstractFile = Option { + try { + outputDirectory(csym) + } catch { + case ex: Throwable => + reporter.warning(cunit.body.pos, s"Couldn't find output folder for symbol source ${csym.name}. Dropping to compliation unit source.\n${ex.getMessage}") + null + } + }.orElse { Option { + try { + outputDirectory(cunit.source) + } catch { + case ex: Throwable => + reporter.warning(cunit.body.pos, s"Couldn't find output folder for compilation unit $cName\n${ex.getMessage}") + null + } + }}.orElse { + reporter.error(cunit.body.pos, s"Couldn't create file for class $cName") + None + }.orNull var pickledBytes = 0 // statistics diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala index 1d29fdee10..e4fcb729a2 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala @@ -25,6 +25,9 @@ trait BytecodeWriters { def outputDirectory(sym: Symbol): AbstractFile = settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile) + def outputDirectory(cunitSource: scala.reflect.internal.util.SourceFile): AbstractFile = + settings.outputDirs outputDirFor cunitSource.file + /** * @param clsName cls.getName */ -- cgit v1.2.3