Skip to content

Commit d9f1d66

Browse files
committed
Provide the macro scala.tasty.Tasty context implicitly
1 parent 4a719d0 commit d9f1d66

File tree

22 files changed

+41
-19
lines changed

22 files changed

+41
-19
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ class Definitions {
686686
def Unpickler_liftedExpr = ctx.requiredMethod("scala.runtime.quoted.Unpickler.liftedExpr")
687687
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")
688688

689+
lazy val TastyTastyType = ctx.requiredClassRef("scala.tasty.Tasty")
690+
def TastyTastyClass(implicit ctx: Context) = TastyTastyType.symbol.asClass
691+
689692
lazy val TastyTopLevelSpliceModule = ctx.requiredModule("scala.tasty.TopLevelSplice")
690693
lazy val TastyTopLevelSplice_tastyContext = TastyTopLevelSpliceModule.requiredMethod("tastyContext")
691694

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ object Splicer {
286286
case NamedArg(_, arg) => interpretTree(arg)
287287
case Ident(name) if env.contains(name) => env(name)
288288

289+
case Inlined(EmptyTree, Nil, expansion) => interpretTree(expansion)
290+
289291
case _ => unexpectedTree(tree)
290292
}
291293

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ trait Implicits { self: Typer =>
626626
EmptyTree
627627
}
628628

629+
def synthesizedTastyContext(formal: Type): Tree =
630+
if (ctx.inTransparentMethod || enclosingInlineds.nonEmpty) ref(defn.TastyTopLevelSplice_tastyContext)
631+
else EmptyTree
632+
629633
/** If `formal` is of the form Eq[T, U], where no `Eq` instance exists for
630634
* either `T` or `U`, synthesize `Eq.eqAny[T, U]` as solution.
631635
*/
@@ -696,7 +700,8 @@ trait Implicits { self: Typer =>
696700
else
697701
trySpecialCase(defn.ClassTagClass, synthesizedClassTag,
698702
trySpecialCase(defn.QuotedTypeClass, synthesizedTypeTag,
699-
trySpecialCase(defn.EqClass, synthesizedEq, failed)))
703+
trySpecialCase(defn.TastyTastyClass, synthesizedTastyContext,
704+
trySpecialCase(defn.EqClass, synthesizedEq, failed))))
700705
}
701706
}
702707

library/src/scala/tasty/TopLevelSplice.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package scala.tasty
33
/** Context in a top level ~ at inline site, intrinsically as `import TopLevelSplice._` */
44
object TopLevelSplice {
55
/** Compiler tasty context available in a top level ~ at inline site */
6-
implicit def tastyContext: Tasty = throw new Exception("Not in transparent macro.")
6+
def tastyContext: Tasty = throw new Exception("Not in transparent macro.")
77
}

