Skip to content

Commit b00e15c

Browse files
Merge pull request #10783 from dotty-staging/improve-docs
Update Reference Documentation
2 parents 1f5e98c + 8f29c9a commit b00e15c

35 files changed

+92
-90
lines changed

docs/docs/reference/changed-features/compiler-plugins.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: "Changes in Compiler Plugins"
44
---
55

6-
Compiler plugins are supported by Dotty since 0.9. There are two notable changes
6+
Compiler plugins are supported by Dotty (and Scala 3) since 0.9. There are two notable changes
77
compared to `scalac`:
88

99
- No support for analyzer plugins
@@ -13,14 +13,14 @@ compared to `scalac`:
1313
normal type checking. This is a very powerful feature but for production usages,
1414
a predictable and consistent type checker is more important.
1515

16-
For experimentation and research, Dotty introduces _research plugin_. Research plugins
16+
For experimentation and research, Scala 3 introduces _research plugin_. Research plugins
1717
are more powerful than `scalac` analyzer plugins as they let plugin authors customize
1818
the whole compiler pipeline. One can easily replace the standard typer by a custom one or
1919
create a parser for a domain-specific language. However, research plugins are only
20-
enabled for nightly or snaphot releases of Dotty.
20+
enabled for nightly or snaphot releases of Scala 3.
2121

2222
Common plugins that add new phases to the compiler pipeline are called
23-
_standard plugins_ in Dotty. In terms of features, they are similar to
23+
_standard plugins_ in Scala 3. In terms of features, they are similar to
2424
`scalac` plugins, despite minor changes in the API.
2525

2626
## Using Compiler Plugins
@@ -41,7 +41,7 @@ pluginClass=dividezero.DivideZero
4141

4242
This is different from `scalac` plugins that required a `scalac-plugin.xml` file.
4343

44-
Starting from 1.1.5, `sbt` also supports Dotty compiler plugins. Please refer to the
44+
Starting from 1.1.5, `sbt` also supports Scala 3 compiler plugins. Please refer to the
4545
`sbt` [documentation][2] for more information.
4646

4747
## Writing a Standard Compiler Plugin

docs/docs/reference/changed-features/eta-expansion.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ rather than `next _`.
3535
The reason for excluding nullary methods from automatic eta expansion
3636
is that Scala implicitly inserts the `()` argument, which would
3737
conflict with eta expansion. Automatic `()` insertion is
38-
[limited](../dropped-features/auto-apply.md) in Dotty, but the fundamental ambiguity
38+
[limited](../dropped-features/auto-apply.md) in Scala 3, but the fundamental ambiguity
3939
remains.
4040

4141
[More details](eta-expansion-spec.md)
42-

docs/docs/reference/changed-features/implicit-conversions-spec.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ language:
9494
```scala
9595
implicit val m: Map[Int, String] = Map(1 -> "abc")
9696

97-
val x: String = 1 // scalac: assigns "abc" to x
98-
// Dotty: type error
97+
val x: String = 1 // Scala 2: assigns "abc" to x
98+
// Scala 3: type error
9999
```
100100

