Skip to content

Commit f42366d

Browse files
committed
Update Hole syntax in RefinedPrinter and documentation
1 parent 67353f0 commit f42366d

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
730730
val argsText = ("(" ~ toTextGlobal(args, ", ") ~ ")").provided(args.nonEmpty)
731731
val tptText = toTextGlobal(tpt)
732732
val contentText = ("|" ~~ toTextGlobal(content)).provided(content ne EmptyTree)
733-
prefix ~~ idx.toString ~ targsText ~ argsText ~ ":" ~~ tptText ~~ contentText ~~ postfix
733+
prefix ~~ "`" ~ idx.toString ~ "`" ~ targsText ~ argsText ~ ":" ~~ tptText ~~ contentText ~~ postfix
734734
case CapturingTypeTree(refs, parent) =>
735735
parent match
736736
case ImpureByNameTypeTree(bntpt) =>

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,42 @@ import scala.annotation.constructorOnly
2828
* Transforms top level quote
2929
* ```
3030
* '{ ...
31-
* @TypeSplice type X0 = {{ 0 | .. | contentsTpe0 | .. }}
32-
* @TypeSplice type X2 = {{ 1 | .. | contentsTpe1 | .. }}
31+
* @TypeSplice type X0 = [[[ `0`: ... | contentsTpe0 ]]]
32+
* type X1
3333
* val x1: U1 = ???
3434
* val x2: U2 = ???
3535
* ...
36-
* {{{ 3 | x1 | contents0 | T0 }}} // hole
36+
* {{{ `2`(x1): T0 | contents0 }}} // Hole
3737
* ...
38-
* {{{ 4 | x2 | contents1 | T1 }}} // hole
38+
* {{{ `3`[X1](x2): T1 | contents1 }}} // Hole
3939
* ...
40-
* {{{ 5 | x1, x2 | contents2 | T2 }}} // hole
40+
* {{{ `4`(x1, x2): T2 | contents2 }}} // Hole
4141
* ...
4242
* }
4343
* ```
4444
* to
4545
* ```
4646
* unpickleExprV2(
47-
* pickled = [[ // PICKLED TASTY
48-
* @TypeSplice type X0 // with bounds that do not contain captured types
49-
* @TypeSplice type X1 // with bounds that do not contain captured types
47+
* pickled = tasty""" // PICKLED TASTY
48+
* @TypeSplice type X0 // with bounds that do not contain captured types
49+
* type X1
5050
* val x1 = ???
5151
* val x2 = ???
5252
* ...
53-
* {{{ 0 | x1 | | T0 }}} // hole
54-
* ...
55-
* {{{ 1 | x2 | | T1 }}} // hole
56-
* ...
57-
* {{{ 2 | x1, x2 | | T2 }}} // hole
53+
* {{{ `0`(x1): T0 }}} // Hole
54+
* ...
55+
* {{{ `1`[X1](x2): T1 }}} // Hole
56+
* ...
57+
* {{{ `2`(x1, x2): T2 }}} // Hole
5858
* ...
59-
* ]],
59+
* """,
6060
* typeHole = (idx: Int, args: List[Any]) => idx match {
6161
* case 0 => contentsTpe0.apply(args(0).asInstanceOf[Type[?]]) // beta reduced
62-
* case 1 => contentsTpe1.apply(args(0).asInstanceOf[Type[?]]) // beta reduced
6362
* },
6463
* termHole = (idx: Int, args: List[Any], quotes: Quotes) => idx match {
65-
* case 3 => content0.apply(args(0).asInstanceOf[Expr[U1]]).apply(quotes) // beta reduced
66-
* case 4 => content1.apply(args(0).asInstanceOf[Expr[U2]]).apply(quotes) // beta reduced
67-
* case 5 => content2.apply(args(0).asInstanceOf[Expr[U1]], args(1).asInstanceOf[Expr[U2]]).apply(quotes) // beta reduced
64+
* case 0 => content0.apply(args(0).asInstanceOf[Expr[U1]]).apply(quotes) // beta reduced
65+
* case 1 => content1.apply(args(0).asInstanceOf[Expr[U2]]).apply(quotes) // beta reduced
66+
* case 2 => content2.apply(args(0).asInstanceOf[Expr[U1]], args(1).asInstanceOf[Expr[U2]]).apply(quotes) // beta reduced
6867
* },
6968
* )
7069
* ```

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,19 @@ object Splicing:
3838
*
3939
* After this phase we have the invariant where all splices have the following shape
4040
* ```
41-
* {{{ <holeIdx> | <holeType> | <captures>* | (<capturedTerms>*) => <spliceContent> }}}
41+
* {{{ `<holeIdx>`[<typeCaptures>*](<termCaptures>*): <holeType> | (<capturesTypes>*, <capturedTerms>*) => <spliceContent> }}}
4242
* ```
43-
* where `<spliceContent>` does not contain any free references to quoted definitions and `<captures>*`
43+
* where `<spliceContent>` does not contain any free references to quoted definitions and `<typeCaptures>*`/`<termCaptures>*`
4444
* contains the quotes with references to all cross-quote references. There are some special rules
4545
* for references in the LHS of assignments and cross-quote method references.
4646
*
47-
* In the following code example `x1` and `x2` are cross-quote references.
47+
* In the following code example `x1`, `x2` and `U` are cross-quote references.
4848
* ```
4949
* '{ ...
5050
* val x1: T1 = ???
51-
* val x2: T2 = ???
52-
* ${ (q: Quotes) ?=> f('{ g(x1, x2) }) }: T3
51+
* type U <: T2
52+
* val x2: U = ???
53+
* ${ (q: Quotes) ?=> f('{ g[U](x1, x2) }) }: T3
5354
* }
5455
* ```
5556
*
@@ -59,10 +60,11 @@ object Splicing:
5960
* ```
6061
* '{ ...
6162
* val x1: T1 = ???
62-
* val x2: T2 = ???
63-
* {{{ 0 | T3 | x1, x2 |
64-
* (x1$: Expr[T1], x2$: Expr[T2]) => // body of this lambda does not contain references to x1 or x2
65-
* (q: Quotes) ?=> f('{ g(${x1$}, ${x2$}) })
63+
* type U <: T2
64+
* val x2: U = ???
65+
* {{{ `0`[U](x1, x2): T3 |
66+
* (U$2: Type[U], x1$: Expr[T], x2$: Expr[U]) => // body of this lambda does not contain references to x1 or x2
67+
* (q: Quotes) ?=> f('{ @SplicedType type U$3 = [[[ `0`: U | U$1 ]]]; g[U$3](${x1$}, ${x2$}) })
6668
*
6769
* }}}
6870
* }
@@ -184,7 +186,7 @@ class Splicing extends MacroTransform:
184186
* ```
185187
* is transformed into
186188
* ```scala
187-
* {{{ <holeIdx++> | T2 | x, X | (x$1: Expr[T1], X$1: Type[X]) => (using Quotes) ?=> {... ${x$1} ... X$1.Underlying ...} }}}
189+
* {{{ `<holeIdx++>`[X](x): T2 | (X$1: Type[X], x$1: Expr[T1]) => (using Quotes) ?=> {... ${x$1} ... X$1.Underlying ...} }}}
188190
* ```
189191
*/
190192
private class SpliceTransformer(spliceOwner: Symbol, isCaptured: Symbol => Boolean) extends Transformer:

0 commit comments

Comments
 (0)