tests/neg/tasty-macro-assert/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Asserts {
1212
object Ops
1313

1414
transparent def macroAssert(cond: => Boolean): Unit =
15-
~impl('(cond))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
15+
~impl('(cond))
1616

1717
def impl(cond: Expr[Boolean])(implicit tasty: Tasty): Expr[Unit] = {
1818
import tasty._

tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.tasty.util._
77
object Macros {
88

99
transparent def testMacro: Unit =
10-
~impl(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
10+
~impl
1111

1212
def impl(implicit tasty: Tasty): Expr[Unit] = {
1313
// 2 is a lifted constant

tests/run/i4515b/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.tasty.Tasty
2+
3+
object Macro {
4+
transparent def foo: Unit = ~fooImpl
5+
def fooImpl(implicit tasty: Tasty): quoted.Expr[Unit] = '()
6+
}

tests/run/i4515b/Test_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
Macro.foo
5+
}
6+
}

tests/run/tasty-custom-show/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.tasty.util.{TreeTraverser, Show}
77
object Macros {
88

99
implicit transparent def printOwners[T](x: => T): Unit =
10-
~impl('(x))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
10+
~impl('(x))
1111

1212
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1313
import tasty._

tests/run/tasty-eval/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.tasty.util.TreeTraverser
66
object Macros {
77

88
implicit transparent def foo(i: Int): String =
9-
~impl('(i))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
9+
~impl('(i))
1010

1111
def impl(i: Expr[Int])(implicit tasty: Tasty): Expr[String] = {
1212
value(i).toString.toExpr

tests/run/tasty-extractors-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.tasty._
55
object Macros {
66

77
implicit transparent def printTree[T](x: => T): Unit =
8-
~impl('(x))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
8+
~impl('(x))
99

1010
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1111
import tasty._

tests/run/tasty-extractors-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import scala.tasty._
55
object Macros {
66

77
implicit transparent def printTree[T](x: => T): Unit =
8-
~impl('(x))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
8+
~impl('(x))
99

1010
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1111
import tasty._

tests/run/tasty-extractors-3/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.tasty.util.TreeTraverser
77
object Macros {
88

99
implicit transparent def printTypes[T](x: => T): Unit =
10-
~impl('(x))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
10+
~impl('(x))
1111

1212
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1313
import tasty._

tests/run/tasty-extractors-constants-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.tasty.util._
66
object Macros {
77

88
implicit transparent def testMacro: Unit =
9-
~impl(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
9+
~impl
1010

1111
def impl(implicit tasty: Tasty): Expr[Unit] = {
1212
import tasty._

tests/run/tasty-extractors-owners/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.tasty.util.TreeTraverser
66
object Macros {
77

88
implicit transparent def printOwners[T](x: => T): Unit =
9-
~impl('(x))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
9+
~impl('(x))
1010

1111
def impl[T](x: Expr[T])(implicit tasty: Tasty): Expr[Unit] = {
1212
import tasty._

tests/run/tasty-extractors-types/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.tasty.util.TreeTraverser
66
object Macros {
77

88
implicit transparent def printType[T]: Unit =
9-
~impl('[T])(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
9+
~impl('[T])
1010

1111
def impl[T](x: Type[T])(implicit tasty: Tasty): Expr[Unit] = {
1212
import tasty._

tests/run/tasty-getfile/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.tasty.{Tasty, TopLevelSplice}
44
object SourceFiles {
55

66
implicit transparent def getThisFile: String =
7-
~getThisFileImpl(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
7+
~getThisFileImpl
88

99
private def getThisFileImpl(implicit tasty: Tasty): Expr[String] = {
1010
import tasty._

tests/run/tasty-linenumber-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LineNumber(val value: Int) {
99
object LineNumber {
1010

1111
implicit transparent def line: LineNumber =
12-
~lineImpl(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
12+
~lineImpl
1313

1414
def lineImpl(implicit tasty: Tasty): Expr[LineNumber] = {
1515
import tasty._

tests/run/tasty-linenumber/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class LineNumber(val value: Int) {
99
object LineNumber {
1010

1111
implicit transparent def line[T >: Unit <: Unit]: LineNumber =
12-
~lineImpl('[T])(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
12+
~lineImpl('[T])
1313

1414
def lineImpl(x: Type[Unit])(implicit tasty: Tasty): Expr[LineNumber] = {
1515
import tasty._

tests/run/tasty-location/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ case class Location(owners: List[String])
77
object Location {
88

99
implicit transparent def location: Location =
10-
~impl(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
10+
~impl
1111

1212
def impl(implicit tasty: Tasty): Expr[Location] = {
1313
import tasty._

tests/run/tasty-macro-assert/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Asserts {
1212
object Ops
1313

1414
transparent def macroAssert(cond: => Boolean): Unit =
15-
~impl('(cond))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
15+
~impl('(cond))
1616

1717
def impl(cond: Expr[Boolean])(implicit tasty: Tasty): Expr[Unit] = {
1818
import tasty._

tests/run/tasty-subtyping/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import scala.tasty._
55
object Macros {
66

77
transparent def isTypeEqual[T, U]: Boolean =
8-
~isTypeEqualImpl('[T], '[U])(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
8+
~isTypeEqualImpl('[T], '[U])
99

1010
transparent def isSubTypeOf[T, U]: Boolean =
11-
~isSubTypeOfImpl('[T], '[U])(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~
11+
~isSubTypeOfImpl('[T], '[U])
1212

1313
def isTypeEqualImpl[T, U](t: Type[T], u: Type[U])(implicit tasty: Tasty): Expr[Boolean] = {
1414
import tasty._

0 commit comments

Comments
 (0)