Skip to content

Commit 8057f8d

Browse files
committed
remove usingquotes arg, fix unnecessary changes
1 parent 40c9c1c commit 8057f8d

File tree

7 files changed

+81
-76
lines changed

7 files changed

+81
-76
lines changed

library/src/scala/quoted/Quotes.scala

Lines changed: 11 additions & 5 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[?]

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: 1 addition & 3 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

@@ -39,8 +38,7 @@ object SnippetCompilerArgs:
3938
|
4039
|Available flags:
4140
|compile - Enables snippet checking.
42-
|macrocompile - Enables snippet checking for macros.
43-
|usingquotes - Enables checking snippet additionally wrapped in `scala.quoted.Quotes` impilicit scope.
41+
|macrocompile - Enables snippet checking for macros.
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)