Skip to content

Commit 3112800

Browse files
Merge pull request #9244 from ShapelessCat/fix-doc-macros
Fix docs
2 parents 16a45c4 + 5bf11fc commit 3112800

File tree

8 files changed

+26
-26
lines changed

8 files changed

+26
-26
lines changed

docs/docs/reference/changed-features/numeric-literals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ BigFloat.FromDigits.fromDigits("1e100000000000")
178178
```
179179
Evaluating this expression throws a `NumberTooLarge` exception at run time. We would like it to
180180
produce a compile-time error instead. We can achieve this by tweaking the `BigFloat` class
181-
with a small dose of meta-programming. The idea is to turn the `fromDigits` method
181+
with a small dose of metaprogramming. The idea is to turn the `fromDigits` method
182182
into a macro, i.e. make it an inline method with a splice as right hand side.
183183
To do this, replace the `FromDigits` instance in the `BigFloat` object by the following two definitions:
184184
```scala

docs/docs/reference/features-classification.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ date: April 6, 2019
55
author: Martin Odersky
66
---
77

8-
This document provides an overview of the constructs proposed for Scala 3 with the aim to facilitate the discussion what to include and when to include it. It classifies features into eight groups: (1) essential foundations, (2) simplifications, (3) restrictions, (4) dropped features, (5) changed features, (6) new features, (7) features oriented towards meta-programming with the aim to replace existing macros, and (8) changes to type checking and inference.
8+
This document provides an overview of the constructs proposed for Scala 3 with the aim to facilitate the discussion what to include and when to include it. It classifies features into eight groups: (1) essential foundations, (2) simplifications, (3) restrictions, (4) dropped features, (5) changed features, (6) new features, (7) features oriented towards metaprogramming with the aim to replace existing macros, and (8) changes to type checking and inference.
99

1010
Each group contains sections classifying the status (i.e. relative importance to be a part of Scala 3, and relative urgency when to decide this) and the migration cost
1111
of the constructs in it.
@@ -160,13 +160,13 @@ Enums offer an essential simplification of fundamental use patterns, so they sho
160160

161161
Being new features, existing code migrates without changes. To be sure, sometimes it would be attractive to rewrite code to make use of the new features in order to increase clarity and conciseness.
162162

163-
## Meta Programming
163+
## Metaprogramming
164164

165-
The following constructs together aim to put meta programming in Scala on a new basis. So far, meta programming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
165+
The following constructs together aim to put metaprogramming in Scala on a new basis. So far, metaprogramming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
166166

167167
It's worth noting that macros were never included in the Scala 2 language specification and were so far made available only under an `-experimental` flag. This has not prevented their widespread usage.
168168

169-
To enable porting most uses of macros, we are experimenting with the advanced language constructs listed below. These designs are more provisional than the rest of the proposed language constructs for Scala 3.0. There might still be some changes until the final release. Stabilizing the feature set needed for meta programming is our first priority.
169+
To enable porting most uses of macros, we are experimenting with the advanced language constructs listed below. These designs are more provisional than the rest of the proposed language constructs for Scala 3.0. There might still be some changes until the final release. Stabilizing the feature set needed for metaprogramming is our first priority.
170170

171171
- [Match Types](new-types/match-types.md) allow computation on types.
172172
- [Inline](metaprogramming/inline.md) provides

docs/docs/reference/metaprogramming/macros-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ is studied [separately](./simple-smp.md).
161161

162162
## Going Further
163163

164-
The meta-programming framework as presented and currently implemented is quite restrictive
164+
The metaprogramming framework as presented and currently implemented is quite restrictive
165165
in that it does not allow for the inspection of quoted expressions and
166166
types. It’s possible to work around this by providing all necessary
167167
information as normal, unquoted inline parameters. But we would gain
@@ -234,7 +234,7 @@ envisage a solution that allows the former but not the latter.
234234

235235
## Conclusion
236236

237-
Meta-programming has a reputation of being difficult and confusing.
237+
Metaprogramming has a reputation of being difficult and confusing.
238238
But with explicit `Expr/Type` types and quotes and splices it can become
239239
downright pleasant. A simple strategy first defines the underlying quoted or unquoted
240240
values using `Expr` and `Type` and then inserts quotes and splices to make the types

