Skip to content

Commit cad0a36

Browse files
authored
Merge pull request #8974 from tegonal/doc
bundle of doc improvements
2 parents 078fcb7 + 8208739 commit cad0a36

File tree

10 files changed

+56
-46
lines changed

10 files changed

+56
-46
lines changed

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

Lines changed: 4 additions & 4 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-
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.
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.
@@ -39,7 +39,7 @@ affect implicits on the language level.
3939
due to _shadowing_ (where an implicit is hidden by a nested definition)
4040
no longer applies.
4141

42-
3. Package prefixes no longer contribute to the implicit scope of a type.
42+
3. Package prefixes no longer contribute to the implicit search scope of a type.
4343
Example:
4444
```scala
4545
package p
@@ -52,7 +52,7 @@ affect implicits on the language level.
5252
```
5353
Both `a` and `b` are visible as implicits at the point of the definition
5454
of `type C`. However, a reference to `p.o.C` outside of package `p` will
55-
have only `b` in its implicit scope but not `a`.
55+
have only `b` in its implicit search scope but not `a`.
5656

5757
4. The treatment of ambiguity errors has changed. If an ambiguity is encountered
5858
in some recursive step of an implicit search, the ambiguity is propagated to the caller.
@@ -85,7 +85,7 @@ affect implicits on the language level.
8585
5. The treatment of divergence errors has also changed. A divergent implicit is
8686
treated as a normal failure, after which alternatives are still tried. This also makes
8787
sense: Encountering a divergent implicit means that we assume that no finite
88-
solution can be found on the given path, but another path can still be tried. By contrast
88+
solution can be found on the corresponding path, but another path can still be tried. By contrast
8989
most (but not all) divergence errors in Scala 2 would terminate the implicit
9090
search as a whole.
9191

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ val x = -10_000_000_000
5252
```
5353
gives a type error, since without an expected type `-10_000_000_000` is treated by rule (3) as an `Int` literal, but it is too large for that type.
5454

55-
### The FromDigits Class
55+
### The FromDigits Trait
5656

57-
To allow numeric literals, a type simply has to define a given instance of the
57+
To allow numeric literals, a type simply has to define a `given` instance of the
5858
`scala.util.FromDigits` typeclass, or one of its subclasses. `FromDigits` is defined
5959
as follows:
6060
```scala
@@ -153,7 +153,7 @@ object BigFloat {
153153
BigFloat(BigInt(intPart), exponent)
154154
}
155155
```
156-
To accept `BigFloat` literals, all that's needed in addition is a given instance of type
156+
To accept `BigFloat` literals, all that's needed in addition is a `given` instance of type
157157
`FromDigits.Floating[BigFloat]`:
158158
```scala
159159
given FromDigits as FromDigits.Floating[BigFloat] {
@@ -196,7 +196,7 @@ object BigFloat {
196196
}
197197
```
198198
Note that an inline method cannot directly fill in for an abstract method, since it produces
199-
no code that can be executed at runtime. That's why we define an intermediary class
199+
no code that can be executed at runtime. That is why we define an intermediary class
200200
`FromDigits` that contains a fallback implementation which is then overridden by the inline
201201
method in the `FromDigits` given instance. That method is defined in terms of a macro
202202
implementation method `fromDigitsImpl`. Here is its definition:
@@ -220,7 +220,7 @@ implementation method `fromDigitsImpl`. Here is its definition:
220220
```
221221
The macro implementation takes an argument of type `Expr[String]` and yields
222222
a result of type `Expr[BigFloat]`. It tests whether its argument is a constant
223-
string. If that's the case, it converts the string using the `apply` method
223+
string. If that is the case, it converts the string using the `apply` method
224224
and lifts the resulting `BigFloat` back to `Expr` level. For non-constant
225225
strings `fromDigitsImpl(digits)` is simply `apply(digits)`, i.e. everything is
226226
evaluated at runtime in this case.

docs/docs/reference/contextual/multiversal-equality.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ given Eql[B, A] = Eql.derived
6767
The `scala.Eql` object defines a number of `Eql` given instances that together
6868
define a rule book for what standard types can be compared (more details below).
6969

70-
There's also a "fallback" instance named `eqlAny` that allows comparisons
70+
There is also a "fallback" instance named `eqlAny` that allows comparisons
7171
over all types that do not themselves have an `Eql` given. `eqlAny` is defined as follows:
7272

7373
```scala
7474
def eqlAny[L, R]: Eql[L, R] = Eql.derived
7575
```
7676

77-
Even though `eqlAny` is not declared a given, the compiler will still construct an `eqlAny` instance as answer to an implicit search for the
77+
Even though `eqlAny` is not declared as `given`, the compiler will still construct an `eqlAny` instance as answer to an implicit search for the
7878
type `Eql[L, R]`, unless `L` or `R` have `Eql` instances
79-
defined on them, or the language feature `strictEquality` is enabled
79+
defined on them, or the language feature `strictEquality` is enabled.
8080

81-
The primary motivation for having `eqlAny` is backwards compatibility,
82-
if this is of no concern, one can disable `eqlAny` by enabling the language
81+
The primary motivation for having `eqlAny` is backwards compatibility.
82+
If this is of no concern, one can disable `eqlAny` by enabling the language
8383
feature `strictEquality`. As for all language features this can be either
8484
done with an import
8585

@@ -112,7 +112,7 @@ The precise rules for equality checking are as follows.
112112

113113
If the `strictEquality` feature is enabled then
114114
a comparison using `x == y` or `x != y` between values `x: T` and `y: U`
115-
is legal if there is a given of type `Eql[T, U]`.
115+
is legal if there is a `given` of type `Eql[T, U]`.
116116

117117
In the default case where the `strictEquality` feature is not enabled the comparison is
118118
also legal if
@@ -123,8 +123,8 @@ also legal if
123123

124124
Explanations:
125125

126-
- _lifting_ a type `S` means replacing all references to abstract types
127-
in covariant positions of `S` by their upper bound, and to replacing
126+
- _lifting_ a type `S` means replacing all references to abstract types
127+
in covariant positions of `S` by their upper bound, and replacing
128128
all refinement types in covariant positions of `S` by their parent.
129129
- a type `T` has a _reflexive_ `Eql` instance if the implicit search for `Eql[T, T]`
130130
succeeds.
@@ -153,8 +153,9 @@ Instances are defined so that every one of these types has a _reflexive_ `Eql` i
153153
## Why Two Type Parameters?
154154

155155
One particular feature of the `Eql` type is that it takes _two_ type parameters, representing the types of the two items to be compared. By contrast, conventional
156-
implementations of an equality type class take only a single type parameter which represents the common type of _both_ operands. One type parameter is simpler than two, so why go through the additional complication? The reason has to do with the fact that, rather than coming up with a type class where no operation existed before,
157-
we are dealing with a refinement of pre-existing, universal equality. It's best illustrated through an example.
156+
implementations of an equality type class take only a single type parameter which represents the common type of _both_ operands.
157+
One type parameter is simpler than two, so why go through the additional complication? The reason has to do with the fact that, rather than coming up with a type class where no operation existed before,
158+
we are dealing with a refinement of pre-existing, universal equality. It is best illustrated through an example.
158159

159160
Say you want to come up with a safe version of the `contains` method on `List[T]`. The original definition of `contains` in the standard library was:
160161
```scala

docs/docs/reference/metaprogramming/tasty-inspect.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ libraryDependencies += "ch.epfl.lamp" %% "dotty-tasty-inspector" % scalaVersion.
99

1010
TASTy files contain the full typed tree of a class including source positions
1111
and documentation. This is ideal for tools that analyze or extract semantic
12-
information of the code. To avoid the hassle of working directly with the TASTy
12+
information from the code. To avoid the hassle of working directly with the TASTy
1313
file we provide the `TastyInspector` which loads the contents and exposes it
1414
through the TASTy reflect API.
1515

@@ -42,8 +42,8 @@ object Test {
4242
}
4343
```
4444

45-
Note that if we need to run the main (in an object called `Test`) after
46-
compilation we need make available the compiler to the runtime:
45+
Note that if we need to run the main (in the example below defined in an object called `Test`) after
46+
compilation we need to make the compiler available to the runtime:
4747

4848
```shell
4949
dotc -d out Test.scala

docs/docs/reference/metaprogramming/tasty-reflect.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You may find all you need without using TASTy Reflect.
1414
## API: From quotes and splices to TASTy reflect trees and back
1515

1616
With `quoted.Expr` and `quoted.Type` we can compute code but also analyze code
17-
by inspecting the ASTs. [Macros](./macros.md) provides the guarantee that the
17+
by inspecting the ASTs. [Macros](./macros.md) provide the guarantee that the
1818
generation of code will be type-correct. Using TASTy Reflect will break these
1919
guarantees and may fail at macro expansion time, hence additional explicit
2020
checks must be done.
@@ -64,8 +64,7 @@ To easily know which extractors are needed, the `showExtractors` method on a
6464
The method `qctx.tasty.Term.seal` provides a way to go back to a
6565
`quoted.Expr[Any]`. Note that the type is `Expr[Any]`. Consequently, the type
6666
must be set explicitly with a checked `cast` call. If the type does not conform
67-
to it an exception will be thrown. In the code above, we could have replaced
68-
`Expr(n)` by `xTree.seal.cast[Int]`.
67+
to it an exception will be thrown at runtime.
6968

7069
### Obtaining the underlying argument
7170

@@ -92,8 +91,8 @@ macro(this.checkCondition())
9291

9392
### Positions
9493

95-
The tasty context provides a `rootPosition` value. For macros it corresponds to
96-
the expansion site. The macro authors can obtain various information about that
94+
The tasty context provides a `rootPosition` value. It corresponds to
95+
the expansion site for macros. The macro authors can obtain various information about that
9796
expansion site. The example below shows how we can obtain position information
9897
such as the start line, the end line or even the source code at the expansion
9998
point.
@@ -117,10 +116,10 @@ def macroImpl()(qctx: QuoteContext): Expr[Unit] = {
117116
### Tree Utilities
118117

119118
`scala.tasty.reflect` contains three facilities for tree traversal and
120-
transformations.
119+
transformation.
121120

122121
`TreeAccumulator` ties the knot of a traversal. By calling `foldOver(x, tree))`
123-
we can dive in the `tree` node and start accumulating values of type `X` (e.g.,
122+
we can dive into the `tree` node and start accumulating values of type `X` (e.g.,
124123
of type List[Symbol] if we want to collect symbols). The code below, for
125124
example, collects the pattern variables of a tree.
126125

@@ -142,8 +141,8 @@ but without returning any value. Finally a `TreeMap` performs a transformation.
142141
#### Let
143142

144143
`scala.tasty.Reflection` also offers a method `let` that allows us
145-
to bind the `rhs` to a `val` and use it in `body`. Additionally, `lets` binds
146-
the given `terms` to names and use them in the `body`. Their type definitions
144+
to bind the `rhs` (right-hand side) to a `val` and use it in `body`. Additionally, `lets` binds
145+
the given `terms` to names and allows to use them in the `body`. Their type definitions
147146
are shown below:
148147

149148
```scala

