Skip to content

Commit 3d7e024

Browse files
committed
tweak: snippet compiler settings
- Fix build settings to make the snippet compiler to work properly - Tweak some doc snippets so that they pass snippet compiker check Related to: #12967 [Cherry-picked 438a17a][modified]
1 parent 17b8f6b commit 3d7e024

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

library/src/scala/quoted/Quotes.scala

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,31 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
15991599
end extension
16001600
end ReturnMethods
16011601

1602-
/** Tree representing a variable argument list in the source code */
1602+
/** Tree representing a variable argument list in the source code.
1603+
*
1604+
* This tree is used to encode varargs terms. The Repeated encapsulates
1605+
* the sequence of the elements but needs to be wrapped in a
1606+
* `scala.<repeated>[T]` (see `defn.RepeatedParamClass`). For example the
1607+
* arguments `1, 2` of `List.apply(1, 2)` can be represented as follows:
1608+
*
1609+
*
1610+
* ```scala
1611+
* //{
1612+
* import scala.quoted._
1613+
* def inQuotes(using Quotes) = {
1614+
* val q: Quotes = summon[Quotes]
1615+
* import q.reflect._
1616+
* //}
1617+
* val intArgs = List(Literal(IntConstant(1)), Literal(IntConstant(2)))
1618+
* Typed(
1619+
* Repeated(intArgs, TypeTree.of[Int]),
1620+
* Inferred(defn.RepeatedParamClass.typeRef.appliedTo(TypeRepr.of[Int]))
1621+
* )
1622+
* //{
1623+
* }
1624+
* //}
1625+
* ```
1626+
*/
16031627
type Repeated <: Term
16041628

16051629
/** `TypeTest` that allows testing at runtime in a pattern match if a `Tree` is a `Repeated` */

library/src/scala/util/boundary.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import scala.annotation.implicitNotFound
1515
* be rewritten to jumps.
1616
*
1717
* Example usage:
18+
*
19+
* ```scala
20+
* import scala.util.boundary, boundary.break
1821
*
19-
* import scala.util.boundary, boundary.break
20-
*
21-
* def firstIndex[T](xs: List[T], elem: T): Int =
22-
* boundary:
23-
* for (x, i) <- xs.zipWithIndex do
24-
* if x == elem then break(i)
25-
* -1
22+
* def firstIndex[T](xs: List[T], elem: T): Int =
23+
* boundary:
24+
* for (x, i) <- xs.zipWithIndex do
25+
* if x == elem then break(i)
26+
* -1
27+
* ```
2628
*/
2729
object boundary:
2830

project/Build.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,29 +2134,36 @@ object ScaladocConfigs {
21342134
.add(VersionsDictionaryUrl("https://scala-lang.org/api/versions.json"))
21352135
.add(DocumentSyntheticTypes(true))
21362136
.add(SnippetCompiler(List(
2137-
s"${dottyLibRoot}/scala=compile",
2137+
s"$dottyLibRoot/scala=compile",
2138+
s"$dottyLibRoot/scala/compiletime=compile",
2139+
s"$dottyLibRoot/scala/util=compile",
2140+
s"$dottyLibRoot/scala/util/control=compile"
21382141
)))
21392142
.add(SiteRoot("docs"))
21402143
.add(ApiSubdirectory(true))
21412144
.withTargets(roots)
21422145
}
21432146

21442147
def stableScala3(version: String) = Def.task {
2148+
val scalaLibrarySrc = s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src"
2149+
val dottyLibrarySrc = s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src"
21452150
Scala3.value
21462151
.add(defaultSourceLinks(version + "-bin-SNAPSHOT-nonbootstrapped", version).value)
21472152
.add(ProjectVersion(version))
21482153
.add(SnippetCompiler(
21492154
List(
2150-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/quoted=compile",
2151-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src/scala/compiletime=compile"
2155+
s"$dottyLibrarySrc/scala/quoted=compile",
2156+
s"$dottyLibrarySrc/scala/compiletime=compile",
2157+
s"$dottyLibrarySrc/scala/util=compile",
2158+
s"$dottyLibrarySrc/scala/util/control=compile"
21522159
)
21532160
))
21542161
.add(CommentSyntax(List(
2155-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/dotty-library-src=markdown",
2156-
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src=wiki",
2162+
s"$dottyLibrarySrc=markdown",
2163+
s"$scalaLibrarySrc=wiki",
21572164
"wiki"
21582165
)))
2159-
.add(DocRootContent(s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed/main/scala-library-src/rootdoc.txt"))
2166+
.add(DocRootContent(s"$scalaLibrarySrc/rootdoc.txt"))
21602167
.withTargets(
21612168
Seq(
21622169
s"out/bootstrap/stdlib-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/classes",

0 commit comments

Comments
 (0)