Skip to content

Commit 2100d36

Browse files
committed
Expunge remaining usages of "delegate" in docs
1 parent de10072 commit 2100d36

File tree

9 files changed

+41
-41
lines changed

9 files changed

+41
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ affect implicits on the language level.
4343
Example:
4444

4545
package p
46-
delegate a for A
46+
given a as A
4747

4848
object o {
49-
delegate b for B
49+
given b as B
5050
type C
5151
}
5252

docs/docs/reference/contextual/derivation.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ a mirror over that array, and finally uses the `reify` method in `Reflected` to
215215

216216
### How to Write Generic Typeclasses
217217

218-
Based on the machinery developed so far it becomes possible to define type classes generically. This means that the `derived` method will compute a type class delegate for any ADT that has a `Generic` delegate, recursively.
218+
Based on the machinery developed so far it becomes possible to define type classes generically. This means that the `derived` method will compute a type class instance for any ADT that has a given `Generic` instance, recursively.
219219
The implementation of these methods typically uses three new type-level constructs in Dotty: inline methods, inline matches, and implicit matches. As an example, here is one possible implementation of a generic `Eql` type class, with explanations. Let's assume `Eql` is defined by the following trait:
220220
```scala
221221
trait Eql[T] {
222222
def eql(x: T, y: T): Boolean
223223
}
224224
```
225-
We need to implement a method `Eql.derived` that produces a delegate for `Eql[T]` provided
226-
there exists a delegate for `Generic[T]`. Here's a possible solution:
225+
We need to implement a method `Eql.derived` that produces a given instance for `Eql[T]` provided
226+
a given `Generic[T]`. Here's a possible solution:
227227
```scala
228228
inline def derived[T] given (ev: Generic[T]): Eql[T] = new Eql[T] {
229229
def eql(x: T, y: T): Boolean = {
@@ -239,7 +239,7 @@ there exists a delegate for `Generic[T]`. Here's a possible solution:
239239
}
240240
}
241241
```
242-
The implementation of the inline method `derived` creates a delegate for `Eql[T]` and implements its `eql` method. The right-hand side of `eql` mixes compile-time and runtime elements. In the code above, runtime elements are marked with a number in parentheses, i.e
242+
The implementation of the inline method `derived` creates a given instance for `Eql[T]` and implements its `eql` method. The right-hand side of `eql` mixes compile-time and runtime elements. In the code above, runtime elements are marked with a number in parentheses, i.e
243243
`(1)`, `(2)`, `(3)`. Compile-time calls that expand to runtime code are marked with a number in brackets, i.e. `[4]`, `[5]`. The implementation of `eql` consists of the following steps.
244244

245245
1. Map the compared values `x` and `y` to their mirrors using the `reflect` method of the implicitly passed `Generic` `(1)`, `(2)`.
@@ -310,16 +310,16 @@ The last, and in a sense most interesting part of the derivation is the comparis
310310
case ev: Eql[T] =>
311311
ev.eql(x, y) // (15)
312312
case _ =>
313-
error("No `Eql` delegate was found for $T")
313+
error("No `Eql` instance was found for $T")
314314
}
315315
```
316-
`tryEql` is an inline method that takes an element type `T` and two element values of that type as arguments. It is defined using an `implicit match` that tries to find a delegate for `Eql[T]`. If a delegate `ev` is found, it proceeds by comparing the arguments using `ev.eql`. On the other hand, if no delegate is found
317-
this signals a compilation error: the user tried a generic derivation of `Eql` for a class with an element type that does not have an `Eql` delegate itself. The error is signaled by
316+
`tryEql` is an inline method that takes an element type `T` and two element values of that type as arguments. It is defined using an `implicit match` that tries to find a given instance for `Eql[T]`. If an instance `ev` is found, it proceeds by comparing the arguments using `ev.eql`. On the other hand, if no instance is found
317+
this signals a compilation error: the user tried a generic derivation of `Eql` for a class with an element type that does not have an `Eql` instance itself. The error is signaled by
318318
calling the `error` method defined in `scala.compiletime`.
319319

320320
**Note:** At the moment our error diagnostics for metaprogramming does not support yet interpolated string arguments for the `scala.compiletime.error` method that is called in the second case above. As an alternative, one can simply leave off the second case, then a missing typeclass would result in a "failure to reduce match" error.
321321

322-
**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eql` delegate for class `Tree`.
322+
**Example:** Here is a slightly polished and compacted version of the code that's generated by inline expansion for the derived `Eql` instance for class `Tree`.
323323

