From badbc52d82b1f97861bf30457014fc9ea19dfcb2 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 11 Feb 2022 12:18:33 -0800 Subject: [PATCH] spec: highlight missing prose for easier review, fixed a few sections The (temporary) highlights will make it easier to review the spec in formatted form as opposed to html text. Added a missing rule about the use of adjusted core types for constraint type inference. Adjusted rule for invalid embedding of interface types. Change-Id: Ie573068d2307b66c937e803c486724175415b9c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/385535 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 57 ++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index b63aba5b16..bf8b5ed5bf 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -11,6 +11,11 @@ For the pre-Go1.18 specification without generics support see The Go Programming Language Specification.

+ +

+[For reviewers: Sections where we know of missing prose are marked like this. The markers will be removed before the release.] +

+

Introduction

@@ -1498,15 +1503,9 @@ type Floatish struct { } - -

-An interface type T may not embed itself -or any interface type that embeds T, recursively. +An interface type T may not embed any type element +that is, contains, or embeds T, recursively.

@@ -1522,6 +1521,11 @@ type Bad1 interface {
 type Bad2 interface {
 	Bad1
 }
+
+// illegal: Bad3 cannot embed a union containing Bad3
+type Bad3 interface {
+	~int | ~string | Bad3
+}
 

Implementing an interface

@@ -1803,6 +1807,10 @@ interface{ <-chan int | chan<- int } // directional channels have dif

Specific types

+

+[The definition of specific types is not quite correct yet.] +

+

An interface specification that contains type elements defines a (possibly empty) set of specific types. @@ -3346,7 +3354,9 @@ f.p[i].x()

Selectors

- +

+[This section is missing rules for x.f where x's type is a type parameter and f is a field.] +

For a primary expression x @@ -4557,14 +4567,6 @@ ensures that type inference does not depend on the order of the untyped argument

Constraint type inference

- -

Constraint type inference infers type arguments by considering type constraints. If a type parameter P has a constraint with a @@ -4604,6 +4606,17 @@ Thus, in this example, constraint type inference can infer the second type argum first one.

+

+Using the core type of a constraint may lose some information: In the (unlikely) case that +the constraint's type set contains a single defined type +N, the corresponding core type is N's underlying type rather than +N itself. In this case, constraint type inference may succeed but instantiation +will fail because the inferred type is not in the type set of the constraint. +Thus, constraint type inference uses the adjusted core type of +a constraint: if the type set contains a single type, use that type; otherwise use the +constraint's core type. +

+

Generally, constraint type inference proceeds in two phases: Starting with a given substitution map M @@ -4611,7 +4624,7 @@ substitution map M

  1. -For all type parameters with a core type, unify the type parameter with the core +For all type parameters with an adjusted core type, unify the type parameter with that type. If any unification fails, constraint type inference fails.
  2. @@ -5369,7 +5382,7 @@ in any of these cases:

    -Additionally, if T or x's type V are type +Additionally, if T or x's type V are type parameters with specific types, x can also be converted to type T if one of the following conditions applies:

    @@ -7317,7 +7330,9 @@ does not exist, delete is a no-op.

    Manipulating complex numbers

    - +

    +[We don't support generic arguments for these built-ins for Go 1.18.] +

    Three functions assemble and disassemble complex numbers.