Skip to content

Commit 95ec081

Browse files
Merge pull request #4673 from dotty-staging/remove-tasty-universe
Remove tasty.Universe and use tasty.Tasty directly
2 parents e3960ae + 59a74e9 commit 95ec081

File tree

30 files changed

+107
-126
lines changed

30 files changed

+107
-126
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ class Definitions {
667667
def Unpickler_liftedExpr = ctx.requiredMethod("scala.runtime.quoted.Unpickler.liftedExpr")
668668
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")
669669

670-
lazy val TastyUniverseModule = ctx.requiredModule("scala.tasty.Universe")
671-
def TastyUniverseModuleClass(implicit ctx: Context) = TastyUniverseModule.symbol.asClass
670+
lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice")
671+
def TastyTopLevelSpliceModuleClass(implicit ctx: Context) = TastyTopLevelSpliceModule.symbol.asClass
672672

673-
lazy val TastyUniverse_compilationUniverseR = TastyUniverseModule.requiredMethod("compilationUniverse")
674-
def TastyUniverse_compilationUniverse(implicit ctx: Context) = TastyUniverse_compilationUniverseR.symbol
673+
lazy val TastyTopLevelSplice_compilationTopLevelSpliceR = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
674+
def TastyTopLevelSplice_compilationTopLevelSplice(implicit ctx: Context) = TastyTopLevelSplice_compilationTopLevelSpliceR.symbol
675675

676676
lazy val EqType = ctx.requiredClassRef("scala.Eq")
677677
def EqClass(implicit ctx: Context) = EqType.symbol.asClass

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DecompilationPrinter extends Phase {
4141
new TastyPrinter(unit.pickled.head._2).printContents()
4242
} else {
4343
out.println(s"/** Decompiled from $unit */")
44-
out.println(TastyImpl.showSourceCode.showTree(unit.tpdTree)(ctx))
44+
out.println(new TastyImpl(ctx).showSourceCode.showTree(unit.tpdTree)(ctx))
4545
}
4646
}
4747
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class QuoteDriver extends Driver {
4242
def show(expr: Expr[_], settings: Settings[Show]): String = {
4343
def show(tree: Tree, ctx: Context): String = {
4444
val tree1 = if (settings.rawTree) tree else (new TreeCleaner).transform(tree)(ctx)
45-
TastyImpl.showSourceCode.showTree(tree1)(ctx)
45+
new TastyImpl(ctx).showSourceCode.showTree(tree1)(ctx)
4646
}
4747
withTree(expr, show, settings)
4848
}

compiler/src/dotty/tools/dotc/tastyreflect/CompilationUniverse.scala

Lines changed: 0 additions & 7 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import dotty.tools.dotc.reporting.Reporter
1111
import dotty.tools.dotc.reporting.diagnostic.MessageContainer
1212
import dotty.tools.dotc.util.SourcePosition
1313

14-
import scala.{quoted, tasty}
14+
import scala.quoted
1515
import scala.reflect.ClassTag
1616
import scala.tasty.util.{Show, ShowExtractors, ShowSourceCode}
1717

18-
object TastyImpl extends scala.tasty.Tasty {
18+
class TastyImpl(val rootContext: Contexts.Context) extends scala.tasty.Tasty { self =>
1919

2020
// ===== Quotes ===================================================
2121

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
516516
outer.enteredSyms.foreach(registerCapturer)
517517

518518
if (ctx.owner.owner.is(Macro)) {
519-
registerCapturer(defn.TastyUniverse_compilationUniverse)
519+
registerCapturer(defn.TastyTopLevelSplice_compilationTopLevelSplice)
520520
// Force a macro to have the context in first position
521-
forceCapture(defn.TastyUniverse_compilationUniverse)
521+
forceCapture(defn.TastyTopLevelSplice_compilationTopLevelSplice)
522522
// Force all parameters of the macro to be created in the definition order
523523
outer.enteredSyms.reverse.foreach(forceCapture)
524524
}
@@ -649,7 +649,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
649649

650650
private def isStage0Value(sym: Symbol)(implicit ctx: Context): Boolean =
651651
(sym.is(Inline) && sym.owner.is(Macro) && !defn.isFunctionType(sym.info)) ||
652-
sym == defn.TastyUniverse_compilationUniverse // intrinsic value at stage 0
652+
sym == defn.TastyTopLevelSplice_compilationTopLevelSplice // intrinsic value at stage 0
653653

654654
private def liftList(list: List[Tree], tpe: Type)(implicit ctx: Context): Tree = {
655655
list.foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import dotty.tools.dotc.core.quoted._
1515
import dotty.tools.dotc.core.Types._
1616
import dotty.tools.dotc.core.Symbols._
1717
import dotty.tools.dotc.core.TypeErasure
18-
import dotty.tools.dotc.tastyreflect.CompilationUniverse
18+
import dotty.tools.dotc.tastyreflect.TastyImpl
1919

2020
import scala.util.control.NonFatal
2121
import dotty.tools.dotc.util.Positions.Position
@@ -38,7 +38,7 @@ object Splicer {
3838
val liftedArgs = getLiftedArgs(call, bindings)
3939
val interpreter = new Interpreter(pos, classLoader)
4040
val interpreted = interpreter.interpretCallToSymbol[Seq[Any] => Object](call.symbol)
41-
val tctx = new CompilationUniverse(ctx)
41+
val tctx = new TastyImpl(ctx)
4242
evaluateMacro(pos) {
4343
// Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
4444
val evaluated = interpreted.map(lambda => lambda(tctx :: liftedArgs).asInstanceOf[scala.quoted.Expr[Nothing]])

library/src/scala/tasty/Tasty.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ abstract class Tasty { tasty =>
3434
}
3535
implicit def ContextDeco(ctx: Context): ContextAPI
3636

37+
implicit def rootContext: Context
38+
3739
// ===== Id =======================================================
3840

3941
type Id
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package scala.tasty
2+
3+
/** Context in a top level ~ at inline site, intrinsically as `import TopLevelSplice._` */
4+
object TopLevelSplice {
5+
/** Compiler tasty context available in a top level ~ at inline site */
6+
implicit def tastyContext: Tasty = throw new Exception("Not in inline macro.")
7+
}

library/src/scala/tasty/Universe.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)