324324
```scala
325325
given [T] as Eql[Tree[T]] where (elemEq: Eql[T]) {
@@ -341,21 +341,21 @@ given [T] as Eql[Tree[T]] where (elemEq: Eql[T]) {
341341
}
342342
```
343343

344-
One important difference between this approach and Scala-2 typeclass derivation frameworks such as Shapeless or Magnolia is that no automatic attempt is made to generate typeclass delegates for elements recursively using the generic derivation framework. There must be a delegate for `Eql[T]` (which can of course be produced in turn using `Eql.derived`), or the compilation will fail. The advantage of this more restrictive approach to typeclass derivation is that it avoids uncontrolled transitive typeclass derivation by design. This keeps code sizes smaller, compile times lower, and is generally more predictable.
344+
One important difference between this approach and Scala-2 typeclass derivation frameworks such as Shapeless or Magnolia is that no automatic attempt is made to generate typeclass instances for elements recursively using the generic derivation framework. There must be a given instance for `Eql[T]` (which can of course be produced in turn using `Eql.derived`), or the compilation will fail. The advantage of this more restrictive approach to typeclass derivation is that it avoids uncontrolled transitive typeclass derivation by design. This keeps code sizes smaller, compile times lower, and is generally more predictable.
345345

346-
### Deriving Delegates Elsewhere
346+
### Deriving Instances Elsewhere
347347

348-
Sometimes one would like to derive a typeclass delegate for an ADT after the ADT is defined, without being able to change the code of the ADT itself.
349-
To do this, simply define a delegate with the `derived` method of the typeclass as right-hand side. E.g, to implement `Ordering` for `Option`, define:
348+
Sometimes one would like to derive a typeclass instance for an ADT after the ADT is defined, without being able to change the code of the ADT itself.
349+
To do this, simply define an instance with the `derived` method of the typeclass as right-hand side. E.g, to implement `Ordering` for `Option`, define:
350350
```scala
351-
delegate [T: Ordering]: Ordering[Option[T]] = Ordering.derived
351+
instance [T: Ordering] as Ordering[Option[T]] = Ordering.derived
352352
```
353353
Usually, the `Ordering.derived` clause has an implicit parameter of type
354354
`Generic[Option[T]]`. Since the `Option` trait has a `derives` clause,
355-
the necessary delegate is already present in the companion object of `Option`.
356-
If the ADT in question does not have a `derives` clause, a `Generic` delegate
355+
the necessary instance is already present in the companion object of `Option`.
356+
If the ADT in question does not have a `derives` clause, a `Generic` instance
357357
would still be synthesized by the compiler at the point where `derived` is called.
358-
This is similar to the situation with type tags or class tags: If no delegate
358+
This is similar to the situation with type tags or class tags: If no instance
359359
is found, the compiler will synthesize one.
360360

361361
### Syntax
@@ -371,7 +371,7 @@ ConstrApps ::= ConstrApp {‘with’ ConstrApp}
371371
### Discussion
372372

373373
The typeclass derivation framework is quite small and low-level. There are essentially
374-
two pieces of infrastructure in the compiler-generated `Generic` delegates:
374+
two pieces of infrastructure in the compiler-generated `Generic` instances:
375375

376376
- a type representing the shape of an ADT,
377377
- a way to map between ADT instances and generic mirrors.

docs/docs/reference/features-classification.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Since these are additions, there's generally no migration cost for old code. An
3636
These constructs replace existing constructs with the aim of making the language safer and simpler to use, and to promote uniformity in code style.
3737

3838
- [Trait Parameters](other-new-features/trait-parameters.md) replace [early initializers](dropped-features/early-initializers.md) with a more generally useful construct.
39-
- [Delegates](contextual/delegates.md)
39+
- [Given Instances](contextual/delegates.md)
4040
replace implicit objects and defs, focussing on intent over mechanism.
4141
- [Given Clauses](contextual/given-clauses.md) replace implicit parameters, avoiding their ambiguities.
4242
- [Extension Methods](contextual/extension-methods.md) replace implicit classes with a clearer and simpler mechanism.
@@ -71,7 +71,7 @@ For the next several versions, old features will remain available and deprecatio
7171
These constructs are restricted to make the language safer.
7272

