Skip to content

Commit 343ae2d

Browse files
committed
updates bundles and boxes to fit recent changes to 2.11.0-SNAPSHOT
Here’s the pull request that has introduced the aforementioned changes: scala/scala#3355.
1 parent 4fd85dc commit 343ae2d

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

overviews/macros/blackbox-whitebox.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ outof: 11
1212

1313
**Eugene Burmako**
1414

15-
Separation of macros into blackbox ones and whitebox ones is implemented in the recent milestone builds of Scala 2.11, starting from 2.11.0-M7. It is not implemented in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
15+
Separation of macros into blackbox ones and whitebox ones is implemented in the recent milestone builds of Scala 2.11, starting from 2.11.0-M7 (however, in 2.11.0-M8, the syntax underwent some changes, so this documentation isn't applicable to earlier milestone builds of 2.11). The *box separation is not implemented in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
1616

1717
## Why macros work?
1818

@@ -39,9 +39,7 @@ We recognize the importance of both blackbox and whitebox macros, however we fee
3939

4040
In the 2.11 release, we take first step of standardization by expressing the distinction between blackbox and whitebox macros in signatures of def macros, so that `scalac` can treat such macros differently. This is just a preparatory step, so both blackbox and whitebox macros remain experimental in Scala 2.11.
4141

42-
We express the distinction by replacing `scala.reflect.macros.Context` with `scala.reflect.macros.BlackboxContext` and `scala.reflect.macros.WhiteboxContext`. If a macro impl is defined with `BlackboxContext` as its first argument, then macro defs that are using it are considered blackbox, and analogously for `WhiteboxContext`. Of course, the vanilla `Context` is still there for compatibility reasons, but it issues a deprecation warning encouraging to choose between blackbox and whitebox macros.
43-
44-
[Macro bundles](/overviews/macros/bundles.html) also support the distinction by providing two different traits to inherit from: `scala.reflect.macros.BlackboxMacro` and `scala.reflect.macros.WhiteboxMacro`. Unsurprisingly, the former provides a `BlackboxContext` and turns its users into blackbox macros, and the latter provides a `WhiteboxContext` and makes def macros referring to it to be whitebox macros.
42+
We express the distinction by replacing `scala.reflect.macros.Context` with `scala.reflect.macros.blackbox.Context` and `scala.reflect.macros.whitebox.Context`. If a macro impl is defined with `blackbox.Context` as its first argument, then macro defs that are using it are considered blackbox, and analogously for `whitebox.Context`. Of course, the vanilla `Context` is still there for compatibility reasons, but it issues a deprecation warning encouraging to choose between blackbox and whitebox macros.
4543

4644
Blackbox def macros are treated differently from def macros of Scala 2.10. The following restrictions are applied to them by the Scala typechecker:
4745

overviews/macros/bundles.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ languages: [ja]
1313

1414
**Eugene Burmako**
1515

16-
Macro bundles are shipped with the recent milestone builds of Scala 2.11, starting from 2.11.0-M4. They are not available in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
16+
Macro bundles are shipped with the recent milestone builds of Scala 2.11, starting from 2.11.0-M4 (however, in 2.11.0-M8, the syntax underwent some changes, so this documentation isn't applicable to earlier milestone builds of 2.11). Macro bundles are not available in Scala 2.10.x or in macro paradise. Follow the instructions at [http://www.scala-lang.org/download/](http://www.scala-lang.org/download/) to download and use the latest milestone of 2.11.
1717

1818
## Macro bundles
1919

@@ -26,26 +26,15 @@ traits outside macro implementations, turning implementations into trivial wrapp
2626

2727
2. Moreover, since macro parameters are path-dependent on the macro context, [special incantations](/overviews/macros/overview.html#writing_bigger_macros) are required to wire implementations and helpers together.
2828

29-
Macro bundles provide a solution to these problems by allowing macro implementations to be declared in traits, which extend
30-
`scala.reflect.macros.BlackboxMacro` or `scala.reflect.macros.WhiteboxMacro`. These base traits predefine `val c: BlackboxContext`
31-
and `val c: WhiteboxContext` correspondingly, relieving macro implementations from having to declare the context in their signatures,
32-
which simplifies modularization.
29+
Macro bundles provide a solution to these problems by allowing macro implementations to be declared in classes that take
30+
`c: BlackboxContext` or `c: WhiteboxContext` as their constructor parameters, relieving macro implementations from having
31+
to declare the context in their signatures, which simplifies modularization. Referencing macro implementations defined in bundles
32+
works in the same way as with impls defined in objects. You specify a bundle name and then select a method from it,
33+
providing type arguments if necessary.
3334

34-
trait BlackboxMacro {
35-
val c: BlackboxContext
36-
}
37-
38-
trait WhiteboxMacro {
39-
val c: WhiteboxContext
40-
}
41-
42-
Referencing macro implementations defined in bundles works in the same way as with impls defined in objects. You specify a bundle name
43-
and then select a method from it, providing type arguments if necessary.
44-
45-
import scala.reflect.macros.Context
46-
import scala.reflect.macros.BlackboxMacro
35+
import scala.reflect.macros.blackbox.Context
4736

48-
trait Impl extends BlackboxMacro {
37+
class Impl(val c: Context) {
4938
def mono = c.literalUnit
5039
def poly[T: c.WeakTypeTag] = c.literal(c.weakTypeOf[T].toString)
5140
}

0 commit comments

Comments
 (0)