Skip to content

Commit d59e8b3

Browse files
Merge pull request #8189 from dotty-staging/update-dcos
Update docs to 0.22RC
2 parents 957a80f + 4af5911 commit d59e8b3

34 files changed

+272
-2246
lines changed

docs/docs/reference/contextual/context-bounds-new.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/docs/reference/contextual/context-bounds.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,36 @@ layout: doc-page
33
title: "Context Bounds"
44
---
55

6-
**Note** The syntax described in this section is currently under revision.
7-
[Here is the new version which will be implemented in Dotty 0.22](./context-bounds-new.html).
8-
96
## Context Bounds
107

11-
A context bound is a shorthand for expressing the common pattern of an implicit parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
8+
A context bound is a shorthand for expressing the common pattern of a context parameter that depends on a type parameter. Using a context bound, the `maximum` function of the last section can be written like this:
129
```scala
1310
def maximum[T: Ord](xs: List[T]): T = xs.reduceLeft(max)
1411
```
15-
A bound like `: Ord` on a type parameter `T` of a method or class indicates an implicit parameter `(given Ord[T])`. The implicit parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
12+
A bound like `: Ord` on a type parameter `T` of a method or class indicates a context parameter `with Ord[T]`. The context parameter(s) generated from context bounds come last in the definition of the containing method or class. E.g.,
1613
```scala
17-
def f[T: C1 : C2, U: C3](x: T)(given y: U, z: V): R
14+
def f[T: C1 : C2, U: C3](x: T)(using y: U, z: V): R
1815
```
1916
would expand to
2017
```scala
21-
def f[T, U](x: T)(given y: U, z: V)(given C1[T], C2[T], C3[U]): R
18+
def f[T, U](x: T)(using y: U, z: V)(using C1[T], C2[T], C3[U]): R
2219
```
2320
Context bounds can be combined with subtype bounds. If both are present, subtype bounds come first, e.g.
2421
```scala
2522
def g[T <: B : C](x: T): R = ...
2623
```
2724

28-
## Syntax
25+
### Migration
26+
27+
To ease migration, context bounds in Dotty map in Scala 3.0 to old-style implicit parameters
28+
for which arguments can be passed either with a `(using ...)` clause or with a normal application. From Scala 3.1 on, they will map to context parameters instead, as is described above.
29+
30+
If the source version is `3.1` and the `-migration` command-line option is set, any pairing of an evidence
31+
context parameter stemming from a context bound with a normal argument will give a migration
32+
warning. The warning indicates that a `(using ...)` clause is needed instead. The rewrite can be
33+
done automatically under `-rewrite`.
34+
35+
### Syntax
2936

3037
```
3138
TypeParamBounds ::= [SubtypeBounds] {ContextBound}

docs/docs/reference/contextual/conversions-new.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

docs/docs/reference/contextual/conversions.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ layout: doc-page
33
title: "Implicit Conversions"
44
---
55

6-
**Note** The syntax described in this section is currently under revision.
7-
[Here is the new version which will be implemented in Dotty 0.22](./conversions-new.html).
8-
96
Implicit conversions are defined by given instances of the `scala.Conversion` class.
107
This class is defined in package `scala` as follows:
118
```scala
@@ -28,19 +25,19 @@ An implicit conversion is applied automatically by the compiler in three situati
2825
3. In an application `e.m(args)` with `e` of type `T`, if `T` does define
2926
some member(s) named `m`, but none of these members can be applied to the arguments `args`.
3027

31-
In the first case, the compiler looks for a given `scala.Conversion` that maps
28+
In the first case, the compiler looks for a given `scala.Conversion` instance that maps
3229
an argument of type `T` to type `S`. In the second and third
33-
case, it looks for a given `scala.Conversion` that maps an argument of type `T`
30+
case, it looks for a given `scala.Conversion` instance that maps an argument of type `T`
3431
to a type that defines a member `m` which can be applied to `args` if present.
35-
If such an instance `C` is given, the expression `e` is replaced by `C.apply(e)`.
32+
If such an instance `C` is found, the expression `e` is replaced by `C.apply(e)`.
3633

3734
## Examples
3835

3936
1. The `Predef` package contains "auto-boxing" conversions that map
4037
primitive number types to subclasses of `java.lang.Number`. For instance, the
4138
conversion from `Int` to `java.lang.Integer` can be defined as follows:
4239
```scala
43-
given int2Integer: Conversion[Int, java.lang.Integer] =
40+
given int2Integer as Conversion[Int, java.lang.Integer] =
4441
java.lang.Integer.valueOf(_)
4542
```
4643

