Skip to content

Use given instead of implicit #7177

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
url = https://github.com/dotty-staging/scala-xml
[submodule "community-build/community-projects/shapeless"]
path = community-build/community-projects/shapeless
url = https://github.com/milessabin/shapeless
branch = shapeless-3
url = https://github.com/dotty-staging/shapeless
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@milessabin, to make some small changes to shapeless I forked it and used a new branch. I will upstream those changes once this PR is merged.

[submodule "community-build/community-projects/xml-interpolator"]
path = community-build/community-projects/xml-interpolator
url = https://github.com/lampepfl/xml-interpolator.git
Expand Down
1 change: 1 addition & 0 deletions docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ Here’s a compiler that maps an expression given in the interpreted
language to quoted Scala code of type `Expr[Int]`.
The compiler takes an environment that maps variable names to Scala `Expr`s.
```scala
import scala.quoted._
import given scala.quoted._

def compile(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package dotty.internal

import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._
import reflect._

Expand Down
4 changes: 3 additions & 1 deletion library/src-bootstrapped/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package object quoted {
given autoToExpr[T] as Conversion[T, Expr[T]] given Liftable[T], QuoteContext = _.toExpr
}

implicit object ExprOps {
given ExprOps {

/** Lift a value into an expression containing the construction of that value */
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)

/** Lifts this sequence of expressions into an expression of a sequence
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ package quoted {
* Given list of statements `s1 :: s2 :: ... :: Nil` and an expression `e` the resulting expression
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
*/
def block[T](statements: List[Expr[_]], expr: Expr[T])(implicit qctx: QuoteContext): Expr[T] = {
def block[T](statements: List[Expr[_]], expr: Expr[T]) given (qctx: QuoteContext): Expr[T] = {
import qctx.tasty._
Block(statements.map(_.unseal), expr.unseal).seal.asInstanceOf[Expr[T]]
}
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package quoted {
type `$splice` = T

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

/** Show a source code like representation of this type */
def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
def show(syntaxHighlight: SyntaxHighlight) given (qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)

}

Expand Down
20 changes: 10 additions & 10 deletions library/src/scala/quoted/ValueOfExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ trait ValueOfExpr[T] {

object ValueOfExpr {

implicit val ValueOfExpr_Unit_delegate: ValueOfExpr[Unit] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Boolean_delegate: ValueOfExpr[Boolean] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Byte_delegate: ValueOfExpr[Byte] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Short_delegate: ValueOfExpr[Short] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Int_delegate: ValueOfExpr[Int] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Long_delegate: ValueOfExpr[Long] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Float_delegate: ValueOfExpr[Float] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Double_delegate: ValueOfExpr[Double] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_Char_delegate: ValueOfExpr[Char] = new PrimitiveValueOfExpr
implicit val ValueOfExpr_String_delegate: ValueOfExpr[String] = new PrimitiveValueOfExpr
given ValueOfExpr_Unit_delegate as ValueOfExpr[Unit] = new PrimitiveValueOfExpr
given ValueOfExpr_Boolean_delegate as ValueOfExpr[Boolean] = new PrimitiveValueOfExpr
given ValueOfExpr_Byte_delegate as ValueOfExpr[Byte] = new PrimitiveValueOfExpr
given ValueOfExpr_Short_delegate as ValueOfExpr[Short] = new PrimitiveValueOfExpr
given ValueOfExpr_Int_delegate as ValueOfExpr[Int] = new PrimitiveValueOfExpr
given ValueOfExpr_Long_delegate as ValueOfExpr[Long] = new PrimitiveValueOfExpr
given ValueOfExpr_Float_delegate as ValueOfExpr[Float] = new PrimitiveValueOfExpr
given ValueOfExpr_Double_delegate as ValueOfExpr[Double] = new PrimitiveValueOfExpr
given ValueOfExpr_Char_delegate as ValueOfExpr[Char] = new PrimitiveValueOfExpr
given ValueOfExpr_String_delegate as ValueOfExpr[String] = new PrimitiveValueOfExpr

private class PrimitiveValueOfExpr[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends ValueOfExpr[T] {
/** Lift a quoted primitive value `'{ n }` into `n` */
Expand Down
1 change: 1 addition & 0 deletions tests/neg-macros/inline-case-objects/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._

