Skip to content

Commit 9890305

Browse files
committed
Create dotty staging library
1 parent f0f8241 commit 9890305

File tree

229 files changed

+193
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+193
-204
lines changed

.drone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ steps:
4040
depends_on: [ clone ]
4141
commands:
4242
- cp -R . /tmp/2/ && cd /tmp/2/
43-
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test"
43+
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;dotty-staging/test ;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test"
4444
- ./project/scripts/bootstrapCmdTests
4545

4646
- name: community_build

build.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ val `dotty-library-bootstrapped` = Build.`dotty-library-bootstrapped`
1010
val `dotty-library-bootstrappedJS` = Build.`dotty-library-bootstrappedJS`
1111
val `dotty-sbt-bridge` = Build.`dotty-sbt-bridge`
1212
val `dotty-sbt-bridge-tests` = Build.`dotty-sbt-bridge-tests`
13+
val `dotty-staging` = Build.`dotty-staging`
1314
val `dotty-language-server` = Build.`dotty-language-server`
1415
val `dotty-bench` = Build.`dotty-bench`
1516
val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped`
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dotty.tools.dotc.consumetasty
22

3+
import java.net.URLClassLoader
4+
35
import dotty.tools.dotc
46
import dotty.tools.dotc.core.Contexts._
5-
import dotty.tools.dotc.quoted.QuoteDriver
67

78
import scala.tasty.file.TastyConsumer
89

910
object ConsumeTasty {
11+
1012
def apply(classpath: String, classes: List[String], tastyConsumer: TastyConsumer): Unit = {
1113
if (classes.isEmpty)
1214
throw new IllegalArgumentException("Parameter classes should no be empty")
@@ -16,9 +18,23 @@ object ConsumeTasty {
1618
new TastyFromClass(tastyConsumer)
1719
}
1820

19-
val currentClasspath = QuoteDriver.currentClasspath(getClass.getClassLoader)
21+
val currentClasspath = getCurrentClasspath(getClass.getClassLoader)
2022
import java.io.File.{ pathSeparator => sep }
2123
val args = "-from-tasty" :: "-Yretain-trees" :: "-classpath" :: s"$classpath$sep$currentClasspath" :: classes
2224
(new Consume).process(args.toArray)
2325
}
26+
27+
private def getCurrentClasspath(cl: ClassLoader): String = {
28+
val classpath0 = System.getProperty("java.class.path")
29+
cl match {
30+
case cl: URLClassLoader =>
31+
// Loads the classes loaded by this class loader
32+
// When executing `run` or `test` in sbt the classpath is not in the property java.class.path
33+
import java.nio.file.Paths
34+
val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString)
35+
newClasspath.mkString("", java.io.File.pathSeparator, if (classpath0 == "") "" else java.io.File.pathSeparator + classpath0)
36+
case _ => classpath0
37+
}
38+
}
39+
2440
}

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dotty.tools.dotc.core.Types._
1414
import dotty.tools.dotc.core.tasty.TreePickler.Hole
1515
import dotty.tools.dotc.core.tasty.{PositionPickler, TastyPickler, TastyPrinter, TastyString}
1616
import dotty.tools.dotc.core.tasty.TreeUnpickler.UnpickleMode
17-
import dotty.tools.dotc.quoted.ToolboxImpl
17+
import dotty.tools.dotc.quoted.QuoteContext
1818
import dotty.tools.dotc.tastyreflect.ReflectionImpl
1919

2020
import scala.internal.quoted._
@@ -38,14 +38,14 @@ object PickledQuotes {
3838
/** Transform the expression into its fully spliced Tree */
3939
def quotedExprToTree[T](expr: quoted.Expr[T])(implicit ctx: Context): Tree = {
4040
val expr1 = expr.asInstanceOf[TastyTreeExpr[Tree]]
41-
ToolboxImpl.checkScopeId(expr1.scopeId)
41+
QuoteContext.checkScopeId(expr1.scopeId)
4242
healOwner(expr1.tree)
4343
}
4444

4545
/** Transform the expression into its fully spliced TypeTree */
4646
def quotedTypeToTree(tpe: quoted.Type[_])(implicit ctx: Context): Tree = {
4747
val tpe1 = tpe.asInstanceOf[TreeType[Tree]]
48-
ToolboxImpl.checkScopeId(tpe1.scopeId)
48+
QuoteContext.checkScopeId(tpe1.scopeId)
4949
healOwner(tpe1.typeTree)
5050
}
5151

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import scala.collection.mutable.ListBuffer
3131
import scala.collection.mutable
3232
import config.Printers.pickling
3333
import core.quoted.PickledQuotes
34-
import dotty.tools.dotc.quoted.ToolboxImpl
34+
import dotty.tools.dotc.quoted.QuoteContext
3535

3636
import scala.quoted
3737
import scala.internal.quoted.{TastyTreeExpr, TreeType}
@@ -1274,8 +1274,8 @@ class TreeUnpickler(reader: TastyReader,
12741274
val args = until(end)(readTerm())
12751275
val splice = splices(idx)
12761276
def wrap(arg: Tree) =
1277-
if (arg.isTerm) given (qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, ToolboxImpl.scopeId)
1278-
else new TreeType(arg, ToolboxImpl.scopeId)
1277+
if (arg.isTerm) given (qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
1278+
else new TreeType(arg, QuoteContext.scopeId)
12791279
val reifiedArgs = args.map(wrap)
12801280
val filled = if (isType) {
12811281
val quotedType = splice.asInstanceOf[Seq[Any] => quoted.Type[_]](reifiedArgs)

compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala

-9
This file was deleted.

compiler/src/dotty/tools/dotc/quoted/QuoteContext.scala

+12
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ object QuoteContext {
88
def apply() given Context: scala.quoted.QuoteContext =
99
new scala.quoted.QuoteContext(ReflectionImpl(the[Context]))
1010

11+
type ScopeId = Int
12+
13+
private[dotty] def checkScopeId(id: ScopeId) given Context: Unit = {
14+
if (id != scopeId)
15+
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
16+
}
17+
18+
// TODO Explore more fine grained scope ids.
19+
// This id can only differentiate scope extrusion from one compiler instance to another.
20+
private[dotty] def scopeId given Context: ScopeId =
21+
the[Context].outersIterator.toList.last.hashCode()
22+
1123
}

compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala

-46
This file was deleted.

compiler/src/dotty/tools/dotc/transform/Splicer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import dotty.tools.repl.AbstractFileClassLoader
2525

2626
import scala.reflect.ClassTag
2727

28-
import dotty.tools.dotc.quoted.{QuoteContext, ToolboxImpl}
28+
import dotty.tools.dotc.quoted.QuoteContext
2929

3030
/** Utility class to splice quoted expressions */
3131
object Splicer {
@@ -251,10 +251,10 @@ object Splicer {
251251
}
252252

253253
private def interpretQuote(tree: Tree)(implicit env: Env): Object =
254-
new scala.internal.quoted.TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span), ToolboxImpl.scopeId)
254+
new scala.internal.quoted.TastyTreeExpr(Inlined(EmptyTree, Nil, tree).withSpan(tree.span), QuoteContext.scopeId)
255255

256256
private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
257-
new scala.internal.quoted.TreeType(tree, ToolboxImpl.scopeId)
257+
new scala.internal.quoted.TreeType(tree, QuoteContext.scopeId)
258258

259259
private def interpretLiteral(value: Any)(implicit env: Env): Object =
260260
value.asInstanceOf[Object]

compiler/test/dotty/Properties.scala

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ object Properties {
5050
/** dotty-compiler jar */
5151
def dottyCompiler: String = sys.props("dotty.tests.classes.dottyCompiler")
5252

53+
/** dotty-staging jar */
54+
def dottyStaging: String = sys.props("dotty.tests.classes.dottyStaging")
55+
5356
/** compiler-interface jar */
5457
def compilerInterface: String = sys.props("dotty.tests.classes.compilerInterface")
5558

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
3939
implicit val testGroup: TestGroup = TestGroup("compilePosWithCompiler")
4040
aggregateTests(
4141
compileFilesInDir("tests/pos-with-compiler", withCompilerOptions),
42+
compileFilesInDir("tests/pos-staging", withStagingOptions),
4243
compileDir("compiler/src/dotty/tools/dotc/ast", withCompilerOptions),
4344
compileDir("compiler/src/dotty/tools/dotc/config", withCompilerOptions),
4445
compileDir("compiler/src/dotty/tools/dotc/core", withCompilerOptions),
@@ -103,7 +104,10 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
103104

104105
@Test def negWithCompiler: Unit = {
105106
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
106-
compileFilesInDir("tests/neg-with-compiler", withCompilerOptions).checkExpectedErrors()
107+
aggregateTests(
108+
compileFilesInDir("tests/neg-with-compiler", withCompilerOptions),
109+
compileFilesInDir("tests/neg-staging", withStagingOptions),
110+
).checkExpectedErrors()
107111
}
108112

109113
// Run tests -----------------------------------------------------------------
@@ -120,6 +124,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
120124
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
121125
aggregateTests(
122126
compileFilesInDir("tests/run-with-compiler", withCompilerOptions),
127+
compileFilesInDir("tests/run-staging", withStagingOptions),
123128
compileDir("tests/run-with-compiler-custom-args/tasty-interpreter", withCompilerOptions)
124129
).checkRuns()
125130
}

compiler/test/dotty/tools/repl/ReplTest.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import dotty.tools.dotc.reporting.MessageRendering
99
import org.junit.{After, Before}
1010

1111

12-
class ReplTest private (out: ByteArrayOutputStream) extends ReplDriver(
13-
Array("-classpath", TestConfiguration.basicClasspath, "-color:never"),
14-
new PrintStream(out)
15-
) with MessageRendering {
12+
class ReplTest private (settings: Array[String], out: ByteArrayOutputStream)
13+
extends ReplDriver(settings, new PrintStream(out)) with MessageRendering {
1614

17-
def this() = this(new ByteArrayOutputStream)
15+
def this(classpath: String) = this(Array("-classpath", classpath, "-color:never"), new ByteArrayOutputStream)
16+
17+
def this() = this(TestConfiguration.basicClasspath)
1818

1919
/** Get the stored output from `out`, resetting the buffer */
2020
def storedOutput(): String = {

compiler/test/dotty/tools/repl/ScriptedTests.scala

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import org.junit.experimental.categories.Category
1111

1212
import scala.collection.mutable.ArrayBuffer
1313
import scala.io.Source
14-
1514
import dotc.reporting.MessageRendering
15+
import dotty.tools.vulpix.TestConfiguration
1616

1717
/** Runs all tests contained in `compiler/test-resources/repl/` */
18-
class ScriptedTests extends ReplTest with MessageRendering {
18+
class ScriptedReplTests(classpath: String) extends ReplTest(classpath) with MessageRendering {
1919

20-
private def scripts(path: String): Array[JFile] = {
20+
protected def scripts(path: String): Array[JFile] = {
2121
val dir = new JFile(getClass.getResource(path).getPath)
2222
assert(dir.exists && dir.isDirectory, "Couldn't load scripts dir")
2323
dir.listFiles
2424
}
2525

26-
private def testFile(f: JFile): Unit = {
26+
protected def testFile(f: JFile): Unit = {
2727
val prompt = "scala>"
2828
val lines = Source.fromFile(f, "UTF-8").getLines().buffered
2929

@@ -89,11 +89,13 @@ class ScriptedTests extends ReplTest with MessageRendering {
8989
fail(s"Error in file $f, expected output did not match actual")
9090
}
9191
}
92+
}
93+
94+
/** Runs all tests contained in `compiler/test-resources/repl/` */
95+
class ScriptedTests extends ScriptedReplTests(TestConfiguration.basicClasspath) {
9296

9397
@Test def replTests = scripts("/repl").foreach(testFile)
9498

9599
@Test def typePrinterTests = scripts("/type-printer").foreach(testFile)
96100

97-
@Category(Array(classOf[BootstrappedOnlyTests]))
98-
@Test def replMacrosTests = scripts("/repl-macros").foreach(testFile)
99101
}

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ object TestConfiguration {
3535
Properties.dottyCompiler
3636
))
3737

38+
val withStagingClasspath = mkClasspath(List(
39+
Properties.scalaLibrary,
40+
Properties.scalaAsm,
41+
Properties.jlineTerminal,
42+
Properties.jlineReader,
43+
Properties.compilerInterface,
44+
Properties.dottyInterfaces,
45+
Properties.dottyLibrary,
46+
Properties.dottyStaging,
47+
Properties.dottyCompiler
48+
))
49+
3850
def mkClasspath(classpaths: List[String]): String =
3951
classpaths.map({ p =>
4052
val file = new java.io.File(p)
@@ -48,6 +60,8 @@ object TestConfiguration {
4860
val defaultOptions = TestFlags(basicClasspath, commonOptions)
4961
val withCompilerOptions =
5062
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
63+
val withStagingOptions =
64+
defaultOptions.withClasspath(withStagingClasspath).withRunClasspath(withStagingClasspath)
5165
val allowDeepSubtypes = defaultOptions without "-Yno-deep-subtypes"
5266
val allowDoubleBindings = defaultOptions without "-Yno-double-bindings"
5367
val picklingOptions = defaultOptions and (

dist/bin/common

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ find_lib () {
107107
DOTTY_COMP=$(find_lib "*dotty-compiler*")
108108
DOTTY_INTF=$(find_lib "*dotty-interfaces*")
109109
DOTTY_LIB=$(find_lib "*dotty-library*")
110+
DOTTY_STAGING=$(find_lib "*dotty-staging*")
110111
SCALA_ASM=$(find_lib "*scala-asm*")
111112
SCALA_LIB=$(find_lib "*scala-library*")
112113
SBT_INTF=$(find_lib "*compiler-interface*")

dist/bin/dotr

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ elif [ $execute_repl == true ] || [ ${#residual_args[@]} -ne 0 ]; then
102102
echo "warning: multiple classpaths are found, dotr only use the last one."
103103
fi
104104
if [ $with_compiler == true ]; then
105-
cp_arg+="$PSEP$DOTTY_COMP$PSEP$DOTTY_INTF$PSEP$SCALA_ASM"
105+
cp_arg+="$PSEP$DOTTY_COMP$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$DOTTY_STAGING"
106106
fi
107107
eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${jvm_options[@]}" "${residual_args[@]}"
108108
else

library/src-non-bootstrapped/scala/quoted/package.scala

-51
This file was deleted.

0 commit comments

Comments
 (0)