@@ -62,9 +59,9 @@ object Completions {
6259
//
6360
// CompletionArg.fromStatusCode(statusCode)
6461

65-
given fromString : Conversion[String, CompletionArg] = Error(_)
66-
given fromFuture : Conversion[Future[HttpResponse], CompletionArg] = Response(_)
67-
given fromStatusCode : Conversion[Future[StatusCode], CompletionArg] = Status(_)
62+
given fromString as Conversion[String, CompletionArg] = Error(_)
63+
given fromFuture as Conversion[Future[HttpResponse], CompletionArg] = Response(_)
64+
given fromStatusCode as Conversion[Future[StatusCode], CompletionArg] = Status(_)
6865
}
6966
import CompletionArg._
7067

docs/docs/reference/contextual/delegates.md

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,4 @@ layout: doc-page
33
title: "Given Instances"
44
---
55

6-
**Note** The syntax described in this section is currently under revision.
7-
[Here is the new version which will be implemented in Dotty 0.22](./givens.html).
8-
9-
Given instances (or, simply, "givens") define "canonical" values of certain types
10-
that serve for synthesizing arguments to [given clauses](./given-clauses.md). Example:
11-
12-
```scala
13-
trait Ord[T] {
14-
def compare(x: T, y: T): Int
15-
def (x: T) < (y: T) = compare(x, y) < 0
16-
def (x: T) > (y: T) = compare(x, y) > 0
17-
}
18-
19-
given intOrd: Ord[Int] {
20-
def compare(x: Int, y: Int) =
21-
if (x < y) -1 else if (x > y) +1 else 0
22-
}
23-
24-
given listOrd[T](given ord: Ord[T]): Ord[List[T]] {
25-
26-
def compare(xs: List[T], ys: List[T]): Int = (xs, ys) match {
27-
case (Nil, Nil) => 0
28-
case (Nil, _) => -1
29-
case (_, Nil) => +1
30-
case (x :: xs1, y :: ys1) =>
31-
val fst = ord.compare(x, y)
32-
if (fst != 0) fst else compare(xs1, ys1)
33-
}
34-
}
35-
```
36-
This code defines a trait `Ord` with two given instances. `intOrd` defines
37-
a given for the type `Ord[Int]` whereas `listOrd[T]` defines givens
38-
for `Ord[List[T]]` for all types `T` that come with a given instance for `Ord[T]` themselves.
39-
The `(given ord: Ord[T])` clause in `listOrd` defines an implicit parameter.
40-
Given clauses are further explained in the [next section](./given-clauses.md).
41-
42-
## Anonymous Given Instances
43-
44-
The name of a given instance can be left out. So the definitions
45-
of the last section can also be expressed like this:
46-
```scala
47-
given Ord[Int] { ... }
48-
given [T](given Ord[T]): Ord[List[T]] { ... }
49-
```
50-
If the name of a given is missing, the compiler will synthesize a name from
51-
the implemented type(s).
52-
53-
## Alias Givens
54-
55-
An alias can be used to define a given instance that is equal to some expression. E.g.:
56-
```scala
57-
given global: ExecutionContext = new ForkJoinPool()
58-
```
59-
This creates a given `global` of type `ExecutionContext` that resolves to the right
60-
hand side `new ForkJoinPool()`.
61-
The first time `global` is accessed, a new `ForkJoinPool` is created, which is then
62-
returned for this and all subsequent accesses to `global`.
63-
64-
Alias givens can be anonymous, e.g.
65-
```scala
66-
given Position = enclosingTree.position
67-
given (given outer: Context): Context = outer.withOwner(currentOwner)
68-
```
69-
An alias given can have type parameters and given clauses just like any other given instance, but it can only implement a single type.
70-
71-
## Given Instance Initialization
72-
73-
A given instance without type parameters or given clause is initialized on-demand, the first
74-
time it is accessed.
75-
If a `given` definition has type parameters or a given clause, a fresh instance is created for each reference.
76-
77-
## Syntax
78-
79-
Here is the new syntax of given instances, seen as a delta from the [standard context free syntax of Scala 3](../../internals/syntax.md).
80-
```
81-
TmplDef ::= ...
82-
| ‘given’ GivenDef
83-
GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
84-
| [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [TemplateBody]
85-
GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
86-
GivenParamClause ::= ‘(’ ‘given’ (DefParams | GivenTypes) ‘)’
87-
GivenTypes ::= Type {‘,’ Type}
88-
```
89-
The identifier `id` can be omitted only if some types are implemented or the template body defines at least one extension method.
6+
The contents of this page have [moved](./givens.html).

0 commit comments

Comments
 (0)