Skip to content

Commit b12fa30

Browse files
committed
remove usingquotes change
1 parent 40c9c1c commit b12fa30

File tree

7 files changed

+82
-97
lines changed

7 files changed

+82
-97
lines changed

library/src/scala/quoted/Quotes.scala

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,11 +2533,17 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
25332533
/** Convert this `TypeRepr` to an `Type[?]`
25342534
*
25352535
* Usage:
2536-
* ```scala sc:usingquotes
2537-
* val typeRepr: TypeRepr = ???
2538-
* typeRepr.asType match
2539-
* case '[t] =>
2540-
* '{ val x: t = ??? }
2536+
* ```scala
2537+
* //{
2538+
* def f(using Quotes) = {
2539+
* val typeRepr: TypeRepr = ???
2540+
* //}
2541+
* typeRepr.asType match
2542+
* case '[t] =>
2543+
* '{ val x: t = ??? }
2544+
* //{
2545+
* }
2546+
* //}
25412547
* ```
25422548
*/
25432549
def asType: Type[?]
@@ -4275,7 +4281,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
42754281
/** Is this symbol marked as a macro. An inline method containing top level splices */
42764282
def Macro: Flags
42774283

4278-
/** Is this symbol `def` */
42794284
def Method: Flags
42804285

42814286
/** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */
@@ -4617,8 +4622,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
46174622
case Bind(_, body) => foldTree(x, body)(owner)
46184623
case Unapply(fun, implicits, patterns) => foldTrees(foldTrees(foldTree(x, fun)(owner), implicits)(owner), patterns)(owner)
46194624
case Alternatives(patterns) => foldTrees(x, patterns)(owner)
4620-
case SummonFrom(cases) => foldTrees(x, cases)(owner)
4621-
case _ => throw MatchError(tree.show(using Printer.TreeStructure))
46224625
}
46234626
}
46244627
end TreeAccumulator
@@ -4660,7 +4663,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
46604663
def transformTree(tree: Tree)(owner: Symbol): Tree = {
46614664
tree match {
46624665
case tree: PackageClause =>
4663-
PackageClause.copy(tree)(transformTerm(tree.pid)(owner).asInstanceOf[Ref], transformTrees(tree.stats)(tree.symbol))
4666+
PackageClause.copy(tree)(transformTerm(tree.pid).asInstanceOf[Ref], transformTrees(tree.stats)(tree.symbol))
46644667
case tree: Import =>
46654668
Import.copy(tree)(transformTerm(tree.expr)(owner), tree.selectors)
46664669
case tree: Export =>
@@ -4683,8 +4686,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
46834686
Alternatives.copy(pattern)(transformTrees(pattern.patterns)(owner))
46844687
case TypedOrTest(inner, tpt) =>
46854688
TypedOrTest.copy(tree)(transformTree(inner)(owner), transformTypeTree(tpt)(owner))
4686-
case _ =>
4687-
throw MatchError(tree.show(using Printer.TreeStructure))
46884689
}
46894690
}
46904691

@@ -4708,20 +4709,11 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
47084709
val owner = tree.symbol
47094710
TypeDef.copy(tree)(tree.name, transformTree(tree.rhs)(owner))
47104711
case tree: ClassDef =>
4711-
val constructor @ DefDef(_, _, _, _) = transformStatement(tree.constructor)(tree.symbol)
4712-
val parents = tree.parents.map(transformTree(_)(tree.symbol))
4713-
val self = tree.self.map { slf =>
4714-
transformStatement(slf)(tree.symbol) match
4715-
case self: ValDef => self
4716-
}
4717-
val body = tree.body.map(transformStatement(_)(tree.symbol))
4718-
ClassDef.copy(tree)(tree.name, constructor, parents, self, body)
4712+
ClassDef.copy(tree)(tree.name, tree.constructor, tree.parents, tree.self, tree.body)
47194713
case tree: Import =>
47204714
Import.copy(tree)(transformTerm(tree.expr)(owner), tree.selectors)
47214715
case tree: Export =>
47224716
tree
4723-
case _ =>
4724-
throw MatchError(tree.show(using Printer.TreeStructure))
47254717
}
47264718
}
47274719