7373
- [Implicit Conversions](contextual/conversions.md): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import.
74-
- [Delegate Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
74+
- [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
7575
- [Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound.
7676
- [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
7777
- [@infix and @alpha](https://github.com/lampepfl/dotty/pull/5975)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ With the right extractors, the "AsFunction" conversion
190190
that maps expressions over functions to functions over expressions can
191191
be implemented in user code:
192192
```scala
193-
delegate AsFunction1[T, U] for Conversion[Expr[T => U], Expr[T] => Expr[U]] {
193+
given AsFunction1[T, U] as Conversion[Expr[T => U], Expr[T] => Expr[U]] {
194194
def apply(f: Expr[T => U]): Expr[T] => Expr[U] =
195195
(x: Expr[T]) => f match {
196196
case Lambda(g) => g(x)

docs/docs/reference/metaprogramming/macros.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ would be rewritten to
194194
def reflect[T: Type, U: Type](f: Expr[T] => Expr[U]): Expr[T => U] =
195195
'{ (x: ${ the[Type[T]] }) => ${ f('x) } }
196196
```
197-
The `the` query succeeds because there is a delegate of
197+
The `the` query succeeds because there is a given instance of
198198
type `Type[T]` available (namely the given parameter corresponding
199199
to the context bound `: Type`), and the reference to that value is
200200
phase-correct. If that was not the case, the phase inconsistency for
@@ -224,7 +224,7 @@ Here’s a compiler that maps an expression given in the interpreted
224224
language to quoted Scala code of type `Expr[Int]`.
225225
The compiler takes an environment that maps variable names to Scala `Expr`s.
226226
```scala
227-
import delegate scala.quoted._
227+
import given scala.quoted._
228228

229229
def compile(e: Exp, env: Map[String, Expr[Int]]): Expr[Int] = e match {
230230
case Num(n) =>
@@ -251,15 +251,15 @@ The `toExpr` extension method is defined in package `quoted`:
251251
```scala
252252
package quoted
253253

254-
delegate ExprOps {
254+
given ExprOps {
255255
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
256256
...
257257
}
258258
```
259259
The extension says that values of types implementing the `Liftable` type class can be
260-
converted ("lifted") to `Expr` values using `toExpr`, provided a delegate import of `scala.quoted._` is in scope.
260+
converted ("lifted") to `Expr` values using `toExpr`, provided a given import of `scala.quoted._` is in scope.
261261

262-
Dotty comes with delegate definitions of `Liftable` for
262+
Dotty comes with given instances of `Liftable` for
263263
several types including `Boolean`, `String`, and all primitive number
264264
types. For example, `Int` values can be converted to `Expr[Int]`
265265
values by wrapping the value in a `Literal` tree node. This makes use
@@ -269,7 +269,7 @@ in the sense that they could all be defined in a user program without
269269
knowing anything about the representation of `Expr` trees. For
270270
instance, here is a possible instance of `Liftable[Boolean]`:
271271
```scala
272-
delegate for Liftable[Boolean] {
272+
given as Liftable[Boolean] {
273273
def toExpr(b: Boolean) given QuoteContext: Expr[Boolean] =
274274
if (b) '{ true } else '{ false }
275275
}
@@ -278,7 +278,7 @@ Once we can lift bits, we can work our way up. For instance, here is a
278278
possible implementation of `Liftable[Int]` that does not use the underlying
279279
tree machinery:
280280
```scala
281-
delegate for Liftable[Int] {
281+
given as Liftable[Int] {
282282
def toExpr(n: Int) given QuoteContext: Expr[Int] = n match {
283283
case Int.MinValue => '{ Int.MinValue }
284284
case _ if n < 0 => '{ - ${ toExpr(-n) } }
@@ -291,7 +291,7 @@ tree machinery:
291291
Since `Liftable` is a type class, its instances can be conditional. For example,
292292
a `List` is liftable if its element type is:
293293
```scala
294-
delegate [T: Liftable] for Liftable[List[T]] {
294+
given [T: Liftable] as Liftable[List[T]] {
295295
def toExpr(xs: List[T]) given QuoteContext: Expr[List[T]] = xs match {
296296
case head :: tail => '{ ${ toExpr(head) } :: ${ toExpr(tail) } }
297297
case Nil => '{ Nil: List[T] }
@@ -337,7 +337,7 @@ implicit search. For instance, to implement
337337
the[Type[List[T]]]
338338
```
339339
where `T` is not defined in the current stage, we construct the type constructor
340-
of `List` applied to the splice of the result of searching for a delegate for `Type[T]`:
340+
of `List` applied to the splice of the result of searching for a given instance for `Type[T]`:
341341
```scala
342342
'[ List[ ${ the[Type[T]] } ] ]
343343
```

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ They can be accessed inside `Copier` as well as from outside:
4343
An export clause has the same format as an import clause. Its general form is:
4444
```scala
4545
export path . { sel_1, ..., sel_n }
46-
export delegate path . { sel_1, ..., sel_n }
46+
export given path . { sel_1, ..., sel_n }
4747
```
4848
It consists of a qualifier expression `path`, which must be a stable identifier, followed by
4949
one or more selectors `sel_i` that identify what gets an alias. Selectors can be
@@ -61,14 +61,14 @@ A member is _eligible_ if all of the following holds:
6161
- its owner is not a base class of the class(*) containing the export clause,
6262
- it is accessible at the export clause,
6363
- it is not a constructor, nor the (synthetic) class part of an object,
64-
- it is delegate (or an old-style `implicit` value)
65-
if and only if the export is tagged with `delegate`.
64+
- it is a given instance (or an old-style `implicit` value)
65+
if and only if the export is tagged with `given`.
6666

6767
It is a compile-time error if a simple or renaming selector does not identify any eligible
6868
members.
6969

7070
Type members are aliased by type definitions, and term members are aliased by method definitions. Export aliases copy the type and value parameters of the members they refer to.
71-
Export aliases are always `final`. Aliases of delegates are again defines as delegates (and aliases of old-style implicits are `implicit`). There are no other modifiers that can be given to an alias. This has the following consequences for overriding:
71+
Export aliases are always `final`. Aliases of given instances are again defined as givens (and aliases of old-style implicits are `implicit`). There are no other modifiers that can be given to an alias. This has the following consequences for overriding:
7272

7373
- Export aliases cannot be overridden, since they are final.
7474
- Export aliases cannot override concrete members in base classes, since they are
@@ -105,7 +105,7 @@ TemplateStat ::= ...
105105
| Export
106106
TopStat ::= ...
107107
| Export
108-
Export ::= ‘export’ [‘delegate’] ImportExpr {‘,’ ImportExpr}
108+
Export ::= ‘export’ [‘given’] ImportExpr {‘,’ ImportExpr}
109109
```
110110

111111
### Elaboration of Export Clauses

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Logarithms {
2020
}
2121

2222
// Extension methods define opaque types' public APIs
23-
delegate LogarithmOps {
23+
given LogarithmOps {
2424
def (x: Logarithm) toDouble: Double = math.exp(x)
2525
def (x: Logarithm) + (y: Logarithm): Logarithm = Logarithm(math.exp(x) + math.exp(y))
2626
def (x: Logarithm) * (y: Logarithm): Logarithm = Logarithm(x + y)

docs/docs/reference/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ These new constructs directly model core features of DOT, higher-kinded types, a
3333
These constructs replace existing constructs with the aim of making the language safer and simpler to use, and to promote uniformity in code style.
3434

3535
- [Trait Parameters](other-new-features/trait-parameters.md) replace [early initializers](dropped-features/early-initializers.md) with a more generally useful construct.
36-
- [Delegates](contextual/delegates.md)
36+
- [Given Instances](contextual/delegates.md)
3737
replace implicit objects and defs, focussing on intent over mechanism.
3838
- [Given Clauses](contextual/given-clauses.md) replace implicit parameters, avoiding their ambiguities.
3939
- [Extension Methods](contextual/extension-methods.md) replace implicit classes with a clearer and simpler mechanism.
@@ -58,7 +58,7 @@ e a special case. There are currently no deprecation plans for value classes, si
5858
These constructs are restricted to make the language safer.
5959

6060
- [Implicit Conversions](contextual/conversions.md): there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import.
61-
- [Delegate Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
61+
- [Given Imports](contextual/import-delegate.md): implicits now require a special form of import, to make the import clearly visible.
6262
- [Type Projection](dropped-features/type-projection.md): only classes can be used as prefix `C` of a type projection `C#A`. Type projection on abstract types is no longer supported since it is unsound.
6363
- [Multiversal Equality](contextual/multiversal-equality.md) implements an "opt-in" scheme to rule out nonsensical comparisons with `==` and `!=`.
6464
- [@infix and @alpha](https://github.com/lampepfl/dotty/pull/5975)

docs/sidebar.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ sidebar:
4343
subsection:
4444
- title: Overview
4545
url: docs/reference/contextual/motivation.html
46-
- title: Delegates
46+
- title: Given Instances
4747
url: docs/reference/contextual/delegates.html
4848
- title: Given Clauses
4949
url: docs/reference/contextual/given-clauses.html
5050
- title: Context Bounds
5151
url: docs/reference/contextual/context-bounds.html
52-
- title: Delegate Imports
52+
- title: Given Imports
5353
url: docs/reference/contextual/import-delegate.html
5454
- title: Extension Methods
5555
url: docs/reference/contextual/extension-methods.html

0 commit comments

Comments
 (0)