From 0a70e0710605f123546dad41a0b1a253bfffbcdc Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 21 Feb 2017 17:02:53 +0100 Subject: [PATCH 1/5] Add support for `-XemitTasty`. It saves tasty output near the class file output to a *.tasty-file. --- .../dotty/tools/backend/jvm/GenBCode.scala | 22 +++++++++++++------ .../tools/dotc/config/ScalaSettings.scala | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index 65dcb6c7994b..8fd6d1bc0139 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -1,19 +1,18 @@ package dotty.tools.backend.jvm import dotty.tools.dotc.CompilationUnit -import dotty.tools.dotc.ast.Trees.{ValDef, PackageDef} +import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef} import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.core.Names.TypeName import scala.collection.mutable -import scala.tools.asm.{CustomAttr, ClassVisitor, MethodVisitor, FieldVisitor} +import scala.tools.asm.{ClassVisitor, CustomAttr, FieldVisitor, MethodVisitor} import scala.tools.nsc.Settings import scala.tools.nsc.backend.jvm._ import dotty.tools.dotc import dotty.tools.dotc.backend.jvm.DottyPrimitives import dotty.tools.dotc.transform.Erasure - import dotty.tools.dotc.interfaces import java.util.Optional @@ -27,14 +26,15 @@ import Symbols._ import Denotations._ import Phases._ import java.lang.AssertionError -import java.io.{ File => JFile } +import java.io.{FileOutputStream, File => JFile} + import scala.tools.asm import scala.tools.asm.tree._ -import dotty.tools.dotc.util.{Positions, DotClass} +import dotty.tools.dotc.util.{DotClass, Positions} import tpd._ import StdNames._ -import scala.reflect.io.{Directory, PlainDirectory, AbstractFile} +import scala.reflect.io.{AbstractFile, Directory, PlainDirectory} import scala.tools.nsc.backend.jvm.opt.LocalOpt class GenBCode extends Phase { @@ -205,7 +205,15 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter if (claszSymbol.isClass) // @DarkDimius is this test needed here? for (binary <- ctx.compilationUnit.pickled.get(claszSymbol.asClass)) { val dataAttr = new CustomAttr(nme.TASTYATTR.toString, binary) - (if (mirrorC ne null) mirrorC else plainC).visitAttribute(dataAttr) + val store = if (mirrorC ne null) mirrorC else plainC + store.visitAttribute(dataAttr) + if (ctx.settings.emitTasty.value) { + val outTastyFile = getFileForClassfile(outF, store.name, ".tasty").file + val fos = new FileOutputStream(outTastyFile, false) + fos.write(binary) + fos.close() + + } } // -------------- bean info class, if needed -------------- diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 40e2b083b625..9f3f4f3fc933 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -44,6 +44,7 @@ class ScalaSettings extends Settings.SettingGroup { /** -X "Advanced" settings */ val Xhelp = BooleanSetting("-X", "Print a synopsis of advanced options.") + val emitTasty = BooleanSetting("-XemitTasty", "Generate tasty in separate *.tasty file.") val noForwarders = BooleanSetting("-Xno-forwarders", "Do not generate static forwarders in mirror classes.") val XminImplicitSearchDepth = IntSetting("-Xmin-implicit-search-depth", "Set number of levels of implicit searches undertaken before checking for divergence.", 5) val xmaxInlines = IntSetting("-Xmax-inlines", "Maximal number of successive inlines", 32) From 473340064d07231c2f7893ae12ad5c4ad1b3c071 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 23 Feb 2017 13:06:36 +0100 Subject: [PATCH 2/5] Fix #2024: TypeApply can be a final apply of a recursive method. nullary methods with type parameters were handled wrongly, which led to absence of type application and a cryptic error message. --- compiler/src/dotty/tools/dotc/transform/TailRec.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index aa0845605050..8a695bf2270b 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -325,6 +325,10 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete else rewriteApply(tree, meth) + case TypeApply(fun, targs) => + val meth = fun.symbol + rewriteApply(tree, meth) + case tree@Block(stats, expr) => tpd.cpy.Block(tree)( noTailTransforms(stats), From de8d3f9a452fd212236c70e3fb3af5dc9d028d8a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 23 Feb 2017 13:08:50 +0100 Subject: [PATCH 3/5] Check that #2024 is fixed. --- tests/pos/tailcall/i2024.scala | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/pos/tailcall/i2024.scala diff --git a/tests/pos/tailcall/i2024.scala b/tests/pos/tailcall/i2024.scala new file mode 100644 index 000000000000..aba1db2e560f --- /dev/null +++ b/tests/pos/tailcall/i2024.scala @@ -0,0 +1,4 @@ +object Test { +// def main(args: Array[String]): Unit = { } + def assume[T]: Any = assume +} From 8495e80ab2656fabfd578807d5ddd73bc498a80d Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 13 Mar 2017 14:20:29 +0100 Subject: [PATCH 4/5] Remove name clash in test. --- tests/pos/tailcall/return.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pos/tailcall/return.scala b/tests/pos/tailcall/return.scala index 454686c3d7a7..3724b5b32b4d 100644 --- a/tests/pos/tailcall/return.scala +++ b/tests/pos/tailcall/return.scala @@ -1,4 +1,4 @@ -object Test { +object Return { def foo(x: Int): Int = return 3 From 176f40a6daccbd5365988e66d84e44cba818e64a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 4 Apr 2017 11:51:30 +0200 Subject: [PATCH 5/5] Change -XemitTasty to -YemitTasty --- compiler/src/dotty/tools/dotc/config/ScalaSettings.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index 9f3f4f3fc933..6c54f10e230c 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -44,7 +44,6 @@ class ScalaSettings extends Settings.SettingGroup { /** -X "Advanced" settings */ val Xhelp = BooleanSetting("-X", "Print a synopsis of advanced options.") - val emitTasty = BooleanSetting("-XemitTasty", "Generate tasty in separate *.tasty file.") val noForwarders = BooleanSetting("-Xno-forwarders", "Do not generate static forwarders in mirror classes.") val XminImplicitSearchDepth = IntSetting("-Xmin-implicit-search-depth", "Set number of levels of implicit searches undertaken before checking for divergence.", 5) val xmaxInlines = IntSetting("-Xmax-inlines", "Maximal number of successive inlines", 32) @@ -71,6 +70,7 @@ class ScalaSettings extends Settings.SettingGroup { val debugOwners = BooleanSetting("-Ydebug-owners", "Print all owners of definitions (requires -Yprint-syms)") val termConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error") val log = PhasesSetting("-Ylog", "Log operations during") + val emitTasty = BooleanSetting("-YemitTasty", "Generate tasty in separate *.tasty file.") val Ylogcp = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.") val YnoImports = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.") val YnoPredef = BooleanSetting("-Yno-predef", "Compile without importing Predef.")