docs/docs/reference/new-types/intersection-types-spec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ A & B <: B A & B <: A
4545
In another word, `A & B` is the same type as `B & A`, in the sense that the two types
4646
have the same values and are subtypes of each other.
4747

48-
If `C` is a type constructor, the join `C[A] & C[B]` is simplified by pulling the
49-
intersection inside the constructor, using the following two rules:
48+
If `C` is a type constructor, then `C[A] & C[B]` can be simplified using the following three rules:
5049

5150
- If `C` is covariant, `C[A] & C[B] ~> C[A & B]`
5251
- If `C` is contravariant, `C[A] & C[B] ~> C[A | B]`
52+
- If `C` is non-variant, emit a compile error
5353

5454
When `C` is covariant, `C[A & B] <: C[A] & C[B]` can be derived:
5555

docs/docs/reference/new-types/intersection-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ The type `S & T` represents values that are of the type `S` and `T` at the same
1111

1212
```scala
1313
trait Resettable {
14-
def reset(): this.type
14+
def reset(): Unit
1515
}
1616
trait Growable[T] {
17-
def add(x: T): this.type
17+
def add(t: T): Unit
1818
}
1919
def f(x: Resettable & Growable[String]) = {
2020
x.reset()
2121
x.add("first")
2222
}
2323
```
2424

