Skip to content

Polishingsof instance-of trial #6386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/reference/contextual-instance/conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ instance of Conversion[String, Token] {
def apply(str: String): Token = new KeyWord(str)
}
```
Using an instance alias, this can be expressed more concisely as:
Using an alias instance, this can be expressed more concisely as:
```scala
instance of Conversion[String, Token] = new KeyWord(_)
```
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/reference/contextual-instance/import-implied.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object B {
In the code above, the `import A._` clause of object `B` will import all members
of `A` _except_ the instance `tc`. Conversely, the second import `import instance A._` will import _only_ that instance.

Generally, a normal import clause brings all members except implicit instance values into scope whereas an `import instance` clause brings only implicit instance values into scope.
Generally, a normal import clause brings all members except implicit instances into scope whereas an `import instance` clause brings only implicit instances into scope.

There are two main benefits arising from these rules:

Expand All @@ -32,22 +32,22 @@ There are two main benefits arising from these rules:

### Relationship with Old-Style Implicits

The rules of evidence imports above have the consequence that a library
The rules of instance imports above have the consequence that a library
would have to migrate in lockstep with all its users from old style implicit definitions and
normal imports to evidence definitions and evidence imports.
normal imports to instance definitions and instance imports.

The following modifications avoid this hurdle to migration.

1. An evidence import also brings old style implicits into scope. So, in Scala 3.0
1. An instance import also brings old style implicits into scope. So, in Scala 3.0
an old-style implicit definition can be brought into scope either by a normal or
by an evidence import.
by an instance import.

2. In Scala 3.1, an old-style implicits accessed implicitly through a normal import
will give a deprecation warning.

3. In some version after 3.1, an old-style implicits accessed implicitly through a normal import
will give a compiler error.

These rules mean that library users can use `import evidence` to access old-style implicits in Scala 3.0,
These rules mean that library users can use `import instance` to access old-style implicits in Scala 3.0,
and will be gently nudged and then forced to do so in later versions. Libraries can then switch to
evidence definitions once their user base has migrated.
instance definitions once their user base has migrated.
6 changes: 3 additions & 3 deletions docs/docs/reference/contextual-instance/instance-defs.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ instance [T] given (ord: Ord[T]) of Ord[List[T]] { ... }
```
If a name is not given, the compiler will synthesize one from the type(s) in the `for` clause.

## instance Aliases
## Alias Instances

An instance alias defines an implicit instance that is equal to some expression. E.g., assuming a global method `currentThreadPool` returning a value with a member `context`, one could define:
An alias instance defines an implicit instance that is equal to some expression. E.g., assuming a global method `currentThreadPool` returning a value with a member `context`, one could define:
```scala
instance ctx of ExecutionContext = currentThreadPool().context
```
Expand All @@ -59,7 +59,7 @@ Alias instances may be anonymous, e.g.
```scala
instance of Position = enclosingTree.position
```
An instance alias can have type and context parameters just like any other instance definition, but it can only implement a single type.
An alias instance can have type and context parameters just like any other instance definition, but it can only implement a single type.

## Syntax

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Implicit classes in Scala 2 are often used to define extension methods, which ar

### Implicit Values

Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an instance alias. E.g., Scala 2's
Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias instance. E.g., Scala 2's
```scala
lazy implicit val pos: Position = tree.sourcePos
```
Expand All @@ -151,7 +151,7 @@ can be expressed in Dotty as

### Abstract Implicits

An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an instance alias. E.g., Scala 2's
An abstract implicit `val` or `def` in Scala 2 can be expressed in Dotty using a regular abstract definition and an alias instance. E.g., Scala 2's
```scala
implicit def symDeco: SymDeco
```
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/contextual/relationship-implicits.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Implicit classes in Scala 2 are often used to define extension methods, which ar

### Implicit Values

Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an instance alias. E.g., Scala 2's
Implicit `val` definitions in Scala 2 can be expressed in Dotty using a regular `val` definition and an alias instance. E.g., Scala 2's
```scala
lazy implicit val pos: Position = tree.sourcePos
```
Expand Down