docs/docs/reference/metaprogramming/macros.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ that program elaboration will lead to neither of the two unwanted
126126
situations described above.
127127

128128
In what concerns the range of features it covers, this form of macros introduces
129-
a principled meta programming framework that is quite close to the MetaML family of
129+
a principled metaprogramming framework that is quite close to the MetaML family of
130130
languages. One difference is that MetaML does not have an equivalent of the PCP
131131
- quoted code in MetaML _can_ access variables in its immediately enclosing
132132
environment, with some restrictions and caveats since such accesses involve
@@ -362,8 +362,8 @@ is handled by the compiler, using the algorithm sketched above.
362362

363363
### Relationship with Inline
364364

365-
Seen by itself, principled meta-programming looks more like a framework for
366-
runtime metaprogramming than one for compile-time meta programming with macros.
365+
Seen by itself, principled metaprogramming looks more like a framework for
366+
runtime metaprogramming than one for compile-time metaprogramming with macros.
367367
But combined with Dotty’s `inline` feature it can be turned into a compile-time
368368
system. The idea is that macro elaboration can be understood as a combination of
369369
a macro library and a quoted program. For instance, here’s the `assert` macro
@@ -375,8 +375,8 @@ object Macros {
375375
inline def assert(inline expr: Boolean): Unit =
376376
${ assertImpl('expr) }
377377

378-
def assertImpl(expr: Expr[Boolean]) =
379-
'{ if !($expr) then throw new AssertionError("failed assertion: " + ${expr.show}) }
378+
def assertImpl(expr: Expr[Boolean])(using QuoteContext) =
379+
'{ if !($expr) then throw new AssertionError("failed assertion: " + ${expr.show}) } // autolift is applied
380380
}
381381

382382
object App {
@@ -502,7 +502,7 @@ function `f` and one `sum` that performs a sum by delegating to `map`.
502502

503503
```scala
504504
object Macros {
505-
def map[T](arr: Expr[Array[T]], f: Expr[T] => Expr[Unit])(implicit t: Type[T]): Expr[Unit] = '{
505+
def map[T](arr: Expr[Array[T]], f: Expr[T] => Expr[Unit])(using t: Type[T], qctx: QuoteContext): Expr[Unit] = '{
506506
var i: Int = 0
507507
while (i < ($arr).length) {
508508
val element: $t = ($arr)(i)
@@ -511,7 +511,7 @@ object Macros {
511511
}
512512
}
513513

514-
def sum(arr: Expr[Array[Int]]): Expr[Int] = '{
514+
def sum(arr: Expr[Array[Int]])(using QuoteContext): Expr[Int] = '{
515515
var sum = 0
516516
${ map(arr, x => '{sum += $x}) }
517517
sum
@@ -719,7 +719,7 @@ This might be used to then perform an implicit search as in:
719719
```scala
720720
inline def (inline sc: StringContext).showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
721721

722-
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using qctx: QuoteContext): Expr[String] = {
722+
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using QuoteContext): Expr[String] = {
723723
argsExpr match {
724724
case Varargs(argExprs) =>
725725
val argShowedExprs = argExprs.map {
@@ -765,7 +765,7 @@ the subxpression of type `Expr[Int]` is bound to `body` as an `Expr[Int => Int]`
765765
```scala
766766
inline def eval(inline e: Int): Int = ${ evalExpr('e) }
767767

768-
private def evalExpr(using QuoteContext)(e: Expr[Int]): Expr[Int] = {
768+
private def evalExpr(e: Expr[Int])(using QuoteContext): Expr[Int] = {
769769
e match {
770770
case '{ val y: Int = $x; $body(y): Int } =>
771771
// body: Expr[Int => Int] where the argument represents references to y

docs/docs/reference/metaprogramming/simple-smp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
layout: doc-page
3-
title: "The Meta-theory of Symmetric Meta-programming"
3+
title: "The Meta-theory of Symmetric Metaprogramming"
44
---
55

66
This note presents a simplified variant of
7-
[principled meta-programming](./macros.md)
7+
[principled metaprogramming](./macros.md)
88
and sketches its soundness proof. The variant treats only dialogues
99
between two stages. A program can have quotes which can contain
1010
splices (which can contain quotes, which can contain splices, and so

docs/docs/reference/metaprogramming/staging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ layout: doc-page
33
title: "Multi-Stage Programming"
44
---
55

6-
The framework expresses at the same time compile-time meta-programming and
7-
multi-stage programming. We can think of compile-time meta-programming as a
6+
The framework expresses at the same time compile-time metaprogramming and
7+
multi-stage programming. We can think of compile-time metaprogramming as a
88
two stage compilation process: one that we write the code in top-level splices,
99
that will be used for code generation (macros) and one that will perform all
1010
necessary evaluations at compile-time and an object program that we will run

docs/docs/reference/overview.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The language redesign was guided by three main goals:
1515
- Further improve the consistency and expressiveness of Scala's language constructs.
1616

1717
Corresponding to these goals, the language changes fall into seven categories:
18-
(1) Core constructs to strengthen foundations, (2) simplifications and (3) restrictions, to make the language easier and safer to use, (4) dropped constructs to make the language smaller and more regular, (5) changed constructs to remove warts, and increase consistency and usability, (6) new constructs to fill gaps and increase expressiveness, (7) a new, principled approach to meta-programming that replaces today's experimental macros.
18+
(1) Core constructs to strengthen foundations, (2) simplifications and (3) restrictions, to make the language easier and safer to use, (4) dropped constructs to make the language smaller and more regular, (5) changed constructs to remove warts, and increase consistency and usability, (6) new constructs to fill gaps and increase expressiveness, (7) a new, principled approach to metaprogramming that replaces today's experimental macros.
1919

2020
## Essential Foundations
2121

@@ -110,13 +110,13 @@ These are additions to the language that make it more powerful or pleasant to us
110110
- [Polymorphic Function Types](https://github.com/lampepfl/dotty/pull/4672) generalize polymorphic methods to dependent function values and types. _Current status_: There is a proposal, and a prototype implementation, but the implementation has not been finalized or merged yet.
111111
- [Kind Polymorphism](other-new-features/kind-polymorphism.md) allows the definition of operators working equally on types and type constructors.
112112

113-
## Meta Programming
113+
## Metaprogramming
114114

115-
The following constructs together aim to put meta programming in Scala on a new basis. So far, meta programming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
115+
The following constructs together aim to put metaprogramming in Scala on a new basis. So far, metaprogramming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.
116116

117117
It's worth noting that macros were never included in the Scala 2 language specification and were so far made available only under an `-experimental` flag. This has not prevented their widespread usage.
118118

119-
To enable porting most uses of macros, we are experimenting with the advanced language constructs listed below. These designs are more provisional than the rest of the proposed language constructs for Scala 3.0. There might still be some changes until the final release. Stabilizing the feature set needed for meta programming is our first priority.
119+
To enable porting most uses of macros, we are experimenting with the advanced language constructs listed below. These designs are more provisional than the rest of the proposed language constructs for Scala 3.0. There might still be some changes until the final release. Stabilizing the feature set needed for metaprogramming is our first priority.
120120

121121
- [Match Types](new-types/match-types.md) allow computation on types.
122122
- [Inline](metaprogramming/inline.md) provides

library/src-bootstrapped/scala/quoted/QuoteContext.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import scala.quoted.show.SyntaxHighlight
55
/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.run`.
66
* Used to perform all operations on quoted `Expr` or `Type`.
77
*
8-
* It contains the low-level Typed AST API `tasty` meta-programming API.
8+
* It contains the low-level Typed AST API `tasty` metaprogramming API.
99
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
1010
*
1111
* @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.tasty._; ... }`.
1212
*/
1313
trait QuoteContext { self =>
1414

15-
/** Low-level Typed AST API `tasty` meta-programming API.
15+
/** Low-level Typed AST API `tasty` metaprogramming API.
1616
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
1717
*/
1818
val tasty: scala.tasty.Reflection

0 commit comments

Comments
 (0)