Skip to content

Commit

Permalink
Merge branch 'carbon-language:trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsdragonis authored Sep 24, 2023
2 parents 5a1ba0b + 58c1060 commit 50ece82
Show file tree
Hide file tree
Showing 133 changed files with 2,488 additions and 2,104 deletions.
45 changes: 20 additions & 25 deletions docs/design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1604,14 +1604,13 @@ fn Foo() -> f32 {
}
```

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

Expand Down Expand Up @@ -2569,8 +2568,7 @@ class ContactInfo {
>
> - [Aliases](aliases.md)
> - ["Aliasing" in "Code and name organization"](code_and_name_organization/README.md#aliasing)
> - <!-- [`alias` a name from an interface impl](generics/details.md#avoiding-name-collisions) -->
> [`alias` a name from an interface impl](generics/details.md#external-impl)
> - [`alias` a name from an interface impl](generics/details.md#avoiding-name-collisions)
> - [`alias` a name in a named constraint](generics/details.md#named-constraints)
> - Proposal
> [#107: Code and name organization](https://github.com/carbon-language/carbon-lang/pull/107)
Expand Down Expand Up @@ -2803,8 +2801,7 @@ In addition to function requirements, interfaces can contain:
- [requirements that other interfaces be implemented](generics/details.md#interface-requiring-other-interfaces)
or
[interfaces that this interface extends](generics/details.md#interface-extension)
- <!-- [associated facets](generics/details.md#associated-facets) -->
[associated facets](generics/details.md#associated-types) and other
- [associated facets](generics/details.md#associated-facets) and other
[associated constants](generics/details.md#associated-constants)
- [interface defaults](generics/details.md#interface-defaults)
- [`final` interface members](generics/details.md#final-members)
Expand Down Expand Up @@ -2857,16 +2854,14 @@ In this case, `Print` is not a direct member of `Circle`, but:
}
```
<!-- [`extend`](generics/details.md#extend-impl) keyword... -->
To include the members of the interface as direct members of the type, use the
`extend` keyword, as in `extend impl as Printable`. This is only permitted on
`impl` declarations in the body of a class definition.
[`extend`](generics/details.md#extend-impl) keyword, as in
`extend impl as Printable`. This is only permitted on `impl` declarations in the
body of a class definition.
Without `extend`, implementations don't have to be in the same library as the
type definition, subject to the orphan rule
([1](generics/details.md#impl-lookup), [2](generics/details.md#orphan-rule)) for
[coherence](generics/terminology.md#coherence).
type definition, subject to the [orphan rule](generics/details.md#orphan-rule)
for [coherence](generics/terminology.md#coherence).
Interfaces and implementations may be
[forward declared](generics/details.md#forward-declarations-and-cyclic-references)
Expand Down Expand Up @@ -2928,8 +2923,7 @@ fn DrawTies[T:! Renderable & GameResult](x: T) {

> References:
>
> - <!-- [Combining interfaces by anding facet types](generics/details.md#combining-interfaces-by-anding-facet-types) -->
> [Combining interfaces by anding type-of-types](generics/details.md#combining-interfaces-by-anding-type-of-types)
> - [Combining interfaces by anding facet types](generics/details.md#combining-interfaces-by-anding-facet-types)
> - Question-for-leads issue
> [#531: Combine interfaces with `+` or `&`](https://github.com/carbon-language/carbon-lang/issues/531)
> - Proposal
Expand Down Expand Up @@ -3559,18 +3553,14 @@ function.

Carbon interfaces with no C++ equivalent, such as
[`CommonTypeWith(U)`](#common-type), may be implemented for C++ types
out-of-line in Carbon code. To satisfy the orphan rule
([1](generics/details.md#impl-lookup), [2](generics/details.md#orphan-rule)),
each C++ library will have a corresponding Carbon wrapper library that must be
imported instead of the C++ library if the Carbon wrapper exists. **TODO:**
Perhaps it will automatically be imported, so a wrapper may be added without
requiring changes to importers?
out-of-line in Carbon code. To satisfy the
[orphan rule](generics/details.md#orphan-rule), each C++ library will have a
corresponding Carbon wrapper library that must be imported instead of the C++
library if the Carbon wrapper exists. **TODO:** Perhaps it will automatically be
imported, so a wrapper may be added without requiring changes to importers?

### Templates

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

> References:
>
> - Proposal
> [#2200: Template generics](https://github.com/carbon-language/carbon-lang/pull/2200)
### Standard types

> **Note:** This is provisional, no design for this has been through the
Expand Down
37 changes: 19 additions & 18 deletions docs/design/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ implemented in descendants.
While it is typical for this case to be associated with single-level inheritance
hierarchies, there are some cases where there is an interface at the root of a
type hierarchy and polymorphic types as interior branches of the tree. The case
of generic interfaces extending or requiring other interface would also be
modeled by deeper inheritance hierarchies.
of interfaces extending or requiring other interface would also be modeled by
deeper inheritance hierarchies.

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

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

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

If the method declaration also includes
[deduced generic parameters](/docs/design/generics/overview.md#deduced-parameters),
[deduced compile-time parameters](/docs/design/generics/overview.md#deduced-parameters),
the `self` parameter must be in the same list in square brackets `[`...`]`. The
`self` parameter may appear in any position in that list, as long as it appears
after any names needed to describe its type.
Expand Down Expand Up @@ -1174,11 +1174,11 @@ methods whose implementation may be overridden in a derived class.

Only methods defined in the scope of the class definition may be virtual, not
any defined in
[external interface `impl` declarations](/docs/design/generics/details.md#external-impl).
[out-of-line interface `impl` declarations](/docs/design/generics/details.md#out-of-line-impl).
Interface methods may be implemented using virtual methods when the
[impl is internal](/docs/design/generics/details.md#implementing-interfaces),
and calls to those methods by way of the interface will do virtual dispatch just
like a direct call to the method does.
[impl is inline](/docs/design/generics/details.md#inline-impl), and calls to
those methods by way of the interface will do virtual dispatch just like a
direct call to the method does.

[Class functions](#class-functions) may not be declared virtual.

Expand Down Expand Up @@ -1595,7 +1595,7 @@ class MyDerivedClass {

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

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

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

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

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

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

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

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

- Ability to convert an object-safe interface (a type-of-type) into an
- Ability to convert an object-safe interface (a facet type) into an
C++-compatible base class (a base type), maybe using
`AsBaseClass(MyInterface)`.
- Ability to convert a C++ base class without data members (a base type) into
an object-safe interface (a type-of-type), maybe using `AsInterface(MyIBC)`.
an object-safe interface (a facet type), maybe using `AsInterface(MyIBC)`.
- Ability to convert a (thin) pointer to an abstract base class to a `DynPtr`
of the corresponding interface.
- Ability to convert `DynPtr(MyInterface)` values to a proxy type that extends
Expand Down Expand Up @@ -2160,7 +2161,7 @@ implementations for [data classes](#data-classes) more generally. These
implementations will typically subject to the criteria that all the data fields
of the type must implement the interface. An example use case would be to say
that a data class is serializable if all of its fields were. For this we will
need a type-of-type for capturing that criteria, maybe something like
need a facet type for capturing that criteria, maybe something like
`DataFieldsImplement(MyInterface)`. The templated implementation will need some
way of iterating through the fields so it can perform operations fieldwise. This
feature should also implement the interfaces for any tuples whose fields satisfy
Expand Down Expand Up @@ -2239,7 +2240,7 @@ the type of `U.x`."
- [Allow functions to act as destructors](/proposals/p1154.md#allow-functions-to-act-as-destructors)
- [Allow private destructors](/proposals/p1154.md#allow-private-destructors)
- [Allow multiple conditional destructors](/proposals/p1154.md#allow-multiple-conditional-destructors)
- [Type-of-type naming](/proposals/p1154.md#type-of-type-naming)
- [Facet type naming](/proposals/p1154.md#type-of-type-naming)
- [Other approaches to extensible classes without vtables](/proposals/p1154.md#other-approaches-to-extensible-classes-without-vtables)
- [#2107: Clarify rules around `Self` and `.Self`](https://github.com/carbon-language/carbon-lang/pull/2107)
Expand Down
12 changes: 6 additions & 6 deletions docs/design/expressions/arithmetic.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ following family of interfaces:
```
// Unary `-`.
interface Negate {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self]() -> Result;
}
```

```
// Binary `+`.
interface AddWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint Add {
Expand All @@ -212,7 +212,7 @@ constraint Add {
```
// Binary `-`.
interface SubWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint Sub {
Expand All @@ -223,7 +223,7 @@ constraint Sub {
```
// Binary `*`.
interface MulWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint Mul {
Expand All @@ -234,7 +234,7 @@ constraint Mul {
```
// Binary `/`.
interface DivWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint Div {
Expand All @@ -245,7 +245,7 @@ constraint Div {
```
// Binary `%`.
interface ModWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint Mod {
Expand Down
12 changes: 6 additions & 6 deletions docs/design/expressions/bitwise.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ implementing the following family of interfaces:
```
// Unary `^`.
interface BitComplement {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self]() -> Result;
}
```

```
// Binary `&`.
interface BitAndWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint BitAnd {
Expand All @@ -216,7 +216,7 @@ constraint BitAnd {
```
// Binary `|`.
interface BitOrWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint BitOr {
Expand All @@ -227,7 +227,7 @@ constraint BitOr {
```
// Binary `^`.
interface BitXorWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint BitXor {
Expand All @@ -238,7 +238,7 @@ constraint BitXor {
```
// Binary `<<`.
interface LeftShiftWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint LeftShift {
Expand All @@ -249,7 +249,7 @@ constraint LeftShift {
```
// Binary `>>`.
interface RightShiftWith(U:! type) {
let Result:! type = Self;
default let Result:! type = Self;
fn Op[self: Self](other: U) -> Result;
}
constraint RightShift {
Expand Down
6 changes: 3 additions & 3 deletions docs/design/expressions/comparison_operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ User-defined types can extend the behavior of the comparison operators by
implementing interfaces. In this section, various properties are specified that
such implementations "should" satisfy. These properties are not enforced in
general, but the standard library might detect violations of some of them in
some circumstances. These properties may be assumed by generic code, resulting
in unexpected behavior if they are violated.
some circumstances. These properties may be assumed by checked-generic code,
resulting in unexpected behavior if they are violated.

#### Equality

Expand Down Expand Up @@ -460,7 +460,7 @@ than or equivalent to themselves.

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

#### Compatibility of equality and ordering

Expand Down
4 changes: 2 additions & 2 deletions docs/design/expressions/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ _Note:_ This rule is intended to be considered more specialized than the other
rules in this document.

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

```
fn F[T:! Hashable](c: bool, x: T, y: T) -> HashCode {
Expand Down
10 changes: 5 additions & 5 deletions docs/design/expressions/implicit_conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- [Data types](#data-types)
- [Same type](#same-type)
- [Pointer conversions](#pointer-conversions)
- [Type-of-types](#type-of-types)
- [Facet types](#facet-types)
- [Consistency with `as`](#consistency-with-as)
- [Extensibility](#extensibility)
- [Alternatives considered](#alternatives-considered)
Expand Down Expand Up @@ -182,11 +182,11 @@ var r: Base** = &p;
*r = q;
```

### Type-of-types
### Facet types

A type `T` with [type-of-type](../generics/terminology.md#facet-type) `TT1` can
be implicitly converted to the type-of-type `TT2` if `T`
[satisfies the requirements](../generics/details.md#subtyping-between-type-of-types)
A type `T` with [facet type](../generics/terminology.md#facet-type) `TT1` can be
implicitly converted to the facet type `TT2` if `T`
[satisfies the requirements](../generics/details.md#subtyping-between-facet-types)
of `TT2`.

## Consistency with `as`
Expand Down
2 changes: 1 addition & 1 deletion docs/design/expressions/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pointer, and do not automatically chain with customized dereference interfaces.

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

Expand Down
Loading

0 comments on commit 50ece82

Please sign in to comment.