diff --git a/build.sbt b/build.sbt index e4f27b72a3ad..c0ff38b603f0 100644 --- a/build.sbt +++ b/build.sbt @@ -14,6 +14,9 @@ val `dotty-staging` = Build.`dotty-staging` val `dotty-language-server` = Build.`dotty-language-server` val `dotty-bench` = Build.`dotty-bench` val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped` +val `tasty-core` = Build.`tasty-core` +val `tasty-core-bootstrapped` = Build.`tasty-core-bootstrapped` +val `tasty-core-scala2` = Build.`tasty-core-scala2` val `scala-library` = Build.`scala-library` val `scala-compiler` = Build.`scala-compiler` val `scala-reflect` = Build.`scala-reflect` diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index b291a6b0ec44..8601d72d96c1 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -20,13 +20,13 @@ import Decorators._ import java.io.DataOutputStream +import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler } import scala.tools.asm import scala.tools.asm.Handle import scala.tools.asm.tree._ import tpd._ import StdNames._ -import dotty.tools.dotc.core.tasty.{TastyBuffer, TastyHeaderUnpickler} import dotty.tools.io._ class GenBCode extends Phase { diff --git a/compiler/src/dotty/tools/dotc/core/NameTags.scala b/compiler/src/dotty/tools/dotc/core/NameTags.scala index fe351ccc61e7..df4989dafac9 100644 --- a/compiler/src/dotty/tools/dotc/core/NameTags.scala +++ b/compiler/src/dotty/tools/dotc/core/NameTags.scala @@ -1,8 +1,6 @@ -package dotty.tools -package dotc -package core +package dotty.tools.dotc.core -import tasty.TastyFormat +import dotty.tools.tasty.TastyFormat /** The possible tags of a NameKind */ object NameTags extends TastyFormat.NameTags { diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index df28f90dd188..8fbd636b756e 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -3,10 +3,11 @@ package dotc package core package classfile +import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler } + import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._ import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotations._, util.Spans._ import NameKinds.DefaultGetterName -import dotty.tools.dotc.core.tasty.{TastyHeaderUnpickler, TastyReader} import ast.tpd._ import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, IOException } @@ -1183,4 +1184,3 @@ class ClassfileParser( throw new RuntimeException("bad constant pool tag " + in.buf(start) + " at byte " + start) } } - diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index bd306960eb76..c6982f1ad5f0 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -12,11 +12,13 @@ import dotty.tools.dotc.core.Mode import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.core.tasty.TreePickler.Hole -import dotty.tools.dotc.core.tasty.{PositionPickler, TastyPickler, TastyPrinter, TastyString} +import dotty.tools.dotc.core.tasty.{ PositionPickler, TastyPickler, TastyPrinter } import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode import dotty.tools.dotc.quoted.QuoteContext import dotty.tools.dotc.tastyreflect.ReflectionImpl +import dotty.tools.tasty.TastyString + import scala.internal.quoted._ import scala.reflect.ClassTag diff --git a/compiler/src/dotty/tools/dotc/core/quoted/QuoteUnpickler.scala b/compiler/src/dotty/tools/dotc/core/quoted/QuoteUnpickler.scala index 7a01d611a94b..b0927b99c3ed 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/QuoteUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/QuoteUnpickler.scala @@ -4,6 +4,8 @@ import dotty.tools.dotc.core.tasty._ import dotty.tools.dotc.core.tasty.TastyUnpickler.NameTable import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode +import dotty.tools.tasty.TastyReader + object QuoteUnpickler { class QuotedTreeSectionUnpickler(posUnpickler: Option[PositionUnpickler], splices: Seq[Any]) extends DottyUnpickler.TreeSectionUnpickler(posUnpickler, None) { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala index 8f9a54dbc524..1b57588f45a8 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala @@ -3,7 +3,9 @@ package dotty.tools.dotc.core.tasty import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Comments.{Comment, CommentsContext, ContextDocstrings} import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.tasty.TastyBuffer.{Addr, NoAddr} + +import dotty.tools.tasty.TastyBuffer +import TastyBuffer.{Addr, NoAddr} import java.nio.charset.Charset @@ -40,4 +42,3 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr)(implic } } } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala index 316a77d13fbf..3b12f6d773c3 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentUnpickler.scala @@ -1,9 +1,11 @@ package dotty.tools.dotc.core.tasty import dotty.tools.dotc.core.Comments.Comment -import dotty.tools.dotc.core.tasty.TastyBuffer.Addr import dotty.tools.dotc.util.Spans.Span +import dotty.tools.tasty.{TastyReader, TastyBuffer} +import TastyBuffer.Addr + import scala.collection.mutable.HashMap import java.nio.charset.Charset @@ -29,4 +31,3 @@ class CommentUnpickler(reader: TastyReader) { def commentAt(addr: Addr): Option[Comment] = comments.get(addr) } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala index 967dec8c03e1..40356da7a40c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala @@ -10,6 +10,8 @@ import classfile.ClassfileParser import Names.SimpleName import TreeUnpickler.UnpickleMode +import dotty.tools.tasty.TastyReader + object DottyUnpickler { /** Exception thrown if classfile is corrupted */ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala index 388de191823e..63b724b051f8 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala @@ -3,11 +3,13 @@ package dotc package core package tasty +import dotty.tools.tasty.TastyBuffer +import TastyBuffer._ + import collection.mutable import Names.{Name, chrs, SimpleName, DerivedName, TypeName} import NameKinds._ import Decorators._ -import TastyBuffer._ import scala.io.Codec class NameBuffer extends TastyBuffer(10000) { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala index 280d858eda69..8a7095b21dd3 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala @@ -3,6 +3,10 @@ package dotc package core package tasty +import dotty.tools.tasty.TastyFormat.SOURCE +import dotty.tools.tasty.TastyBuffer +import TastyBuffer._ + import ast._ import ast.Trees._ import ast.Trees.WithLazyField @@ -10,9 +14,7 @@ import util.{SourceFile, NoSource} import core._ import Contexts._, Symbols._, Annotations._, Decorators._ import collection.mutable -import TastyBuffer._ import util.Spans._ -import TastyFormat.SOURCE class PositionPickler(pickler: TastyPickler, addrOfTree: untpd.Tree => Addr) { val buf: TastyBuffer = new TastyBuffer(5000) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala index 52194c6d2a4f..4d15b39999f6 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/PositionUnpickler.scala @@ -3,10 +3,12 @@ package dotc package core package tasty +import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyReader} +import TastyFormat.SOURCE +import TastyBuffer.{Addr, NameRef} + import util.Spans._ import collection.{mutable, Map} -import TastyBuffer.{Addr, NameRef} -import TastyFormat.SOURCE import Names.TermName /** Unpickler for tree positions */ @@ -61,4 +63,3 @@ class PositionUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName) { def spanAt(addr: Addr): Span = spans.getOrElse(addr, NoSpan) def sourcePathAt(addr: Addr): String = sourcePaths.getOrElse(addr, "") } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala index 6ca530997717..12e8a60c5a28 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala @@ -2,11 +2,13 @@ package dotty.tools.dotc package core package tasty +import dotty.tools.tasty.{TastyBuffer, TastyReader} +import TastyBuffer.NameRef + import Contexts._, Decorators._ import Names.{Name, TermName} import StdNames.nme import TastyUnpickler._ -import TastyBuffer.NameRef import util.Spans.offsetToInt import printing.Highlighting._ @@ -20,7 +22,7 @@ class TastyClassName(bytes: Array[Byte]) { def readName(): Option[(TermName, TermName)] = unpickle(new TreeSectionUnpickler) class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](TreePickler.sectionName) { - import TastyFormat._ + import dotty.tools.tasty.TastyFormat._ def unpickle(reader: TastyReader, tastyName: NameTable): (TermName, TermName) = { import reader._ def readName() = { diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyHTMLPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyHTMLPrinter.scala index e6d2ea258760..f8f6c11ce6c1 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyHTMLPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyHTMLPrinter.scala @@ -2,10 +2,11 @@ package dotty.tools.dotc package core package tasty +import dotty.tools.tasty.TastyBuffer.NameRef + import Contexts._, Decorators._ import Names.Name import TastyUnpickler._ -import TastyBuffer.NameRef import util.Spans.offsetToInt import printing.Highlighting._ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala index a0ead8d38dbe..3ae6cb79510d 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala @@ -3,9 +3,11 @@ package dotc package core package tasty +import dotty.tools.tasty.{TastyBuffer, TastyFormat, TastyHash} import TastyFormat._ -import collection.mutable import TastyBuffer._ + +import collection.mutable import core.Symbols.{Symbol, ClassSymbol} import ast.tpd import Decorators._ @@ -78,4 +80,3 @@ class TastyPickler(val rootCls: ClassSymbol) { val treePkl: TreePickler = new TreePickler(this) } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index 3a007d667371..3dea03543393 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -2,10 +2,12 @@ package dotty.tools.dotc package core package tasty +import dotty.tools.tasty.{TastyBuffer, TastyReader} +import TastyBuffer.{Addr, NameRef} + import Contexts._, Decorators._ import Names.Name import TastyUnpickler._ -import TastyBuffer.{Addr, NameRef} import util.Spans.offsetToInt import printing.Highlighting._ @@ -49,7 +51,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) { } class TreeSectionUnpickler extends SectionUnpickler[String](TreePickler.sectionName) { - import TastyFormat._ + import dotty.tools.tasty.TastyFormat._ private val sb: StringBuilder = new StringBuilder diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala index cef20a5223e6..6222377716ab 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyString.scala @@ -1,4 +1,4 @@ -package dotty.tools.dotc.core.tasty +package dotty.tools.tasty import java.io._ import java.util.Base64 @@ -25,4 +25,3 @@ object TastyString { Base64.getDecoder().decode(string.result().getBytes(UTF_8)) } } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala index 1d7d0f825686..bc40900b2fbb 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala @@ -2,14 +2,15 @@ package dotty.tools.dotc package core package tasty -import scala.collection.mutable +import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyReader, TastyHeaderUnpickler} import TastyFormat.NameTags._ import TastyBuffer.NameRef + +import scala.collection.mutable import Names.{TermName, termName, EmptyTermName} import NameKinds._ object TastyUnpickler { - class UnpickleException(msg: String) extends RuntimeException(msg) abstract class SectionUnpickler[R](val name: String) { def unpickle(reader: TastyReader, nameAtRef: NameTable): R diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala index 08ebedfb054c..345dde2aad75 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala @@ -3,8 +3,11 @@ package dotc package core package tasty -import util.Util.{bestFit, dble} +import dotty.tools.tasty.util.Util.dble +import dotty.tools.tasty.TastyBuffer import TastyBuffer.{Addr, NoAddr, AddrWidth} + +import util.Util.bestFit import config.Printers.pickling import ast.untpd.Tree diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 19044baac2d5..e5fab768f976 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -3,14 +3,15 @@ package dotc package core package tasty +import dotty.tools.tasty.TastyFormat._ +import dotty.tools.tasty.TastyBuffer._ + import ast.Trees._ import ast.{untpd, tpd} -import TastyFormat._ import Contexts._, Symbols._, Types._, Names._, Constants._, Decorators._, Annotations._, Flags._ import typer.Inliner import NameKinds._ import StdNames.nme -import TastyBuffer._ import transform.SymUtils._ import printing.Printer import printing.Texts._ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index acacd0f0cfdd..4bfafc68e752 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -24,6 +24,8 @@ import ast.{TreeTypeMap, Trees, tpd, untpd} import Trees._ import Decorators._ import transform.SymUtils._ + +import dotty.tools.tasty.{TastyBuffer, TastyReader} import TastyBuffer._ import scala.annotation.{switch, tailrec} @@ -33,6 +35,8 @@ import config.Printers.pickling import core.quoted.PickledQuotes import dotty.tools.dotc.quoted.QuoteContext +import dotty.tools.tasty.TastyFormat._ + import scala.quoted import scala.internal.quoted.{TastyTreeExpr, TreeType} import scala.annotation.constructorOnly @@ -49,7 +53,6 @@ class TreeUnpickler(reader: TastyReader, posUnpicklerOpt: Option[PositionUnpickler], commentUnpicklerOpt: Option[CommentUnpickler], splices: Seq[Any]) { - import TastyFormat._ import TreeUnpickler._ import tpd._ @@ -1454,5 +1457,3 @@ object TreeUnpickler { class TreeWithoutOwner extends Exception } - - diff --git a/compiler/src/dotty/tools/dotc/util/Util.scala b/compiler/src/dotty/tools/dotc/util/Util.scala index bf34ff0157ed..7b6e3b1136ff 100644 --- a/compiler/src/dotty/tools/dotc/util/Util.scala +++ b/compiler/src/dotty/tools/dotc/util/Util.scala @@ -1,5 +1,4 @@ package dotty.tools.dotc.util -import reflect.ClassTag object Util { @@ -23,10 +22,4 @@ object Util { else recur(0, length, initMid) } - /** An array twice the size of given array, with existing elements copied over */ - def dble[T: ClassTag](arr: Array[T]): Array[T] = { - val arr1 = new Array[T](arr.length * 2) - System.arraycopy(arr, 0, arr1, 0, arr.length) - arr1 - } } diff --git a/compiler/test/dotty/Properties.scala b/compiler/test/dotty/Properties.scala index f2195e143746..ed377859a047 100644 --- a/compiler/test/dotty/Properties.scala +++ b/compiler/test/dotty/Properties.scala @@ -53,6 +53,9 @@ object Properties { /** dotty-staging jar */ def dottyStaging: String = sys.props("dotty.tests.classes.dottyStaging") + /** tasty-core jar */ + def tastyCore: String = sys.props("dotty.tests.classes.tastyCore") + /** compiler-interface jar */ def compilerInterface: String = sys.props("dotty.tests.classes.compilerInterface") diff --git a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala index 61da70fef499..95b2fd978068 100644 --- a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala @@ -50,6 +50,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting { compileDir("compiler/src/dotty/tools/dotc/typer", withCompilerOptions), compileDir("compiler/src/dotty/tools/dotc/util", withCompilerOptions), compileDir("compiler/src/dotty/tools/io", withCompilerOptions), + compileDir("tasty/src/dotty/tools/tasty", withCompilerOptions), compileList( "testIssue6460", List( @@ -163,7 +164,8 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting { compileFile("tests/pos/pickleinf.scala", picklingWithCompilerOptions), compileDir("compiler/src/dotty/tools/dotc/core/classfile", picklingWithCompilerOptions), compileDir("compiler/src/dotty/tools/dotc/core/tasty", picklingWithCompilerOptions), - compileDir("compiler/src/dotty/tools/dotc/core/unpickleScala2", picklingWithCompilerOptions) + compileDir("compiler/src/dotty/tools/dotc/core/unpickleScala2", picklingWithCompilerOptions), + compileDir("tasty/src/dotty/tools/tasty", picklingWithCompilerOptions) ).limitThreads(4).checkCompile() } diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index fcc591cf9057..702860e379a4 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -210,7 +210,8 @@ class CompilationTests extends ParallelTesting { defaultOutputDir + dotty1Group + "/dotty/" + sep + // and the other compiler dependenies: Properties.compilerInterface + sep + Properties.scalaLibrary + sep + Properties.scalaAsm + sep + - Properties.dottyInterfaces + sep + Properties.jlineTerminal + sep + Properties.jlineReader, + Properties.dottyInterfaces + sep + Properties.tastyCore + sep + Properties.jlineTerminal + sep + + Properties.jlineReader, Array("-Ycheck-reentrant", "-Yemit-tasty-in-class") ) diff --git a/compiler/test/dotty/tools/dotc/TastyHashTest.scala b/compiler/test/dotty/tools/dotc/TastyHashTest.scala index b8cb5c9c0bc2..09d631d97377 100644 --- a/compiler/test/dotty/tools/dotc/TastyHashTest.scala +++ b/compiler/test/dotty/tools/dotc/TastyHashTest.scala @@ -3,7 +3,7 @@ package dotty.tools.dotc import org.junit.Test import org.junit.Assert.assertEquals -import dotty.tools.dotc.core.tasty.TastyHash.pjwHash64 +import dotty.tools.tasty.TastyHash.pjwHash64 class TastyHashTest { @Test def pjwHash64Tests(): Unit = { diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index db121cf00932..931f56d21048 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -32,6 +32,7 @@ object TestConfiguration { Properties.compilerInterface, Properties.dottyInterfaces, Properties.dottyLibrary, + Properties.tastyCore, Properties.dottyCompiler )) diff --git a/dist/bin/common b/dist/bin/common index 085b0f386300..0c7822f6c953 100755 --- a/dist/bin/common +++ b/dist/bin/common @@ -108,6 +108,7 @@ DOTTY_COMP=$(find_lib "*dotty-compiler*") DOTTY_INTF=$(find_lib "*dotty-interfaces*") DOTTY_LIB=$(find_lib "*dotty-library*") DOTTY_STAGING=$(find_lib "*dotty-staging*") +TASTY_CORE=$(find_lib "*tasty-core*") SCALA_ASM=$(find_lib "*scala-asm*") SCALA_LIB=$(find_lib "*scala-library*") SBT_INTF=$(find_lib "*compiler-interface*") diff --git a/dist/bin/dotc b/dist/bin/dotc index b442f27a36c5..532224705709 100755 --- a/dist/bin/dotc +++ b/dist/bin/dotc @@ -50,6 +50,7 @@ classpathArgs () { # echo "dotty-compiler: $DOTTY_COMP" # echo "dotty-interface: $DOTTY_INTF" # echo "dotty-library: $DOTTY_LIB" + # echo "tasty-core: $TASTY_CORE" # echo "scala-asm: $SCALA_ASM" # echo "scala-lib: $SCALA_LIB" # echo "sbt-intface: $SBT_INTF" @@ -61,6 +62,7 @@ classpathArgs () { toolchain+="$SBT_INTF$PSEP" toolchain+="$DOTTY_INTF$PSEP" toolchain+="$DOTTY_COMP$PSEP" + toolchain+="$TASTY_CORE$PSEP" toolchain+="$DOTTY_STAGING$PSEP" # jine @@ -88,7 +90,7 @@ case "$1" in -run) PROG_NAME="$ReplMain" && shift ;; -colors) colors=true && shift ;; -no-colors) unset colors && shift ;; - -with-compiler) jvm_cp_args="$PSEP$DOTTY_COMP" && shift ;; + -with-compiler) jvm_cp_args="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE" && shift ;; # break out -D and -J options and add them to java_args so # they reach the JVM in time to do some good. The -D options diff --git a/dist/bin/dotd b/dist/bin/dotd index 0475e81ad68a..ff4cce9788ce 100755 --- a/dist/bin/dotd +++ b/dist/bin/dotd @@ -76,7 +76,7 @@ ST4_LIB=$(find_lib "*ST4*") # Set jsoup dep: JSOUP_LIB=$(find_lib "*jsoup*") -CLASS_PATH="$DOTTY_LIB$PSEP$DOTTY_COMP$PSEP$DOTTY_DOC_LIB$PSEP$DOTTY_INTF$PSEP$SBT_INTF$PSEP$DOTTY_STAGING" +CLASS_PATH="$DOTTY_LIB$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_DOC_LIB$PSEP$DOTTY_INTF$PSEP$SBT_INTF$PSEP$DOTTY_STAGING" CLASS_PATH="$CLASS_PATH$PSEP$SCALA_LIB" CLASS_PATH="$CLASS_PATH$PSEP$FLEXMARK_LIBS" CLASS_PATH="$CLASS_PATH$PSEP$JACKSON_LIBS" diff --git a/dist/bin/dotr b/dist/bin/dotr index 5d8808a3ed4d..029a0aee97af 100755 --- a/dist/bin/dotr +++ b/dist/bin/dotr @@ -102,7 +102,7 @@ elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then echo "warning: multiple classpaths are found, dotr only use the last one." fi if [ $with_compiler == true ]; then - cp_arg+="$PSEP$DOTTY_COMP$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING" + cp_arg+="$PSEP$DOTTY_COMP$PSEP$TASTY_CORE$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$PSEP$DOTTY_STAGING" fi eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${jvm_options[@]}" "${residual_args[@]}" else diff --git a/language-server/src/dotty/tools/languageserver/decompiler/TastyDecompilerService.scala b/language-server/src/dotty/tools/languageserver/decompiler/TastyDecompilerService.scala index 8494b9630712..cf2faf679ac8 100644 --- a/language-server/src/dotty/tools/languageserver/decompiler/TastyDecompilerService.scala +++ b/language-server/src/dotty/tools/languageserver/decompiler/TastyDecompilerService.scala @@ -6,7 +6,8 @@ import java.net.URI import java.nio.file._ import java.util.concurrent.CompletableFuture -import dotc.core.tasty.TastyUnpickler.UnpickleException +import dotty.tools.tasty.UnpickleException + import dotc.fromtasty.TastyFileUtil import org.eclipse.lsp4j.jsonrpc.services._ diff --git a/project/Build.scala b/project/Build.scala index b626fcb32b58..803d2ef63918 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -252,6 +252,13 @@ object Build { autoScalaLibrary := false ) + lazy val commonScala2Settings = commonSettings ++ Seq( + scalaVersion := stdlibVersion(Bootstrapped), + moduleName ~= { _.stripSuffix("-scala2") }, + version := dottyVersion, + target := baseDirectory.value / ".." / "out" / "scala-2" / name.value, + ) + // Settings used when compiling dotty with the reference compiler lazy val commonNonBootstrappedSettings = commonDottySettings ++ Seq( unmanagedSourceDirectories in Compile += baseDirectory.value / "src-non-bootstrapped", @@ -298,12 +305,13 @@ object Build { // compiler instances. This cache is invalidated based on timestamps // however this is only implemented on jars, directories are never // invalidated. + val tastyCore = packageBin.in(`tasty-core`, Compile).value val dottyLibrary = packageBin.in(`dotty-library`, Compile).value val dottyInterfaces = packageBin.in(`dotty-interfaces`, Compile).value val dottyCompiler = packageBin.in(`dotty-compiler`, Compile).value val dottyDoc = packageBin.in(`dotty-doc`, Compile).value - val allJars = Seq(dottyLibrary, dottyInterfaces, dottyCompiler, dottyDoc) ++ externalNonBootstrappedDeps.map(_.data) + val allJars = Seq(tastyCore, dottyLibrary, dottyInterfaces, dottyCompiler, dottyDoc) ++ externalNonBootstrappedDeps.map(_.data) makeScalaInstance( state.value, @@ -361,7 +369,6 @@ object Build { private lazy val dottydocClasspath = Def.task { val jars = (packageAll in `dotty-compiler`).value val dottyLib = jars("dotty-library") - val dottyInterfaces = jars("dotty-interfaces") val otherDeps = (dependencyClasspath in Compile).value.map(_.data).mkString(File.pathSeparator) val externalDeps = externalCompilerClasspathTask.value dottyLib + File.pathSeparator + findArtifactPath(externalDeps, "scala-library") @@ -512,6 +519,7 @@ object Build { "-Ddotty.tests.classes.dottyInterfaces=" + jars("dotty-interfaces"), "-Ddotty.tests.classes.dottyLibrary=" + jars("dotty-library"), "-Ddotty.tests.classes.dottyCompiler=" + jars("dotty-compiler"), + "-Ddotty.tests.classes.tastyCore=" + jars("tasty-core"), "-Ddotty.tests.classes.compilerInterface=" + findArtifactPath(externalDeps, "compiler-interface"), "-Ddotty.tests.classes.scalaLibrary=" + findArtifactPath(externalDeps, "scala-library"), "-Ddotty.tests.classes.scalaAsm=" + findArtifactPath(externalDeps, "scala-asm"), @@ -573,7 +581,8 @@ object Build { val dottyCompiler = jars("dotty-compiler") val dottyStaging = jars("dotty-staging") val dottyInterfaces = jars("dotty-interfaces") - run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm, dottyStaging).mkString(File.pathSeparator))) + val tastyCore = jars("tasty-core") + run(insertClasspathInArgs(args1, List(dottyCompiler, dottyInterfaces, asm, dottyStaging, tastyCore).mkString(File.pathSeparator))) } else run(args) }, @@ -647,8 +656,9 @@ object Build { } val dottyInterfaces = jars("dotty-interfaces") val dottyStaging = jars("dotty-staging") + val tastyCore = jars("tasty-core") val asm = findArtifactPath(externalDeps, "scala-asm") - extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm, dottyStaging) + extraClasspath ++= Seq(dottyCompiler, dottyInterfaces, asm, dottyStaging, tastyCore) } val fullArgs = main :: insertClasspathInArgs(args, extraClasspath.mkString(File.pathSeparator)) @@ -669,12 +679,13 @@ object Build { Map( "dotty-interfaces" -> packageBin.in(`dotty-interfaces`, Compile).value, "dotty-compiler" -> packageBin.in(Compile).value, + "tasty-core" -> packageBin.in(`tasty-core`, Compile).value, // NOTE: Using dotty-library-bootstrapped here is intentional: when // running the compiler, we should always have the bootstrapped // library on the compiler classpath since the non-bootstrapped one // may not be binary-compatible. - "dotty-library" -> packageBin.in(`dotty-library-bootstrapped`, Compile).value, + "dotty-library" -> packageBin.in(`dotty-library-bootstrapped`, Compile).value ).mapValues(_.getAbsolutePath) } }.value, @@ -697,6 +708,7 @@ object Build { packageAll.in(`dotty-compiler`).value ++ Seq( "dotty-compiler" -> packageBin.in(Compile).value.getAbsolutePath, "dotty-staging" -> packageBin.in(LocalProject("dotty-staging"), Compile).value.getAbsolutePath, + "tasty-core" -> packageBin.in(LocalProject("tasty-core-bootstrapped"), Compile).value.getAbsolutePath, ) } ) @@ -743,6 +755,22 @@ object Build { (unmanagedSourceDirectories in (`dotty-library-bootstrapped`, Compile)).value, ) + lazy val tastyCoreSettings = Seq( + scalacOptions ~= { old => + val (language, other) = old.partition(_.startsWith("-language:")) + other :+ (language.headOption.map(_ + ",Scala2Compat").getOrElse("-language:Scala2Compat")) + } + ) + + lazy val `tasty-core` = project.in(file("tasty")).asTastyCore(NonBootstrapped) + lazy val `tasty-core-bootstrapped`: Project = project.in(file("tasty")).asTastyCore(Bootstrapped) + lazy val `tasty-core-scala2`: Project = project.in(file("tasty")).asTastyCoreScala2 + + def tastyCore(implicit mode: Mode): Project = mode match { + case NonBootstrapped => `tasty-core` + case Bootstrapped => `tasty-core-bootstrapped` + } + lazy val `dotty-staging` = project.in(file("staging")). withCommonSettings(Bootstrapped). // We want the compiler to be present in the compiler classpath when compiling this project but not @@ -1053,6 +1081,7 @@ object Build { publishLocal in `dotty-interfaces`, publishLocal in `dotty-compiler-bootstrapped`, publishLocal in `dotty-library-bootstrapped`, + publishLocal in `tasty-core-bootstrapped`, publishLocal in `dotty-staging`, publishLocal in `scala-library`, publishLocal in `scala-reflect`, @@ -1129,6 +1158,7 @@ object Build { (publishLocal in `dotty-interfaces`).value (publishLocal in `scala-library`).value (publishLocal in `scala-reflect`).value + (publishLocal in `tasty-core-bootstrapped`).value (publishLocal in `dotty-library-bootstrapped`).value (publishLocal in `dotty-doc-bootstrapped`).value (publishLocal in `dotty-compiler-bootstrapped`).value @@ -1263,8 +1293,9 @@ object Build { // FIXME: we do not aggregate `bin` because its tests delete jars, thus breaking other tests def asDottyRoot(implicit mode: Mode): Project = project.withCommonSettings. - aggregate(`dotty-interfaces`, dottyLibrary, dottyCompiler, dottyDoc, `dotty-sbt-bridge`). + aggregate(`dotty-interfaces`, dottyLibrary, dottyCompiler, tastyCore, dottyDoc, `dotty-sbt-bridge`). bootstrappedAggregate(`scala-library`, `scala-compiler`, `scala-reflect`, scalap, `dotty-language-server`, `dotty-staging`). + dependsOn(tastyCore). dependsOn(dottyCompiler). dependsOn(dottyLibrary). nonBootstrappedSettings( @@ -1274,6 +1305,7 @@ object Build { def asDottyCompiler(implicit mode: Mode): Project = project.withCommonSettings. dependsOn(`dotty-interfaces`). dependsOn(dottyLibrary). + dependsOn(tastyCore). settings(dottyCompilerSettings) def asDottyLibrary(implicit mode: Mode): Project = project.withCommonSettings. @@ -1282,6 +1314,12 @@ object Build { ). settings(dottyLibrarySettings) + def asTastyCore(implicit mode: Mode): Project = project.withCommonSettings. + dependsOn(dottyLibrary). + settings(tastyCoreSettings) + + def asTastyCoreScala2: Project = project.settings(commonScala2Settings) + def asDottyDoc(implicit mode: Mode): Project = project.withCommonSettings. dependsOn(dottyCompiler, dottyCompiler % "test->test"). settings(dottyDocSettings) @@ -1294,7 +1332,7 @@ object Build { def asDist(implicit mode: Mode): Project = project. enablePlugins(PackPlugin). withCommonSettings. - dependsOn(`dotty-interfaces`, dottyCompiler, dottyLibrary, `dotty-staging`, dottyDoc). + dependsOn(`dotty-interfaces`, dottyCompiler, dottyLibrary, tastyCore, `dotty-staging`, dottyDoc). settings(commonDistSettings). bootstrappedSettings( target := baseDirectory.value / "target" // override setting in commonBootstrappedSettings diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyBuffer.scala b/tasty/src/dotty/tools/tasty/TastyBuffer.scala similarity index 98% rename from compiler/src/dotty/tools/dotc/core/tasty/TastyBuffer.scala rename to tasty/src/dotty/tools/tasty/TastyBuffer.scala index 8d188bb64cd7..1d48027087f5 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyBuffer.scala +++ b/tasty/src/dotty/tools/tasty/TastyBuffer.scala @@ -1,7 +1,4 @@ -package dotty.tools -package dotc -package core -package tasty +package dotty.tools.tasty import util.Util.dble diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala similarity index 99% rename from compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala rename to tasty/src/dotty/tools/tasty/TastyFormat.scala index b6c9fb0ee38b..3f516efe638c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -1,6 +1,4 @@ -package dotty.tools.dotc -package core -package tasty +package dotty.tools.tasty /************************************************************ Notation: @@ -505,7 +503,6 @@ object TastyFormat { | DEFAULTparameterized | STABLE | EXTENSION - | GIVEN | PARAMsetter | EXPORTED | OPEN diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyHash.scala b/tasty/src/dotty/tools/tasty/TastyHash.scala similarity index 92% rename from compiler/src/dotty/tools/dotc/core/tasty/TastyHash.scala rename to tasty/src/dotty/tools/tasty/TastyHash.scala index 4ffc1965202e..aff663f42a8d 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyHash.scala +++ b/tasty/src/dotty/tools/tasty/TastyHash.scala @@ -1,4 +1,4 @@ -package dotty.tools.dotc.core.tasty +package dotty.tools.tasty object TastyHash { @@ -20,4 +20,3 @@ object TastyHash { h } } - diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyHeaderUnpickler.scala b/tasty/src/dotty/tools/tasty/TastyHeaderUnpickler.scala similarity index 78% rename from compiler/src/dotty/tools/dotc/core/tasty/TastyHeaderUnpickler.scala rename to tasty/src/dotty/tools/tasty/TastyHeaderUnpickler.scala index 5fd56c18af59..05e421750411 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyHeaderUnpickler.scala +++ b/tasty/src/dotty/tools/tasty/TastyHeaderUnpickler.scala @@ -1,11 +1,8 @@ -package dotty.tools.dotc -package core -package tasty +package dotty.tools.tasty import java.util.UUID -import dotty.tools.dotc.core.tasty.TastyFormat.{MajorVersion, MinorVersion, header} -import dotty.tools.dotc.core.tasty.TastyUnpickler.UnpickleException +import TastyFormat.{MajorVersion, MinorVersion, header} class TastyHeaderUnpickler(reader: TastyReader) { import reader._ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala b/tasty/src/dotty/tools/tasty/TastyReader.scala similarity index 98% rename from compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala rename to tasty/src/dotty/tools/tasty/TastyReader.scala index 2ad0c9ee9d7d..31407f7a4ab8 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyReader.scala +++ b/tasty/src/dotty/tools/tasty/TastyReader.scala @@ -1,11 +1,9 @@ -package dotty.tools -package dotc -package core -package tasty +package dotty.tools.tasty -import TastyBuffer._ import collection.mutable +import TastyBuffer._ + /** A byte array buffer that can be filled with bytes or natural numbers in TASTY format, * and that supports reading and patching addresses represented as natural numbers. * diff --git a/tasty/src/dotty/tools/tasty/UnpickleException.scala b/tasty/src/dotty/tools/tasty/UnpickleException.scala new file mode 100644 index 000000000000..d1eb5f696ed4 --- /dev/null +++ b/tasty/src/dotty/tools/tasty/UnpickleException.scala @@ -0,0 +1,3 @@ +package dotty.tools.tasty + +class UnpickleException(msg: String) extends RuntimeException(msg) diff --git a/tasty/src/dotty/tools/tasty/util/Util.scala b/tasty/src/dotty/tools/tasty/util/Util.scala new file mode 100644 index 000000000000..5726e65773b0 --- /dev/null +++ b/tasty/src/dotty/tools/tasty/util/Util.scala @@ -0,0 +1,14 @@ +package dotty.tools.tasty.util + +import reflect.ClassTag + +object Util { + + /** An array twice the size of given array, with existing elements copied over */ + def dble[T: ClassTag](arr: Array[T]): Array[T] = { + val arr1 = new Array[T](arr.length * 2) + System.arraycopy(arr, 0, arr1, 0, arr.length) + arr1 + } + +}