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..6c54f10e230c 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -70,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.") 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), 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 +} 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