From e43d09f77ec5a120ffda2ada7ed696f67307c5f4 Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Fri, 12 Feb 2021 01:22:28 -0800 Subject: [PATCH 1/3] Fix links in docs --- docs/docs/internals/syntax.md | 2 +- .../other-new-features/transparent-traits.md | 28 +++++++++---------- docs/docs/reference/syntax.md | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/docs/internals/syntax.md b/docs/docs/internals/syntax.md index bebd6228cb18..6bdde243c630 100644 --- a/docs/docs/internals/syntax.md +++ b/docs/docs/internals/syntax.md @@ -88,7 +88,7 @@ semi ::= ‘;’ | nl {nl} ## Optional Braces -The lexical analyzer also inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](../reference/other-new-features-indentation.html) +The lexical analyzer also inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](../reference/other-new-features/indentation.md) In the context-free productions below we use the notation `<<< ts >>>` to indicate a token sequence `ts` that is either enclosed in a pair of braces `{ ts }` or that constitutes an indented region `indent ts outdent`. Analogously, the diff --git a/docs/docs/reference/other-new-features/transparent-traits.md b/docs/docs/reference/other-new-features/transparent-traits.md index 0cb8f9d6e2ac..49ac906e0ef1 100644 --- a/docs/docs/reference/other-new-features/transparent-traits.md +++ b/docs/docs/reference/other-new-features/transparent-traits.md @@ -19,10 +19,10 @@ val x = Set(if condition then Val else Var) Here, the inferred type of `x` is `Set[Kind & Product & Serializable]` whereas one would have hoped it to be `Set[Kind]`. The reasoning for this particular type to be inferred is as follows: - - The type of the conditional above is the [union type](new-types/union-types.md) `Val | Var`. - - A union type is widened in type inference to the least supertype that is - not a union type. In the example, this type is `Kind & Product & Serializable` since all three traits are traits of both `Val` and `Var`. - So that type becomes the inferred element type of the set. +- The type of the conditional above is the [union type](../new-types/union-types.md) `Val | Var`. +- A union type is widened in type inference to the least supertype that is not a union type. + In the example, this type is `Kind & Product & Serializable` since all three traits are traits of both `Val` and `Var`. + So that type becomes the inferred element type of the set. Scala 3 allows one to mark a mixin trait as `transparent`, which means that it can be suppressed in type inference. Here's an example that follows the lines of the code above, but now with a new transparent trait `S` instead of `Product`: @@ -46,9 +46,8 @@ by adding a [`@transparentTrait` annotation](https://dotty.epfl.ch/api/scala/ann Typically, transparent traits are traits that influence the implementation of inheriting classes and traits that are not usually used as types by themselves. Two examples from the standard collection library are: - - `IterableOps`, which provides method implementations for an `Iterable` - - `StrictOptimizedSeqOps`, which optimises some of these implementations for - sequences with efficient indexing. +- `IterableOps`, which provides method implementations for an `Iterable`. +- `StrictOptimizedSeqOps`, which optimises some of these implementations for sequences with efficient indexing. Generally, any trait that is extended recursively is a good candidate to be declared transparent. @@ -59,13 +58,12 @@ Transparent traits can be given as explicit types as usual. But they are often e The precise rules are as follows: - - When inferring a type of a type variable, or the type of a val, or the return type of a def, - - where that type is not higher-kinded, - - and where `B` is its known upper bound or `Any` if none exists: - - If the type inferred so far is of the form `T1 & ... & Tn` where - `n >= 1`, replace the maximal number of transparent `Ti`s by `Any`, while ensuring that - the resulting type is still a subtype of the bound `B`. - - However, do not perform this widening if all transparent traits `Ti` can get replaced in that way. +- When inferring a type of a type variable, or the type of a val, or the return type of a def, +- where that type is not higher-kinded, +- and where `B` is its known upper bound or `Any` if none exists: +- If the type inferred so far is of the form `T1 & ... & Tn` where + `n >= 1`, replace the maximal number of transparent `Ti`s by `Any`, while ensuring that + the resulting type is still a subtype of the bound `B`. +- However, do not perform this widening if all transparent traits `Ti` can get replaced in that way. The last clause ensures that a single transparent trait instance such as `Product` is not widened to `Any`. Transparent trait instances are only dropped when they appear in conjunction with some other type. - diff --git a/docs/docs/reference/syntax.md b/docs/docs/reference/syntax.md index 508c82e39224..354ea4c262a2 100644 --- a/docs/docs/reference/syntax.md +++ b/docs/docs/reference/syntax.md @@ -87,7 +87,7 @@ semi ::= ‘;’ | nl {nl} ## Optional Braces -The lexical analyzer also inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](../other-new-features/indentation.md). +The lexical analyzer also inserts `indent` and `outdent` tokens that represent regions of indented code [at certain points](./other-new-features/indentation.md). In the context-free productions below we use the notation `<<< ts >>>` to indicate a token sequence `ts` that is either enclosed in a pair of braces `{ ts }` or that constitutes an indented region `indent ts outdent`. Analogously, the From 591edbed534cfb97700b036d6a6316270cbc941c Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Fri, 12 Feb 2021 01:26:50 -0800 Subject: [PATCH 2/3] Fix a code example syntax --- .../reference/new-types/dependent-function-types-spec.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/reference/new-types/dependent-function-types-spec.md b/docs/docs/reference/new-types/dependent-function-types-spec.md index 5f9bf9cf5f6a..e1dd839a9162 100644 --- a/docs/docs/reference/new-types/dependent-function-types-spec.md +++ b/docs/docs/reference/new-types/dependent-function-types-spec.md @@ -7,7 +7,7 @@ Initial implementation in [PR #3464](https://github.com/lampepfl/dotty/pull/3464 ## Syntax -``` +```ebnf FunArgTypes ::= InfixType | ‘(’ [ FunArgType {',' FunArgType } ] ‘)’ | ‘(’ TypedFunParam {',' TypedFunParam } ‘)’ @@ -15,7 +15,7 @@ TypedFunParam ::= id ‘:’ Type ``` Dependent function types associate to the right, e.g. -`(s: S) ⇒ (t: T) ⇒ U` is the same as `(s: S) ⇒ ((t: T) ⇒ U)`. +`(s: S) => (t: T) => U` is the same as `(s: S) => ((t: T) => U)`. ## Implementation @@ -25,7 +25,7 @@ refinement types of `scala.FunctionN`. A dependent function type `(x1: K1, ..., xN: KN) => R` of arity `N` translates to: ```scala -FunctionN[K1, ..., Kn, R'] with +FunctionN[K1, ..., Kn, R']: def apply(x1: K1, ..., xN: KN): R ``` From 98164f800f38482c4c197b5d6b534c7eb8157190 Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Fri, 12 Feb 2021 01:38:32 -0800 Subject: [PATCH 3/3] Remove a trailing : from a heading --- docs/docs/reference/metaprogramming/macros-spec.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/docs/reference/metaprogramming/macros-spec.md b/docs/docs/reference/metaprogramming/macros-spec.md index a90b2a7fbfb7..e03bb2fc2d20 100644 --- a/docs/docs/reference/metaprogramming/macros-spec.md +++ b/docs/docs/reference/metaprogramming/macros-spec.md @@ -90,7 +90,7 @@ Separator * ::= ' The two environment combinators are both associative with left and right identity `()`. -### Operational semantics: +### Operational semantics We define a small step reduction relation `-->` with the following rules: ``` @@ -111,6 +111,7 @@ splice evaluation context `e_s` are defined syntactically as follows: Eval context e ::= [ ] | e t | v e | 'e_s[${e}] Splice context e_s ::= [ ] | (x: T) => e_s | e_s t | u e_s ``` + ### Typing rules Typing judgments are of the form `Es |- t: T`. There are two