25-
The value `x` is required to be _both_ a `Resettable` and a
25+
The parameter `x` is required to be _both_ a `Resettable` and a
2626
`Growable[String]`.
2727

2828
The members of an intersection type `A & B` are all the members of `A` and all
@@ -51,8 +51,8 @@ can be further simplified to `List[A & B]` because `List` is
5151
covariant.
5252

5353
One might wonder how the compiler could come up with a definition for
54-
`children` of type `List[A & B]` since all its is given are `children`
55-
definitions of type `List[A]` and `List[B]`. The answer is it does not
54+
`children` of type `List[A & B]` since what is given are `children`
55+
definitions of type `List[A]` and `List[B]`. The answer is the compiler does not
5656
need to. `A & B` is just a type that represents a set of requirements for
5757
values of the type. At the point where a value is _constructed_, one
5858
must make sure that all inherited members are correctly defined.

docs/docs/reference/new-types/union-types-spec.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ class A extends C[A] with D
7676
class B extends C[B] with D with E
7777
```
7878

79-
The join of `A | B` is `C[A | B] with D`
79+
The join of `A | B` is `C[A | B] & D`
8080

8181
## Type inference
8282

83-
When inferring the result type of a definition (`val`, `var`, or `def`), if the
84-
type we are about to infer is a union type, we replace it by its join.
83+
When inferring the result type of a definition (`val`, `var`, or `def`) and the
84+
type we are about to infer is a union type, then we replace it by its join.
8585
Similarly, when instantiating a type argument, if the corresponding type
8686
parameter is not upper-bounded by a union type and the type we are about to
8787
instantiate is a union type, we replace it by its join. This mirrors the
8888
treatment of singleton types which are also widened to their underlying type
89-
unless explicitly specified. and the motivation is the same: inferring types
89+
unless explicitly specified. The motivation is the same: inferring types
9090
which are "too precise" can lead to unintuitive typechecking issues later on.
9191

9292
Note: Since this behavior limits the usability of union types, it might
@@ -127,6 +127,14 @@ trait B { def hello: String }
127127
def test(x: A | B) = x.hello // error: value `hello` is not a member of A | B
128128
```
129129

