Skip to content

Commit 58c1060

Browse files
josh11bchandlerc
andauthored
Updates to design docs to reflect accepted proposals (#3254)
Includes proposals: - #990 - #2188 - #2138 - #2200 - #2360 - #2760 - #2964 - #3162 Also tries to use more precise language when talking about: - implementations, to avoid confusing `impl` declaration and definitions with the `impls` operator used in `where` clauses, an issue brought up in #2495 and #2483; - "binding patterns", like `x: i32`, and "bindings" like `x`. --------- Co-authored-by: Chandler Carruth <[email protected]>
1 parent caecdc7 commit 58c1060

20 files changed

+153
-138
lines changed

docs/design/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,14 +1604,13 @@ fn Foo() -> f32 {
16041604
}
16051605
```
16061606

1607-
> **Note:** This is provisional, no design for `match` statements has been
1608-
> through the proposal process yet.
1609-
16101607
> References:
16111608
>
16121609
> - [Pattern matching](pattern_matching.md)
16131610
> - Question-for-leads issue
16141611
> [#1283: how should pattern matching and implicit conversion interact?](https://github.com/carbon-language/carbon-lang/issues/1283)
1612+
> - Proposal
1613+
> [#2188: Pattern matching syntax and semantics](https://github.com/carbon-language/carbon-lang/pull/2188)
16151614
16161615
## User-defined types
16171616

@@ -3562,9 +3561,6 @@ imported, so a wrapper may be added without requiring changes to importers?
35623561

35633562
### Templates
35643563

3565-
> **Note:** This is provisional, no design for this has been through the
3566-
> proposal process yet.
3567-
35683564
Carbon supports both
35693565
[checked and template generics](#checked-and-template-parameters). This provides
35703566
a migration path for C++ template code:
@@ -3591,6 +3587,11 @@ toolchain. However, even when using Carbon's generated C++ headers for interop,
35913587
we will include the ability where possible to use a Carbon generic from C++ as
35923588
if it were a C++ template.
35933589

3590+
> References:
3591+
>
3592+
> - Proposal
3593+
> [#2200: Template generics](https://github.com/carbon-language/carbon-lang/pull/2200)
3594+
35943595
### Standard types
35953596

35963597
> **Note:** This is provisional, no design for this has been through the

docs/design/classes.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ implemented in descendants.
311311
While it is typical for this case to be associated with single-level inheritance
312312
hierarchies, there are some cases where there is an interface at the root of a
313313
type hierarchy and polymorphic types as interior branches of the tree. The case
314-
of generic interfaces extending or requiring other interface would also be
315-
modeled by deeper inheritance hierarchies.
314+
of interfaces extending or requiring other interface would also be modeled by
315+
deeper inheritance hierarchies.
316316

317317
An interface as base class needs to either have a virtual destructor or forbid
318318
deallocation.
@@ -325,7 +325,7 @@ that support dynamic dispatch are called _object-safe_, following
325325

326326
- They don't have a `Self` in the signature of a method in a contravariant
327327
position like a parameter.
328-
- They don't have free associated types or other associated items used in a
328+
- They don't have free associated facets or other associated items used in a
329329
method signature.
330330

331331
The restrictions on object-safe interfaces match the restrictions on base class
@@ -910,7 +910,7 @@ which must be an
910910
then match pattern '`self:` _type_' against it".
911911

912912
If the method declaration also includes
913-
[deduced generic parameters](/docs/design/generics/overview.md#deduced-parameters),
913+
[deduced compile-time parameters](/docs/design/generics/overview.md#deduced-parameters),
914914
the `self` parameter must be in the same list in square brackets `[`...`]`. The
915915
`self` parameter may appear in any position in that list, as long as it appears
916916
after any names needed to describe its type.
@@ -1595,7 +1595,7 @@ class MyDerivedClass {
15951595

15961596
The properties of a type, whether type is abstract, base, or final, and whether
15971597
the destructor is virtual or non-virtual, determines which
1598-
[type-of-types](/docs/design/generics/terminology.md#facet-type) it satisfies.
1598+
[facet types](/docs/design/generics/terminology.md#facet-type) it satisfies.
15991599

16001600
- Non-abstract classes are `Concrete`. This means you can create local and
16011601
member variables of this type. `Concrete` types have destructors that are
@@ -1623,9 +1623,9 @@ conform to the decision on
16231623
| final | any | yes | yes | yes |
16241624

16251625
The compiler automatically determines which of these
1626-
[type-of-types](/docs/design/generics/terminology.md#facet-type) a given type
1626+
[facet types](/docs/design/generics/terminology.md#facet-type) a given type
16271627
satisfies. It is illegal to directly implement `Concrete`, `Deletable`, or
1628-
`Destructible` directly. For more about these constraints, see
1628+
`Destructible`. For more about these constraints, see
16291629
["destructor constraints" in the detailed generics design](/docs/design/generics/details.md#destructor-constraints).
16301630

16311631
A pointer to `Deletable` types may be passed to the `Delete` method of the
@@ -1644,8 +1644,9 @@ interface Allocator {
16441644
}
16451645
```
16461646

1647-
To pass a pointer to a base class without a virtual destructor to a generic
1648-
function expecting a `Deletable` type, use the `UnsafeAllowDelete`
1647+
To pass a pointer to a base class without a virtual destructor to a
1648+
checked-generic function expecting a `Deletable` type, use the
1649+
`UnsafeAllowDelete`
16491650
[type adapter](/docs/design/generics/details.md#adapting-types).
16501651

16511652
```
@@ -1670,7 +1671,7 @@ and not implemented in the current class.
16701671

16711672
Types satisfy the
16721673
[`TrivialDestructor`](/docs/design/generics/details.md#destructor-constraints)
1673-
type-of-type if:
1674+
facet type if:
16741675

16751676
- the class declaration does not define a destructor or the class defines the
16761677
destructor with an empty body `{ }`,
@@ -1949,11 +1950,11 @@ We want four things so that Carbon's object-safe interfaces may interoperate
19491950
with C++ abstract base classes without data members, matching the
19501951
[interface as base class use case](#interface-as-base-class):
19511952

1952-
- Ability to convert an object-safe interface (a type-of-type) into an
1953+
- Ability to convert an object-safe interface (a facet type) into an
19531954
C++-compatible base class (a base type), maybe using
19541955
`AsBaseClass(MyInterface)`.
19551956
- Ability to convert a C++ base class without data members (a base type) into
1956-
an object-safe interface (a type-of-type), maybe using `AsInterface(MyIBC)`.
1957+
an object-safe interface (a facet type), maybe using `AsInterface(MyIBC)`.
19571958
- Ability to convert a (thin) pointer to an abstract base class to a `DynPtr`
19581959
of the corresponding interface.
19591960
- Ability to convert `DynPtr(MyInterface)` values to a proxy type that extends
@@ -2160,7 +2161,7 @@ implementations for [data classes](#data-classes) more generally. These
21602161
implementations will typically subject to the criteria that all the data fields
21612162
of the type must implement the interface. An example use case would be to say
21622163
that a data class is serializable if all of its fields were. For this we will
2163-
need a type-of-type for capturing that criteria, maybe something like
2164+
need a facet type for capturing that criteria, maybe something like
21642165
`DataFieldsImplement(MyInterface)`. The templated implementation will need some
21652166
way of iterating through the fields so it can perform operations fieldwise. This
21662167
feature should also implement the interfaces for any tuples whose fields satisfy
@@ -2239,7 +2240,7 @@ the type of `U.x`."
22392240
- [Allow functions to act as destructors](/proposals/p1154.md#allow-functions-to-act-as-destructors)
22402241
- [Allow private destructors](/proposals/p1154.md#allow-private-destructors)
22412242
- [Allow multiple conditional destructors](/proposals/p1154.md#allow-multiple-conditional-destructors)
2242-
- [Type-of-type naming](/proposals/p1154.md#type-of-type-naming)
2243+
- [Facet type naming](/proposals/p1154.md#type-of-type-naming)
22432244
- [Other approaches to extensible classes without vtables](/proposals/p1154.md#other-approaches-to-extensible-classes-without-vtables)
22442245
22452246
- [#2107: Clarify rules around `Self` and `.Self`](https://github.com/carbon-language/carbon-lang/pull/2107)

docs/design/expressions/arithmetic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ following family of interfaces:
193193
```
194194
// Unary `-`.
195195
interface Negate {
196-
let Result:! type = Self;
196+
default let Result:! type = Self;
197197
fn Op[self: Self]() -> Result;
198198
}
199199
```
200200

201201
```
202202
// Binary `+`.
203203
interface AddWith(U:! type) {
204-
let Result:! type = Self;
204+
default let Result:! type = Self;
205205
fn Op[self: Self](other: U) -> Result;
206206
}
207207
constraint Add {
@@ -212,7 +212,7 @@ constraint Add {
212212
```
213213
// Binary `-`.
214214
interface SubWith(U:! type) {
215-
let Result:! type = Self;
215+
default let Result:! type = Self;
216216
fn Op[self: Self](other: U) -> Result;
217217
}
218218
constraint Sub {
@@ -223,7 +223,7 @@ constraint Sub {
223223
```
224224
// Binary `*`.
225225
interface MulWith(U:! type) {
226-
let Result:! type = Self;
226+
default let Result:! type = Self;
227227
fn Op[self: Self](other: U) -> Result;
228228
}
229229
constraint Mul {
@@ -234,7 +234,7 @@ constraint Mul {
234234
```
235235
// Binary `/`.
236236
interface DivWith(U:! type) {
237-
let Result:! type = Self;
237+
default let Result:! type = Self;
238238
fn Op[self: Self](other: U) -> Result;
239239
}
240240
constraint Div {
@@ -245,7 +245,7 @@ constraint Div {
245245
```
246246
// Binary `%`.
247247
interface ModWith(U:! type) {
248-
let Result:! type = Self;
248+
default let Result:! type = Self;
249249
fn Op[self: Self](other: U) -> Result;
250250
}
251251
constraint Mod {

docs/design/expressions/bitwise.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ implementing the following family of interfaces:
197197
```
198198
// Unary `^`.
199199
interface BitComplement {
200-
let Result:! type = Self;
200+
default let Result:! type = Self;
201201
fn Op[self: Self]() -> Result;
202202
}
203203
```
204204

205205
```
206206
// Binary `&`.
207207
interface BitAndWith(U:! type) {
208-
let Result:! type = Self;
208+
default let Result:! type = Self;
209209
fn Op[self: Self](other: U) -> Result;
210210
}
211211
constraint BitAnd {
@@ -216,7 +216,7 @@ constraint BitAnd {
216216
```
217217
// Binary `|`.
218218
interface BitOrWith(U:! type) {
219-
let Result:! type = Self;
219+
default let Result:! type = Self;
220220
fn Op[self: Self](other: U) -> Result;
221221
}
222222
constraint BitOr {
@@ -227,7 +227,7 @@ constraint BitOr {
227227
```
228228
// Binary `^`.
229229
interface BitXorWith(U:! type) {
230-
let Result:! type = Self;
230+
default let Result:! type = Self;
231231
fn Op[self: Self](other: U) -> Result;
232232
}
233233
constraint BitXor {
@@ -238,7 +238,7 @@ constraint BitXor {
238238
```
239239
// Binary `<<`.
240240
interface LeftShiftWith(U:! type) {
241-
let Result:! type = Self;
241+
default let Result:! type = Self;
242242
fn Op[self: Self](other: U) -> Result;
243243
}
244244
constraint LeftShift {
@@ -249,7 +249,7 @@ constraint LeftShift {
249249
```
250250
// Binary `>>`.
251251
interface RightShiftWith(U:! type) {
252-
let Result:! type = Self;
252+
default let Result:! type = Self;
253253
fn Op[self: Self](other: U) -> Result;
254254
}
255255
constraint RightShift {

docs/design/expressions/comparison_operators.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ User-defined types can extend the behavior of the comparison operators by
241241
implementing interfaces. In this section, various properties are specified that
242242
such implementations "should" satisfy. These properties are not enforced in
243243
general, but the standard library might detect violations of some of them in
244-
some circumstances. These properties may be assumed by generic code, resulting
245-
in unexpected behavior if they are violated.
244+
some circumstances. These properties may be assumed by checked-generic code,
245+
resulting in unexpected behavior if they are violated.
246246

247247
#### Equality
248248

@@ -460,7 +460,7 @@ than or equivalent to themselves.
460460

461461
**TODO:** The standard library should provide a way to specify that an ordering
462462
is a weak, partial, or total ordering, and a way to request such an ordering in
463-
a generic.
463+
a checked generic.
464464

465465
#### Compatibility of equality and ordering
466466

docs/design/expressions/if.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ _Note:_ This rule is intended to be considered more specialized than the other
175175
rules in this document.
176176

177177
Because this `impl` is declared `final`, `T.(CommonType(T)).Result` is always
178-
assumed to be `T`, even in contexts where `T` involves a generic parameter and
179-
so the result would normally be an unknown type whose type-of-type is `type`.
178+
assumed to be `T`, even in contexts where `T` involves a symbolic binding and so
179+
the result would normally be an unknown type whose facet type is `type`.
180180

181181
```
182182
fn F[T:! Hashable](c: bool, x: T, y: T) -> HashCode {

docs/design/expressions/indexing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pointer, and do not automatically chain with customized dereference interfaces.
5151

5252
**Open question:** It's not clear that the lack of chaining is necessary, and it
5353
might be more expressive for the pointer type returned by the `Addr` methods to
54-
be an associated type with a default to allow types to produce custom
54+
be an associated facet with a default to allow types to produce custom
5555
pointer-like types on their indexing boundary and have them still be
5656
automatically dereferenced.
5757

docs/design/functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ the `a` and `b` parameters of `Add`.
151151
Other designs build upon basic function syntax to add advanced features:
152152

153153
- [Generic functions](generics/overview.md#generic-functions) adds support for
154-
deduced parameters and generic type parameters.
154+
deduced parameters and compile-time parameters.
155155
- [Class member functions](classes.md#member-functions) adds support for
156156
methods and class functions.
157157

158158
## Alternatives considered
159159

160160
- [Function keyword](/proposals/p0438.md#function-keyword)
161-
- [Only allow `auto` return types if parameters are generic](/proposals/p0826.md#only-allow-auto-return-types-if-parameters-are-generic)
161+
- [Only allow `auto` return types if parameters are compile-time](/proposals/p0826.md#only-allow-auto-return-types-if-parameters-are-generic)
162162
- [Provide alternate function syntax for concise return type inference](/proposals/p0826.md#provide-alternate-function-syntax-for-concise-return-type-inference)
163163
- [Allow separate declaration and definition](/proposals/p0826.md#allow-separate-declaration-and-definition)
164164

docs/design/generics/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ feature of Carbon:
1111

1212
- [Overview](overview.md) - A high-level description of the generics design,
1313
with pointers to other design documents that dive deeper into individual
14-
topics.
14+
topics
1515
- [Goals](goals.md) - The motivation and principles guiding the design
16-
direction.
16+
direction
1717
- [Terminology](terminology.md) - A glossary establishing common terminology
18-
for describing the design.
19-
- [Detailed design](details.md) - In depth description of how generic type
20-
parameters work.
21-
- ~~Rejected alternatives~~ - not implemented yet
18+
for describing the design
19+
- [Detailed design](details.md) - In-depth description
20+
- [Appendix: Witness tables](appendix-witness.md) - Describes an
21+
implementation strategy for checked generics, and Carbon's rationale for
22+
only using it for dynamic dispatch.
23+
- [Appendix: Coherence](appendix-coherence.md) - Describes the rationale
24+
for Carbon's choice to have coherent generics, and the alternatives.

docs/design/generics/appendix-witness.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ class Vector {
213213
}
214214
```
215215

216-
The [impl of `Vector` for `Point_Inline`](details.md#inline-impl) would be a
217-
value of this type:
216+
The [`impl` definition of `Vector` for `Point_Inline`](details.md#inline-impl)
217+
would be a value of this type:
218218

219219
```
220220
var VectorForPoint_Inline: Vector = {

0 commit comments

Comments
 (0)