@@ -4767,10 +4759,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
47674759
Repeated.copy(tree)(transformTerms(elems)(owner), transformTypeTree(elemtpt)(owner))
47684760
case Inlined(call, bindings, expansion) =>
47694761
Inlined.copy(tree)(call, transformSubTrees(bindings)(owner), transformTerm(expansion)(owner))
4770-
case SummonFrom(cases) =>
4771-
SummonFrom.copy(tree)(transformCaseDefs(cases)(owner))
4772-
case _ =>
4773-
throw MatchError(tree.show(using Printer.TreeStructure))
47744762
}
47754763
}
47764764

@@ -4799,8 +4787,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
47994787
TypeBind.copy(tree)(tree.name, tree.body)
48004788
case tree: TypeBlock =>
48014789
TypeBlock.copy(tree)(tree.aliases, tree.tpt)
4802-
case _ =>
4803-
throw MatchError(tree.show(using Printer.TreeStructure))
48044790
}
48054791

48064792
def transformCaseDef(tree: CaseDef)(owner: Symbol): CaseDef = {

library/src/scala/quoted/Type.scala

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,20 @@ object Type:
2626
* Returns None if the type is not a singleton constant type.
2727
*
2828
* Example usage:
29-
* ```scala sc:usingquotes
29+
* ```scala
30+
* //{
3031
* import scala.deriving.*
31-
* import quotes.reflect.*
32-
* val expr: Expr[Any] = ???
33-
* expr match
34-
* case '{ $mirrorExpr : Mirror.Sum { type MirroredLabel = label } } =>
35-
* Type.valueOfConstant[label] // Option[String]
32+
* def f(using Quotes) = {
33+
* import quotes.reflect.*
34+
* val expr: Expr[Any] = ???
35+
* //}
36+
* expr match {
37+
* case '{ $mirrorExpr : Mirror.Sum { type MirroredLabel = label } } =>
38+
* Type.valueOfConstant[label] // Option[String]
39+
* }
40+
* //{
41+
* }
42+
* //}
3643
* ```
3744
*/
3845
def valueOfConstant[T](using Type[T])(using Quotes): Option[T] =
@@ -43,14 +50,20 @@ object Type:
4350
* Returns None if the type is not a tuple singleton constant types.
4451
*
4552
* Example usage:
46-
* ```scala sc:usingquotes
53+
* ```scala
4754
* //{
4855
* import scala.deriving.*
49-
* import quotes.reflect.*
50-
* val expr: Expr[Any] = ???
51-
* expr match
52-
* case '{ type label <: Tuple; $mirrorExpr : Mirror.Sum { type MirroredElemLabels = `label` } } =>
53-
* Type.valueOfTuple[label] // Option[Tuple]
56+
* def f(using Quotes) = {
57+
* import quotes.reflect.*
58+
* val expr: Expr[Any] = ???
59+
* //}
60+
* expr match {
61+
* case '{ type label <: Tuple; $mirrorExpr : Mirror.Sum { type MirroredElemLabels = `label` } } =>
62+
* Type.valueOfTuple[label] // Option[Tuple]
63+
* }
64+
* //{
65+
* }
66+
* //}
5467
* ```
5568
*/
5669
@since("3.1")

library/src/scala/quoted/Varargs.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ object Varargs {
1616
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
1717
*
1818
* Usage:
19-
* ```scala sc:usingquotes
20-
* import quotes.reflect.*
21-
* '{ List(${Varargs(List('{1}, '{2}, '{3}))}: _*) } // equivalent to '{ List(1, 2, 3) }
19+
* ```scala
20+
* //{
21+
* def f(using Quotes) = {
22+
* import quotes.reflect.*
23+
* //}
24+
* '{ List(${Varargs(List('{1}, '{2}, '{3}))}: _*) } // equivalent to '{ List(1, 2, 3) }
25+
* //{
26+
* }
27+
* //}
2228
* ```
2329
*/
2430
def apply[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] = {

scaladoc-testcases/src/tests/snippetCompilerTests.scala

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,15 @@ class B { }
5656

5757
/**
5858
* ```scala sc:macrocompile
59-
* inline def sum(args: Int*): Int = ${ sumExpr('args) }
60-
* def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match
61-
* case Varargs(Exprs(args)) => ???
62-
* // args: Seq[Int]
59+
* import scala.quoted._
60+
* inline def sum(args: Int*): Int = ${ sumExpr('args) }
61+
* def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match
62+
* case Varargs(Exprs(args)) => ???
63+
* // args: Seq[Int]
6364
* ```
6465
*/
65-
class C { }
6666

67-
/**
68-
* ```scala sc:usingquotes
69-
* import quotes.reflect.*
70-
* '{ List(${Varargs(List('{1}, '{2}, '{3}))}: _*) } // equivalent to '{ List(1, 2, 3) }
71-
* ```
72-
*/
73-
class D { }
67+
class C { }
7468

7569
trait Quotes {
7670
val reflect: reflectModule = ???

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetChecker.scala

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,19 @@ class SnippetChecker(val args: Scaladoc.Args)(using cctx: CompilerContext):
4444
lineOffset: SnippetChecker.LineOffset,
4545
sourceFile: SourceFile
4646
): Option[SnippetCompilationResult] = {
47-
arg.flag match
48-
case flag @ (SCFlags.Compile | SCFlags.Fail | SCFlags.UsingQuotes) =>
49-
val wrapped = WrappedSnippet(
50-
snippet,
51-
data.map(_.packageName),
52-
data.fold(Nil)(_.classInfos),
53-
data.map(_.imports).getOrElse(Nil),
54-
lineOffset + data.fold(0)(_.position.line) + constantLineOffset,
55-
data.fold(0)(_.position.column) + constantColumnOffset,
56-
flag == SCFlags.UsingQuotes
57-
)
58-
Some(compiler.compile(wrapped, arg, sourceFile))
59-
case SCFlags.MacroCompile =>
60-
val wrapped = WrappedSnippet(
61-
snippet,
62-
data.map(_.packageName),
63-
data.map(_.imports).getOrElse(Nil),
64-
lineOffset + data.fold(0)(_.position.line) + constantLineOffset,
65-
data.fold(0)(_.position.column) + constantColumnOffset
66-
)
67-
Some(compiler.compile(wrapped, arg, sourceFile))
68-
case SCFlags.NoCompile => None
47+
if arg.flag != SCFlags.NoCompile then
48+
val wrapped = WrappedSnippet(
49+
snippet,
50+
data.map(_.packageName),
51+
data.fold(Nil)(_.classInfos),
52+
data.map(_.imports).getOrElse(Nil),
53+
lineOffset + data.fold(0)(_.position.line) + constantLineOffset,
54+
data.fold(0)(_.position.column) + constantColumnOffset,
55+
arg.flag
56+
)
57+
Some(compiler.compile(wrapped, arg, sourceFile))
58+
else
59+
None
6960

7061
}
7162

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetCompilerArgs.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ case class SnippetCompilerArg(flag: SCFlags):
99
enum SCFlags(val flagName: String):
1010
case Compile extends SCFlags("compile")
1111
case MacroCompile extends SCFlags("macrocompile")
12-
case UsingQuotes extends SCFlags("usingquotes")
1312
case NoCompile extends SCFlags("nocompile")
1413
case Fail extends SCFlags("fail")
1514

@@ -40,7 +39,6 @@ object SnippetCompilerArgs:
4039
|Available flags:
4140
|compile - Enables snippet checking.
4241
|macrocompile - Enables snippet checking for macros.
43-
|usingquotes - Enables checking snippet additionally wrapped in `scala.quoted.Quotes` impilicit scope.
4442
|nocompile - Disables snippet checking.
4543
|fail - Enables snippet checking, asserts that snippet doesn't compile.
4644
|

scaladoc/src/dotty/tools/scaladoc/snippets/WrappedSnippet.scala

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,49 @@ object WrappedSnippet:
1010

1111
val indent: Int = 2
1212

13-
def apply(
14-
str: String,
15-
packageName: Option[String],
16-
imports: List[String],
17-
outerLineOffset: Int,
18-
outerColumnOffset: Int
19-
): WrappedSnippet =
20-
apply(str, packageName, Nil, imports, outerLineOffset, outerColumnOffset)
21-
2213
def apply(
2314
str: String,
2415
packageName: Option[String],
2516
classInfos: Seq[SnippetCompilerData.ClassInfo],
2617
imports: List[String],
2718
outerLineOffset: Int,
2819
outerColumnOffset: Int,
29-
usingQuotes: Boolean = false
20+
flag: SCFlags,
3021
): WrappedSnippet =
3122
val baos = new ByteArrayOutputStream()
3223
val ps = new PrintStream(baos)
3324
ps.startHide()
3425
ps.println(s"package ${packageName.getOrElse("snippets")}")
3526
imports.foreach(i => ps.println(s"import $i"))
36-
val nestLevels = if classInfos.isEmpty then 1 else classInfos.length + (if usingQuotes then 1 else 0)
37-
if classInfos.isEmpty then
27+
val nonEmptyClassInfos = if classInfos.isEmpty then Seq(SnippetCompilerData.ClassInfo(None, Nil, None)) else classInfos
28+
29+
if flag == SCFlags.MacroCompile then
3830
ps.println("object Snippet {")
3931
else
40-
classInfos.zipWithIndex.foreach { (info, i) =>
32+
nonEmptyClassInfos.zipWithIndex.foreach { (info, i) =>
4133
ps.printlnWithIndent(indent * i, s"trait Snippet$i${info.generics.getOrElse("")} { ${info.tpe.fold("")(cn => s"self: $cn =>")}")
4234
info.names.foreach{ name =>
4335
ps.printlnWithIndent(indent * i + indent, s"val $name = self")
4436
}
4537
}
46-
if usingQuotes then
47-
ps.printlnWithIndent(classInfos.length * indent, "def f(using Quotes) = {")
38+
4839
ps.endHide()
49-
str.split('\n').foreach(ps.printlnWithIndent(nestLevels * indent, _))
40+
val (indentsMade, createdVals) = if flag == SCFlags.MacroCompile then
41+
(1, 1)
42+
else
43+
(nonEmptyClassInfos.size, nonEmptyClassInfos.flatMap(_.names).size)
44+
45+
str.split('\n').foreach(ps.printlnWithIndent(indentsMade * indent, _))
5046
ps.startHide()
51-
(0 to nestLevels -1).reverse.foreach( i => ps.printlnWithIndent(i * indent, "}"))
47+
(0 to indentsMade -1).reverse.foreach( i => ps.printlnWithIndent(i * indent, "}"))
5248
ps.endHide()
49+
5350
WrappedSnippet(
5451
baos.toString,
5552
outerLineOffset,
5653
outerColumnOffset,
57-
nestLevels + classInfos.flatMap(_.names).size + packageName.size + 2 /*Hide tokens*/,
58-
nestLevels * indent
54+
indentsMade + imports.length + createdVals + packageName.size + 2 /*Hide tokens*/,
55+
indentsMade * indent
5956
)
6057

6158
extension (ps: PrintStream)

0 commit comments

Comments
 (0)