object Macros {
def impl(foo: Any) given QuoteContext: Expr[String] = foo.getClass.getCanonicalName.toExpr
Expand Down
1 change: 1 addition & 0 deletions tests/neg-macros/inline-option/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._

object Macro {
def impl(opt: Option[Int]) given QuoteContext: Expr[Int] = opt match {
Expand Down
1 change: 1 addition & 0 deletions tests/neg-macros/quote-macro-complex-arg-0.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Macros {
inline def foo(inline i: Int, dummy: Int, j: Int): Int = ${ bar(i + 1, 'j) } // error: i + 1 is not a parameter or field reference
Expand Down
1 change: 1 addition & 0 deletions tests/neg-with-compiler/GenericNumLits/Even_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scala.util.FromDigits
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

case class Even(n: Int)
Expand Down
1 change: 1 addition & 0 deletions tests/neg/BigFloat/BigFloat_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test
import scala.util.FromDigits
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

case class BigFloat(mantissa: BigInt, exponent: Int) {
Expand Down
1 change: 1 addition & 0 deletions tests/neg/GenericNumLits/Even_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scala.util.FromDigits
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

case class Even(n: Int)
Expand Down
1 change: 1 addition & 0 deletions tests/pos-macros/quote-whitebox-2/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._

object Macro {

Expand Down
1 change: 1 addition & 0 deletions tests/pos/i5547.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object scalatest {
inline def assert1(condition: => Boolean): Unit =
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i6214.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
object Test {
def res(x: quoted.Expr[Int]) given QuoteContext: quoted.Expr[Int] = x match {
case '{ val a: Int = $y; 1} => y // owner of `y` is `res`
Expand Down
1 change: 1 addition & 0 deletions tests/pos/quote-lift.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Test {
given as QuoteContext = ???
Expand Down
1 change: 1 addition & 0 deletions tests/pos/quote-liftable.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

def test given QuoteContext = {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scala.quoted._

import given scala.quoted._

object Foo {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Foo {

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/f-interpolator-neg/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import given scala.quoted.autolift._
import scala.quoted.matching._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// using staging reflection

import scala.quoted._
import given scala.quoted._

object TypeToolbox {
/** are the two types equal? */
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/i5629/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Macros {

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/inline-case-objects/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._

object Macros {
def impl(foo: Any) given QuoteContext: Expr[String] = foo.getClass.getCanonicalName.toExpr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._

object E {

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/quote-matcher-runtime/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._


Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/quote-matcher-symantics-1/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

object Macros {
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/quote-matcher-symantics-2/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

object Macros {
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/quote-matcher-symantics-3/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.matching._

object Macros {
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/quote-toExprOfTuple/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Macro {
inline def t2[T0, T1](t0: T0, t1: T1): (T0, T1) = ${ impl2('{t0}, '{t1}) }
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/reflect-inline/assert_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object api {
inline def (inline x: String) stripMargin: String =
Expand Down
3 changes: 1 addition & 2 deletions tests/run-macros/reflect-isFunctionType/macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import scala.quoted._

import given scala.quoted._

inline def isFunctionType[T:Type]: Boolean = ${ isFunctionTypeImpl('[T]) }

Expand Down Expand Up @@ -30,4 +30,3 @@ def isDependentFunctionTypeImpl[T](tp: Type[T]) given (qctx: QuoteContext): Expr
import qctx.tasty._
tp.unseal.tpe.isDependentFunctionType.toExpr
}

1 change: 1 addition & 0 deletions tests/run-macros/reflect-typeChecks/assert_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object scalatest {

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-dealias/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Macros {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import given scala.quoted.autolift._

import scala.quoted.matching._
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-interpolation-1/Macro.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.language.implicitConversions
import given scala.quoted.autolift._

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-macro-positions/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object Macros {

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-simplified/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import scala.annotation.tailrec
import scala.quoted._
import given scala.quoted._

object Macros {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import given scala.quoted.autolift._
import scala.quoted.matching._

Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/type-show/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._

object TypeToolbox {
inline def show[A]: String = ${ showImpl('[A]) }
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/xml-interpolation-2/XmlQuote_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import given scala.quoted.autolift._


Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3847-b.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._
import scala.reflect.ClassTag

Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3847.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._
import scala.reflect.ClassTag

Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947b.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947b2.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947b3.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947c.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._

object Test {
Expand Down
1 change: 1 addition & 0 deletions tests/run-staging/i3947d.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import scala.quoted._
import given scala.quoted._
import scala.quoted.staging._
object Test {
delegate for Toolbox = Toolbox.make(getClass.getClassLoader)
Expand Down
Loading