101101
This snippet contains a type error. The right hand side of `val x`
@@ -119,4 +119,3 @@ For more information about implicit resolution, see [Changes in
119119
Implicit Resolution](implicit-resolution.md).
120120
Other details are available in
121121
[PR #2065](https://github.com/lampepfl/dotty/pull/2065)
122-

docs/docs/reference/changed-features/implicit-resolution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: doc-page
33
title: "Changes in Implicit Resolution"
44
---
5-
This page describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Dotty.
5+
This page describes changes to the implicit resolution that apply both to the new `given`s and to the old-style `implicit`s in Scala 3.
66
Implicit resolution uses a new algorithm which caches implicit results
77
more aggressively for performance. There are also some changes that
88
affect implicits on the language level.
@@ -114,7 +114,7 @@ the implicit search for `Q` fails.
114114
**5.** The treatment of divergence errors has also changed. A divergent implicit is treated as a normal failure, after which alternatives are still tried. This also makes sense: Encountering a divergent implicit means that we assume that no finite solution can be found on the corresponding path, but another path can still be tried. By contrast,
115115
most (but not all) divergence errors in Scala 2 would terminate the implicit search as a whole.
116116

117-
**6.** Scala-2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Dotty drops this distinction. So the following code snippet would be ambiguous in Dotty:
117+
**6.** Scala-2 gives a lower level of priority to implicit conversions with call-by-name parameters relative to implicit conversions with call-by-value parameters. Scala 3 drops this distinction. So the following code snippet would be ambiguous in Scala 3:
118118

119119
```scala
120120
implicit def conv1(x: Int): A = new A(x)

docs/docs/reference/changed-features/interpolation-escapes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Escapes in interpolations
55

66
In Scala 2 there was no straightforward way to represent a single quote character `"` in a single quoted interpolation. A `\` character can't be used for that because interpolators themselves decide how to handle escaping, so the parser doesn't know whether the `"` should be escaped or used as a terminator.
77

8-
In Dotty, you can use the `$` meta character of interpolations to escape a `"` character.
8+
In Scala 3, you can use the `$` meta character of interpolations to escape a `"` character.
99

1010
```scala
1111
val inventor = "Thomas Edison"

docs/docs/reference/changed-features/lazy-vals-init.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: Lazy Vals initialization
44
---
55

6-
Dotty implements [Version 6](https://docs.scala-lang.org/sips/improved-lazy-val-initialization.html#version-6---no-synchronization-on-this-and-concurrent-initialization-of-fields)
6+
Scala 3 implements [Version 6](https://docs.scala-lang.org/sips/improved-lazy-val-initialization.html#version-6---no-synchronization-on-this-and-concurrent-initialization-of-fields)
77
of the [SIP-20] improved lazy vals initialization proposal.
88

99
## Motivation
@@ -23,7 +23,7 @@ class Foo {
2323
}
2424
```
2525

26-
The Dotty compiler will generate code equivalent to:
26+
The Scala 3 compiler will generate code equivalent to:
2727

2828
```scala
2929
class Foo {

docs/docs/reference/changed-features/overload-resolution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: doc-page
33
title: "Changes in Overload Resolution"
44
---
55

6-
Overload resolution in Dotty improves on Scala 2 in two ways.
6+
Overload resolution in Scala 3 improves on Scala 2 in two ways.
77
First, it takes all argument lists into account instead of
88
just the first argument list.
99
Second, it can infer parameter types of function values even if they
@@ -49,7 +49,7 @@ overload resolution based on additional argument blocks.
4949
The handling of function values with missing parameter types has been improved. We can now
5050
pass such values in the first argument list of an overloaded application, provided
5151
that the remaining parameters suffice for picking a variant of the overloaded function.
52-
For example, the following code compiles in Dotty, while it results in an
52+
For example, the following code compiles in Scala 3, while it results in an
5353
missing parameter type error in Scala2:
5454
```scala
5555
def f(x: Int, f2: Int => Int) = f2(x)

docs/docs/reference/changed-features/pattern-matching.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ layout: doc-page
33
title: "Option-less pattern matching"
44
---
55

6-
Dotty implementation of pattern matching was greatly simplified compared to Scala 2. From a user perspective, this means that Scala 3 generated patterns are a *lot* easier to debug, as variables all show up in debug modes and positions are correctly preserved.
6+
The implementation of pattern matching in Scala 3 was greatly simplified compared to Scala 2. From a user perspective, this means that Scala 3 generated patterns are a *lot* easier to debug, as variables all show up in debug modes and positions are correctly preserved.
77

8-
Dotty supports a superset of Scala 2 [extractors](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#extractor-patterns).
8+
Scala 3 supports a superset of Scala 2 [extractors](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#extractor-patterns).
99

1010
## Extractors
1111

docs/docs/reference/contextual/derivation.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ Mirror.Product {
122122
Note the following properties of `Mirror` types,
123123

124124
+ Properties are encoded using types rather than terms. This means that they have no runtime footprint unless used and
125-
also that they are a compile time feature for use with Dotty's metaprogramming facilities.
125+
also that they are a compile time feature for use with Scala 3's metaprogramming facilities.
126126
+ The kinds of `MirroredType` and `MirroredElemTypes` match the kind of the data type the mirror is an instance for.
127127
This allows `Mirrors` to support ADTs of all kinds.
128128
+ There is no distinct representation type for sums or products (ie. there is no `HList` or `Coproduct` type as in
129129
Scala 2 versions of shapeless). Instead the collection of child types of a data type is represented by an ordinary,
130-
possibly parameterized, tuple type. Dotty's metaprogramming facilities can be used to work with these tuple types
130+
possibly parameterized, tuple type. Scala 3's metaprogramming facilities can be used to work with these tuple types
131131
as-is, and higher level libraries can be built on top of them.
132132
+ For both product and sum types, the elements of `MirroredElemTypes` are arranged in definition order (i.e. `Branch[T]`
133133
precedes `Leaf[T]` in `MirroredElemTypes` for `Tree` because `Branch` is defined before `Leaf` in the source file).
@@ -152,20 +152,20 @@ provider of an ADT with a `derives` clause has to know about the derivation of a
152152

153153
Note that `derived` methods may have context `Mirror` parameters indirectly (e.g. by having a context argument which in turn
154154
has a context `Mirror` parameter, or not at all (e.g. they might use some completely different user-provided mechanism, for
155-
instance using Dotty macros or runtime reflection). We expect that (direct or indirect) `Mirror` based implementations
155+
instance using Scala 3 macros or runtime reflection). We expect that (direct or indirect) `Mirror` based implementations
156156
will be the most common and that is what this document emphasises.
157157

158158
Type class authors will most likely use higher level derivation or generic programming libraries to implement
159159
`derived` methods. An example of how a `derived` method might be implemented using _only_ the low level facilities
160-
described above and Dotty's general metaprogramming features is provided below. It is not anticipated that type class
160+
described above and Scala 3's general metaprogramming features is provided below. It is not anticipated that type class
161161
authors would normally implement a `derived` method in this way, however this walkthrough can be taken as a guide for
162162
authors of the higher level derivation libraries that we expect typical type class authors will use (for a fully
163163
worked out example of such a library, see [shapeless 3](https://github.com/milessabin/shapeless/tree/shapeless-3)).
164164

165165
#### How to write a type class `derived` method using low level mechanisms
166166

167167
The low-level method we will use to implement a type class `derived` method in this example exploits three new
168-
type-level constructs in Dotty: inline methods, inline matches, and implicit searches via `summonInline` or `summonFrom`. Given this definition of the
168+
type-level constructs in Scala 3: inline methods, inline matches, and implicit searches via `summonInline` or `summonFrom`. Given this definition of the
169169
`Eq` type class,
170170

171171

@@ -194,7 +194,7 @@ call sites (for instance the compiler generated instance definitions in the comp
194194

195195
The body of this method (1) first materializes the `Eq` instances for all the child types of type the instance is
196196
being derived for. This is either all the branches of a sum type or all the fields of a product type. The
197-
implementation of `summonAll` is `inline` and uses Dotty's `summonInline` construct to collect the instances as a
197+
implementation of `summonAll` is `inline` and uses Scala 3's `summonInline` construct to collect the instances as a
198198
`List`,
199199

200200
```scala
@@ -319,7 +319,7 @@ given derived$Eq[T](using eqT: Eq[T]): Eq[Opt[T]] =
319319
```
320320

321321
Alternative approaches can be taken to the way that `derived` methods can be defined. For example, more aggressively
322-
inlined variants using Dotty macros, whilst being more involved for type class authors to write than the example
322+
inlined variants using Scala 3 macros, whilst being more involved for type class authors to write than the example
323323
above, can produce code for type classes like `Eq` which eliminate all the abstraction artefacts (eg. the `Lists` of
324324
child instances in the above) and generate code which is indistinguishable from what a programmer might write by hand.
325325
As a third example, using a higher level library such as shapeless the type class author could define an equivalent
@@ -402,8 +402,8 @@ lockstep and it has to assert this conformance in some places using casts. If ge
402402
written these casts will never fail.
403403

404404
As mentioned, however, the compiler-provided mechanism is intentionally very low level and it is anticipated that
405-
higher level type class derivation and generic programming libraries will build on this and Dotty's other
405+
higher level type class derivation and generic programming libraries will build on this and Scala 3's other
406406
metaprogramming facilities to hide these low-level details from type class authors and general users. Type class
407407
derivation in the style of both shapeless and Magnolia are possible (a prototype of shapeless 3, which combines
408408
aspects of both shapeless 2 and Magnolia has been developed alongside this language feature) as is a more aggressively
409-
inlined style, supported by Dotty's new quote/splice macro and inlining facilities.
409+
inlined style, supported by Scala 3's new quote/splice macro and inlining facilities.

docs/docs/reference/contextual/motivation.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Particular criticisms are:
3535
```
3636
one cannot write `currentMap("abc")` since the string "abc" is taken as explicit argument to the implicit `ctx` parameter. One has to write `currentMap.apply("abc")` instead, which is awkward and irregular. For the same reason, a method definition can only have one implicit parameter section and it must always come last. This restriction not only reduces orthogonality, but also prevents some useful program constructs, such as a method with a regular parameter whose type depends on an implicit value. Finally, it's also a bit annoying that implicit parameters must have a name, even though in many cases that name is never referenced.
3737

38-
5. Implicits pose challenges for tooling. The set of available implicits depends on context, so command completion has to take context into account. This is feasible in an IDE but docs like ScalaDoc that are based static web pages can only provide an approximation. Another problem is that failed implicit searches often give very unspecific error messages, in particular if some deeply recursive implicit search has failed. Note that the Dotty compiler has already made a lot of progress in the error diagnostics area. If a recursive search fails some levels down, it shows what was constructed and what is missing. Also, it suggests imports that can bring missing implicits in scope.
38+
5. Implicits pose challenges for tooling. The set of available implicits depends on context, so command completion has to take context into account. This is feasible in an IDE but docs like ScalaDoc that are based static web pages can only provide an approximation. Another problem is that failed implicit searches often give very unspecific error messages, in particular if some deeply recursive implicit search has failed. Note that the Scala 3 compiler has already made a lot of progress in the error diagnostics area. If a recursive search fails some levels down, it shows what was constructed and what is missing. Also, it suggests imports that can bring missing implicits in scope.
3939

4040
None of the shortcomings is fatal, after all implicits are very widely used, and many libraries and applications rely on them. But together, they make code using implicits a lot more cumbersome and less clear than it could be.
4141

@@ -78,4 +78,3 @@ Could we achieve the same goals by tweaking existing implicits? After having tri
7878
- Third, even if we would somehow succeed with migration, we still have the problem
7979
how to teach this. We cannot make existing tutorials go away. Almost all existing tutorials start with implicit conversions, which will go away; they use normal imports, which will go away, and they explain calls to methods with implicit parameters by expanding them to plain applications, which will also go away. This means that we'd have
8080
to add modifications and qualifications to all existing literature and courseware, likely causing more confusion with beginners instead of less. By contrast, with a new syntax there is a clear criterion: Any book or courseware that mentions `implicit` is outdated and should be updated.
81-

docs/docs/reference/contextual/relationship-implicits.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ asked for.
103103

104104
Context bounds are the same in both language versions. They expand to the respective forms of implicit parameters.
105105

106-
**Note:** To ease migration, context bounds in Dotty map for a limited time to old-style implicit parameters for which arguments can be passed either in a using clause or
106+
**Note:** To ease migration, context bounds in Scala 3 map for a limited time to old-style implicit parameters for which arguments can be passed either in a using clause or
107107
in a normal argument list. Once old-style implicits are deprecated, context bounds
108108
will map to using clauses instead.
109109

@@ -141,7 +141,7 @@ Implicit by-name parameters are not supported in Scala 2, but can be emulated to
141141

142142
### Implicit Conversions
143143

144-
Implicit conversion methods in Scala 2 can be expressed as given instances of the `scala.Conversion` class in Dotty. E.g. instead of
144+
Implicit conversion methods in Scala 2 can be expressed as given instances of the `scala.Conversion` class in Scala 3. E.g. instead of
145145

146146
```scala
147147
implicit def stringToToken(str: String): Token = new Keyword(str)
@@ -162,18 +162,18 @@ given stringToToken: Conversion[String, Token] = KeyWord(_)
162162

163163
### Implicit Classes
164164

165-
Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Dotty. Other uses of implicit classes can be simulated by a pair of a regular class and a given `Conversion` instance.
165+
Implicit classes in Scala 2 are often used to define extension methods, which are directly supported in Scala 3. Other uses of implicit classes can be simulated by a pair of a regular class and a given `Conversion` instance.
166166

167167
### Implicit Values
168168

169-
Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias given.
169+
Implicit `val` definitions in Scala 2 can be expressed in Scala 3 using a regular `val` definition and an alias given.
170170
E.g., Scala 2's
171171

172172
```scala
173173
lazy implicit val pos: Position = tree.sourcePos
174174
```
175175

176-
can be expressed in Dotty as
176+
can be expressed in Scala 3 as
177177

178178
```scala
179179
lazy val pos: Position = tree.sourcePos
@@ -182,13 +182,13 @@ given Position = pos
182182

183183
### Abstract Implicits
184184

185-
An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an alias given. E.g., Scala 2's
185+
An abstract implicit `val` or `def` in Scala 2 can be expressed in Scala 3 using a regular abstract definition and an alias given. E.g., Scala 2's
186186

187187
```scala
188188
implicit def symDecorator: SymDecorator
189189
```
190190

191-
can be expressed in Dotty as
191+
can be expressed in Scala 3 as
192192

193193
```scala
194194
def symDecorator: SymDecorator
@@ -197,7 +197,7 @@ given SymDecorator = symDecorator
197197

198198
## Implementation Status and Timeline
199199

200-
The Dotty implementation implements both Scala-2's implicits and the new abstractions. In fact, support for Scala-2's implicits is an essential part of the common language subset between 2.13/2.14 and Dotty.
200+
The Scala 3 implementation implements both Scala-2's implicits and the new abstractions. In fact, support for Scala-2's implicits is an essential part of the common language subset between 2.13/2.14 and Scala 3.
201201
Migration to the new abstractions will be supported by making automatic rewritings available.
202202

203203
Depending on adoption patterns, old style implicits might start to be deprecated in a version following Scala 3.0.

0 commit comments

Comments
 (0)