130+
On the otherhand, the following would be allowed
131+
```scala
132+
trait C { def hello: String }
133+
trait A extends C with D
134+
trait B extends C with E
135+
136+
def test(x: A | B) = x.hello // ok as `hello` is a member of the join of A | B which is C
137+
130138
## Exhaustivity checking
131139

132140
If the selector of a pattern match is a union type, the match is considered

docs/docs/reference/other-new-features/export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export O.c
8787
def f: c.T = ...
8888
```
8989

90+
<a id="note_class"></a>
9091
Export clauses can appear in classes or they can appear at the top-level. An export clause cannot appear as a statement in a block.
9192

92-
<a id="note_class"></a>
9393
(\*) Note: Unless otherwise stated, the term "class" in this discussion also includes object and trait definitions.
9494

9595
### Motivation

docs/docs/reference/other-new-features/named-typeargs.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: "Named Type Arguments"
55

66
**Note:** This feature is implemented in Dotty, but is not expected to be part of Scala 3.0.
77

8-
Type arguments of methods can now be named, as well as by position. Example:
8+
Type arguments of methods can now be specified by name as well as by position. Example:
99

1010
``` scala
1111
def construct[Elem, Coll[_]](xs: Elem*): Coll[Elem] = ???
@@ -15,8 +15,10 @@ val xs2 = construct[Coll = List](1, 2, 3)
1515
```
1616

1717
Similar to a named value argument `(x = e)`, a named type argument
18-
`[X = T]` instantiates the type parameter `X` to the type `T`. Type
19-
arguments must be all named or un-named, mixtures of named and
18+
`[X = T]` instantiates the type parameter `X` to the type `T`.
19+
Named type arguments do not have to be in order (see `xs1` above) and
20+
unspecified arguments are inferred by the compiler (see `xs2` above).
21+
Type arguments must be all named or un-named, mixtures of named and
2022
positional type arguments are not supported.
2123

2224
## Motivation

0 commit comments

Comments
 (0)