Skip to content

Create dotty-staging library #7080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 29, 2019
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ steps:
depends_on: [ clone ]
commands:
- cp -R . /tmp/2/ && cd /tmp/2/
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test"
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;dotty-staging/test ;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test"
- ./project/scripts/bootstrapCmdTests

- name: community_build
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ val `dotty-library-bootstrapped` = Build.`dotty-library-bootstrapped`
val `dotty-library-bootstrappedJS` = Build.`dotty-library-bootstrappedJS`
val `dotty-sbt-bridge` = Build.`dotty-sbt-bridge`
val `dotty-sbt-bridge-tests` = Build.`dotty-sbt-bridge-tests`
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`
Expand Down
20 changes: 18 additions & 2 deletions compiler/src/dotty/tools/dotc/consumetasty/ConsumeTasty.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dotty.tools.dotc.consumetasty

import java.net.URLClassLoader

import dotty.tools.dotc
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.quoted.QuoteDriver

import scala.tasty.file.TastyConsumer

object ConsumeTasty {

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

val currentClasspath = QuoteDriver.currentClasspath(getClass.getClassLoader)
val currentClasspath = getCurrentClasspath(getClass.getClassLoader)
import java.io.File.{ pathSeparator => sep }
val args = "-from-tasty" :: "-Yretain-trees" :: "-classpath" :: s"$classpath$sep$currentClasspath" :: classes
(new Consume).process(args.toArray)
}

private def getCurrentClasspath(cl: ClassLoader): String = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be duplicated with QuoteDriver ? (Unrelated but this implementation looks very fragile to me, this makes way too many assumptions about how classloaders are setup, which might be broken by sbt 1.3 uses of layered classloaders for example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into it in another PR. For now we keep the same behaviour as before.

val classpath0 = System.getProperty("java.class.path")
cl match {
case cl: URLClassLoader =>
// Loads the classes loaded by this class loader
// When executing `run` or `test` in sbt the classpath is not in the property java.class.path
import java.nio.file.Paths
val newClasspath = cl.getURLs.map(url => Paths.get(url.toURI).toString)
newClasspath.mkString("", java.io.File.pathSeparator, if (classpath0 == "") "" else java.io.File.pathSeparator + classpath0)
case _ => classpath0
}
}

}
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.TreeUnpickler.UnpickleMode
import dotty.tools.dotc.quoted.ToolboxImpl
import dotty.tools.dotc.quoted.QuoteContext
import dotty.tools.dotc.tastyreflect.ReflectionImpl

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

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.collection.mutable.ListBuffer
import scala.collection.mutable
import config.Printers.pickling
import core.quoted.PickledQuotes
import dotty.tools.dotc.quoted.ToolboxImpl
import dotty.tools.dotc.quoted.QuoteContext

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

This file was deleted.

12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ object QuoteContext {
def apply() given Context: scala.quoted.QuoteContext =
new scala.quoted.QuoteContext(ReflectionImpl(the[Context]))

type ScopeId = Int

private[dotty] def checkScopeId(id: ScopeId) given Context: Unit = {
if (id != scopeId)
throw new scala.quoted.ScopeException("Cannot call `scala.quoted.staging.run(...)` within a macro or another `run(...)`")
}

// TODO Explore more fine grained scope ids.
// This id can only differentiate scope extrusion from one compiler instance to another.
private[dotty] def scopeId given Context: ScopeId =
the[Context].outersIterator.toList.last.hashCode()

}
46 changes: 0 additions & 46 deletions compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala

This file was deleted.

6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import dotty.tools.repl.AbstractFileClassLoader

import scala.reflect.ClassTag

import dotty.tools.dotc.quoted.{QuoteContext, ToolboxImpl}
import dotty.tools.dotc.quoted.QuoteContext

/** Utility class to splice quoted expressions */
object Splicer {
Expand Down Expand Up @@ -251,10 +251,10 @@ object Splicer {
}

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

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

private def interpretLiteral(value: Any)(implicit env: Env): Object =
value.asInstanceOf[Object]
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotty/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ object Properties {
/** dotty-compiler jar */
def dottyCompiler: String = sys.props("dotty.tests.classes.dottyCompiler")

/** dotty-staging jar */
def dottyStaging: String = sys.props("dotty.tests.classes.dottyStaging")

/** compiler-interface jar */
def compilerInterface: String = sys.props("dotty.tests.classes.compilerInterface")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
implicit val testGroup: TestGroup = TestGroup("compilePosWithCompiler")
aggregateTests(
compileFilesInDir("tests/pos-with-compiler", withCompilerOptions),
compileFilesInDir("tests/pos-staging", withStagingOptions),
compileDir("compiler/src/dotty/tools/dotc/ast", withCompilerOptions),
compileDir("compiler/src/dotty/tools/dotc/config", withCompilerOptions),
compileDir("compiler/src/dotty/tools/dotc/core", withCompilerOptions),
Expand Down Expand Up @@ -103,7 +104,10 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {

@Test def negWithCompiler: Unit = {
implicit val testGroup: TestGroup = TestGroup("compileNegWithCompiler")
compileFilesInDir("tests/neg-with-compiler", withCompilerOptions).checkExpectedErrors()
aggregateTests(
compileFilesInDir("tests/neg-with-compiler", withCompilerOptions),
compileFilesInDir("tests/neg-staging", withStagingOptions),
).checkExpectedErrors()
}

// Run tests -----------------------------------------------------------------
Expand All @@ -120,6 +124,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
aggregateTests(
compileFilesInDir("tests/run-with-compiler", withCompilerOptions),
compileFilesInDir("tests/run-staging", withStagingOptions),
compileDir("tests/run-with-compiler-custom-args/tasty-interpreter", withCompilerOptions)
).checkRuns()
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import org.junit.{After, Before}
import org.junit.Assert._


class ReplTest(withCompiler: Boolean = false, out: ByteArrayOutputStream = new ByteArrayOutputStream) extends ReplDriver(
class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new ByteArrayOutputStream) extends ReplDriver(
Array(
"-classpath",
if (withCompiler)
TestConfiguration.withCompilerClasspath
if (withStaging)
TestConfiguration.withStagingClasspath
else
TestConfiguration.basicClasspath,
"-color:never"),
Expand Down
5 changes: 5 additions & 0 deletions compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ object TestConfiguration {
Properties.dottyCompiler
))

lazy val withStagingClasspath =
withCompilerClasspath + File.pathSeparator + mkClasspath(List(Properties.dottyStaging))

def mkClasspath(classpaths: List[String]): String =
classpaths.map({ p =>
val file = new java.io.File(p)
Expand All @@ -48,6 +51,8 @@ object TestConfiguration {
val defaultOptions = TestFlags(basicClasspath, commonOptions)
val withCompilerOptions =
defaultOptions.withClasspath(withCompilerClasspath).withRunClasspath(withCompilerClasspath)
lazy val withStagingOptions =
defaultOptions.withClasspath(withStagingClasspath).withRunClasspath(withStagingClasspath)
val allowDeepSubtypes = defaultOptions without "-Yno-deep-subtypes"
val allowDoubleBindings = defaultOptions without "-Yno-double-bindings"
val picklingOptions = defaultOptions and (
Expand Down
1 change: 1 addition & 0 deletions dist/bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ find_lib () {
DOTTY_COMP=$(find_lib "*dotty-compiler*")
DOTTY_INTF=$(find_lib "*dotty-interfaces*")
DOTTY_LIB=$(find_lib "*dotty-library*")
DOTTY_STAGING=$(find_lib "*dotty-staging*")
SCALA_ASM=$(find_lib "*scala-asm*")
SCALA_LIB=$(find_lib "*scala-library*")
SBT_INTF=$(find_lib "*compiler-interface*")
Expand Down
2 changes: 1 addition & 1 deletion dist/bin/dotr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
cp_arg+="$PSEP$DOTTY_COMP$PSEP$DOTTY_INTF$PSEP$SCALA_ASM$DOTTY_STAGING"
fi
eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$cp_arg\"" "${jvm_options[@]}" "${residual_args[@]}"
else
Expand Down
51 changes: 0 additions & 51 deletions library/src-non-bootstrapped/scala/quoted/package.scala

This file was deleted.

8 changes: 0 additions & 8 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@ package scala
package quoted {

import scala.quoted.show.SyntaxHighlight
import scala.quoted.staging.Toolbox

sealed trait Expr[+T] {

/** Evaluate the contents of this expression and return the result.
*
* May throw a FreeVariableError on expressions that came from a macro.
*/
@deprecated("Use scala.quoted.run", "")
final def run(implicit toolbox: Toolbox): T = toolbox.run(_ => this)

/** Show a source code like representation of this expression without syntax highlight */
def show(implicit qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)

Expand Down
4 changes: 4 additions & 0 deletions library/src/scala/quoted/ScopeException.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package scala.quoted

/** Excetion thrown when an Expr or Type is used ouside of the scope where it is valid */
class ScopeException(msg: String) extends Exception(msg)
3 changes: 0 additions & 3 deletions library/src/scala/quoted/staging/RunScopeException.scala

This file was deleted.

This file was deleted.

Loading