Skip to content
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

Values, variables, pointers, and references #2006

Merged
merged 100 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
18e79ba
Filling out template with PR 2006
chandlerc Aug 12, 2022
b8fbace
Migrate content over from #821 which can't be updated.
chandlerc Aug 12, 2022
34e5e7a
add codespell fix
chandlerc Aug 12, 2022
7d1f3be
begin reworking abstract
chandlerc Aug 12, 2022
2ac27c4
precommit
chandlerc Aug 12, 2022
3b8bf85
change name
chandlerc Aug 12, 2022
6ee7bbe
improve terminology
chandlerc Aug 13, 2022
649e660
precommit
chandlerc Aug 13, 2022
dbe628e
wip
chandlerc Oct 8, 2022
fbc05e9
add missing file
chandlerc Oct 15, 2022
8a3902d
fixups
chandlerc Oct 15, 2022
62499f9
Merge branch 'trunk' into pointers2
chandlerc Mar 30, 2023
b2460bd
trim down to just the value semantic bits and leave pattern matching …
chandlerc Mar 31, 2023
406df97
expand much of the values docs
chandlerc Mar 31, 2023
ae043e9
toc
chandlerc Mar 31, 2023
4612d7d
more content and skeleton
chandlerc Mar 31, 2023
ac6ab56
toc
chandlerc Mar 31, 2023
baf91f9
add more content and improve formatting
chandlerc Apr 1, 2023
352f606
finish fleshing out new version of docs
chandlerc Apr 1, 2023
06ef0e8
format, toc, and other cleanups
chandlerc Apr 1, 2023
0d606da
Major update to terminology and TOC started.
chandlerc Apr 8, 2023
ff9eeb7
TOC andother tweaks
chandlerc Apr 8, 2023
20e97c6
more toc
chandlerc Apr 8, 2023
883ef56
push more content through
chandlerc Apr 8, 2023
e44b8e8
main overhaul complete
chandlerc Apr 14, 2023
6b24020
toc
chandlerc Apr 14, 2023
4a51cc8
improve initial wording a bit
chandlerc Apr 15, 2023
9507d79
fill in initializing
chandlerc Apr 15, 2023
1eb3d15
fix fenced languages
chandlerc Apr 15, 2023
57307f6
start filling in all the gaps
chandlerc Apr 15, 2023
fd3e65f
many many fixes
chandlerc Apr 15, 2023
d0540dc
toc and links
chandlerc Apr 15, 2023
443f4d6
loooooooonger
chandlerc Apr 15, 2023
c32d958
looooooooooooooooooonger
chandlerc Apr 15, 2023
b082769
tweak the graph more
chandlerc Apr 15, 2023
3229c33
nm
chandlerc Apr 15, 2023
d8d3d29
fix a typo and add a reference
chandlerc Apr 15, 2023
af6c7f6
Merge branch 'trunk' into pointers2
chandlerc Apr 19, 2023
fad8304
Update docs/design/values.md
chandlerc Apr 19, 2023
358b04a
address review comments
chandlerc Apr 19, 2023
8b72b14
Apply suggestions from code review
chandlerc Apr 20, 2023
8f6542f
replicate some context
chandlerc Apr 20, 2023
bd13418
remove an incorrect bit
chandlerc Apr 20, 2023
e58bd26
format
chandlerc Apr 20, 2023
d208544
start building up a useful proposal, including the template
chandlerc Apr 20, 2023
8b49cbd
toc
chandlerc Apr 20, 2023
ef140ca
fix link
chandlerc Apr 20, 2023
3d37ec1
format
chandlerc Apr 20, 2023
7a58838
complete the proposal update
chandlerc Apr 20, 2023
c530308
toc
chandlerc Apr 20, 2023
fc442eb
Apply suggestions from code review
chandlerc Jun 21, 2023
fd3ab3d
improvements from review
chandlerc Jun 22, 2023
e861ae0
start trying a simplified model
chandlerc Jun 23, 2023
1d968d1
get the order right
chandlerc Jun 23, 2023
8a77b18
Apply suggestions from code review
chandlerc Jun 24, 2023
7eb061c
Update docs/design/expressions/README.md
chandlerc Jun 24, 2023
23ea26c
more updates from review
chandlerc Jun 24, 2023
6c1aed0
lots of work on alternatives
chandlerc Jun 24, 2023
3f3df4a
TOC updates, link updates, and more links
chandlerc Jun 24, 2023
67e1206
remove unlinkable headings
chandlerc Jun 24, 2023
c3f87c1
fill in some todos
chandlerc Jun 24, 2023
06f9fb2
clean up a bunch of interactions
chandlerc Jun 26, 2023
60cbf93
lots more fixes
chandlerc Jun 26, 2023
46da744
still more fixes
chandlerc Jun 26, 2023
1991d37
Apply suggestions from code review
chandlerc Jul 10, 2023
bc5aac3
add file that i forgot in previous commits
chandlerc Jul 10, 2023
81e5dec
address a couple of review comments
chandlerc Jul 10, 2023
43e2e35
more updates from review
chandlerc Jul 11, 2023
68dbdc1
add more content
chandlerc Jul 11, 2023
85a8bd5
tidy
chandlerc Jul 11, 2023
ebea40b
fix a link
chandlerc Jul 11, 2023
7f6f9b6
Update proposals/p2006.md
chandlerc Jul 12, 2023
31508f4
fix formmatting
chandlerc Jul 11, 2023
0e32816
fix formmatting
chandlerc Jul 11, 2023
1852b79
undo a formatting hack that seems unnecesasry now
chandlerc Jul 12, 2023
9676357
lots of updates from review
chandlerc Jul 13, 2023
2cabca0
fixes
chandlerc Jul 13, 2023
580ec34
Update docs/design/values.md
chandlerc Jul 13, 2023
153809c
Update docs/design/values.md
chandlerc Jul 13, 2023
a27c60a
Update proposals/p2006.md
chandlerc Jul 13, 2023
18bb868
formatting
chandlerc Jul 13, 2023
1781950
adjust from review
chandlerc Jul 14, 2023
3464499
Merge branch 'trunk' into pointers2
chandlerc Jul 14, 2023
aaedc23
Update proposals/p2006.md
chandlerc Jul 15, 2023
441928d
Merge branch 'trunk' into pointers2
chandlerc Jul 15, 2023
408af96
remove a stray edit
chandlerc Jul 15, 2023
5fb5b4a
remove another stray edit
chandlerc Jul 15, 2023
0dba116
Apply suggestions from code review
chandlerc Aug 4, 2023
3cc6ab6
format
chandlerc Aug 4, 2023
63b4b05
replace "read" with "bind" in another place
chandlerc Aug 4, 2023
e23c819
restructure
chandlerc Aug 4, 2023
8f0340b
toc
chandlerc Aug 4, 2023
ee3c494
updates based on review
chandlerc Aug 4, 2023
2e0e0e0
format
chandlerc Aug 4, 2023
1c5b066
review feedback
chandlerc Aug 5, 2023
4a68fec
toc
chandlerc Aug 5, 2023
da6fe5d
Merge branch 'trunk' into pointers2
chandlerc Aug 5, 2023
d4fbee7
fix link
chandlerc Aug 5, 2023
2e1e8b3
Update docs/design/expressions/type_operators.md
chandlerc Aug 7, 2023
1615171
format
chandlerc Aug 7, 2023
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
208 changes: 134 additions & 74 deletions docs/design/README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/design/control_flow/return.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ fn MaybeDraw(should_draw: bool) -> () {

### `returned var`

[Variables](../variables.md) may be declared with a `returned` statement. Its
syntax is:
[Local variables](../values.md#binding-patterns-and-local-variables-with-let-and-var)
may be declared with a `returned` statement. Its syntax is:

> `returned` _var statement_

Expand Down
103 changes: 70 additions & 33 deletions docs/design/expressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,27 @@ graph BT
unqualifiedName["x"]
click unqualifiedName "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/README.md#unqualified-names"

top((" "))

memberAccess>"x.y<br>
x.(...)"]
x.(...)<br>
x->y<br>
x->(...)"]
click memberAccess "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/member_access.md"

constType["const T"]
click pointer-type "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/type_operators.md"

pointerType>"T*"]
click pointer-type "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/type_operators.md"

%% FIXME: Need to switch unary operators from a left/right associativity to
%% a "repeated" marker, as we only have one direction for associativity and
%% that is wrong in this specific case.
pointer>"*x<br>
&x<br>"]
click pointer "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/pointer.md"

negation["-x"]
click negation "https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/arithmetic.md"

Expand Down Expand Up @@ -124,15 +141,22 @@ graph BT

expressionEnd["x;"]

memberAccess --> parens & braces & unqualifiedName
negation --> memberAccess
complement --> memberAccess
top --> parens & braces & unqualifiedName

constType --> top
pointerType --> constType
as --> pointerType

memberAccess --> top
pointer --> memberAccess
negation --> pointer
complement --> pointer
unary --> negation & complement
%% Use a longer arrow here to put `not` next to `and` and `or`.
not -----> memberAccess
multiplication & modulo & as & bitwise_and & bitwise_or & bitwise_xor & shift --> unary
not -------> memberAccess
as & multiplication & modulo & bitwise_and & bitwise_or & bitwise_xor & shift --> unary
addition --> multiplication
comparison --> modulo & addition & as & bitwise_and & bitwise_or & bitwise_xor & shift
comparison --> as & addition & modulo & bitwise_and & bitwise_or & bitwise_xor & shift
logicalOperand --> comparison & not
and & or --> logicalOperand
logicalExpression --> and & or
Expand Down Expand Up @@ -179,12 +203,14 @@ keyword and is not preceded by a period (`.`).

### Qualified names and member access

A _qualified name_ is a word that appears immediately after a period. Qualified
names appear in the following contexts:
A _qualified name_ is a word that appears immediately after a period or
rightward arrow. Qualified names appear in the following contexts:

- [Designators](/docs/design/classes.md#literals): `.` _word_
- [Simple member access expressions](member_access.md): _expression_ `.`
_word_
- [Simple pointer member access expressions](member_access.md): _expression_
`->` _word_

```
var x: auto = {.hello = 1, .world = 2};
Expand All @@ -194,6 +220,10 @@ var x: auto = {.hello = 1, .world = 2};
x.hello = x.world;
^^^^^ ^^^^^ qualified name
^^^^^^^ ^^^^^^^ member access expression

x.hello = (&x)->world;
^^^^^ qualified name
^^^^^^^^^^^ pointer member access expression
```

Qualified names refer to members of an entity determined by the context in which
Expand Down Expand Up @@ -231,6 +261,7 @@ complex than a single _word_, a compound member access expression can be used,
with parentheses around the member name:

- _expression_ `.` `(` _expression_ `)`
- _expression_ `->` `(` _expression_ `)`

```
interface I { fn F[self: Self](); }
Expand All @@ -241,34 +272,40 @@ impl X as I { fn F[self: Self]() {} }
fn Q(x: X) { x.(I.F)(); }
```

Either simple or compound member access can be part of a _pointer_ member access
expression when an `->` is used instead of a `.`, where _expression_ `->` _..._
is syntactic sugar for `(` `*` _expression_ `)` `.` _..._.

## Operators

Most expressions are modeled as operators:

| Category | Operator | Syntax | Function |
| ---------- | ------------------------------- | --------- | --------------------------------------------------------------------- |
| Arithmetic | [`-`](arithmetic.md) (unary) | `-x` | The negation of `x`. |
| Bitwise | [`^`](bitwise.md) (unary) | `^x` | The bitwise complement of `x`. |
| Arithmetic | [`+`](arithmetic.md) | `x + y` | The sum of `x` and `y`. |
| Arithmetic | [`-`](arithmetic.md) (binary) | `x - y` | The difference of `x` and `y`. |
| Arithmetic | [`*`](arithmetic.md) | `x * y` | The product of `x` and `y`. |
| Arithmetic | [`/`](arithmetic.md) | `x / y` | `x` divided by `y`, or the quotient thereof. |
| Arithmetic | [`%`](arithmetic.md) | `x % y` | `x` modulo `y`. |
| Bitwise | [`&`](bitwise.md) | `x & y` | The bitwise AND of `x` and `y`. |
| Bitwise | [`\|`](bitwise.md) | `x \| y` | The bitwise OR of `x` and `y`. |
| Bitwise | [`^`](bitwise.md) (binary) | `x ^ y` | The bitwise XOR of `x` and `y`. |
| Bitwise | [`<<`](bitwise.md) | `x << y` | `x` bit-shifted left `y` places. |
| Bitwise | [`>>`](bitwise.md) | `x >> y` | `x` bit-shifted right `y` places. |
| Conversion | [`as`](as_expressions.md) | `x as T` | Converts the value `x` to the type `T`. |
| Comparison | [`==`](comparison_operators.md) | `x == y` | Equality: `true` if `x` is equal to `y`. |
| Comparison | [`!=`](comparison_operators.md) | `x != y` | Inequality: `true` if `x` is not equal to `y`. |
| Comparison | [`<`](comparison_operators.md) | `x < y` | Less than: `true` if `x` is less than `y`. |
| Comparison | [`<=`](comparison_operators.md) | `x <= y` | Less than or equal: `true` if `x` is less than or equal to `y`. |
| Comparison | [`>`](comparison_operators.md) | `x > y` | Greater than: `true` if `x` is greater than to `y`. |
| Comparison | [`>=`](comparison_operators.md) | `x >= y` | Greater than or equal: `true` if `x` is greater than or equal to `y`. |
| Logical | [`and`](logical_operators.md) | `x and y` | A short-circuiting logical AND: `true` if both operands are `true`. |
| Logical | [`or`](logical_operators.md) | `x or y` | A short-circuiting logical OR: `true` if either operand is `true`. |
| Logical | [`not`](logical_operators.md) | `not x` | Logical NOT: `true` if the operand is `false`. |
| Category | Operator | Syntax | Function |
| ---------- | ----------------------------------- | --------- | --------------------------------------------------------------------- |
| Pointer | [`*`](pointer_operators.md) (unary) | `*x` | Pointer dereference: the object pointed to by `x`. |
| Pointer | [`&`](pointer_operators.md) (unary) | `&x` | Address-of: a pointer to the object `x`. |
| Arithmetic | [`-`](arithmetic.md) (unary) | `-x` | The negation of `x`. |
| Bitwise | [`^`](bitwise.md) (unary) | `^x` | The bitwise complement of `x`. |
| Arithmetic | [`+`](arithmetic.md) | `x + y` | The sum of `x` and `y`. |
| Arithmetic | [`-`](arithmetic.md) (binary) | `x - y` | The difference of `x` and `y`. |
| Arithmetic | [`*`](arithmetic.md) | `x * y` | The product of `x` and `y`. |
| Arithmetic | [`/`](arithmetic.md) | `x / y` | `x` divided by `y`, or the quotient thereof. |
| Arithmetic | [`%`](arithmetic.md) | `x % y` | `x` modulo `y`. |
| Bitwise | [`&`](bitwise.md) | `x & y` | The bitwise AND of `x` and `y`. |
| Bitwise | [`\|`](bitwise.md) | `x \| y` | The bitwise OR of `x` and `y`. |
| Bitwise | [`^`](bitwise.md) (binary) | `x ^ y` | The bitwise XOR of `x` and `y`. |
| Bitwise | [`<<`](bitwise.md) | `x << y` | `x` bit-shifted left `y` places. |
| Bitwise | [`>>`](bitwise.md) | `x >> y` | `x` bit-shifted right `y` places. |
| Conversion | [`as`](as_expressions.md) | `x as T` | Converts the value `x` to the type `T`. |
| Comparison | [`==`](comparison_operators.md) | `x == y` | Equality: `true` if `x` is equal to `y`. |
| Comparison | [`!=`](comparison_operators.md) | `x != y` | Inequality: `true` if `x` is not equal to `y`. |
| Comparison | [`<`](comparison_operators.md) | `x < y` | Less than: `true` if `x` is less than `y`. |
| Comparison | [`<=`](comparison_operators.md) | `x <= y` | Less than or equal: `true` if `x` is less than or equal to `y`. |
| Comparison | [`>`](comparison_operators.md) | `x > y` | Greater than: `true` if `x` is greater than to `y`. |
| Comparison | [`>=`](comparison_operators.md) | `x >= y` | Greater than or equal: `true` if `x` is greater than or equal to `y`. |
| Logical | [`and`](logical_operators.md) | `x and y` | A short-circuiting logical AND: `true` if both operands are `true`. |
| Logical | [`or`](logical_operators.md) | `x or y` | A short-circuiting logical OR: `true` if either operand is `true`. |
| Logical | [`not`](logical_operators.md) | `not x` | Logical NOT: `true` if the operand is `false`. |

The binary arithmetic and bitwise operators also have
[compound assignment](/docs/design/assignment.md) forms. These are statements
Expand Down
38 changes: 29 additions & 9 deletions docs/design/expressions/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
## Overview

Carbon supports indexing using the conventional `a[i]` subscript syntax. When
`a` is an l-value, the result of subscripting is always an l-value, but when `a`
is an r-value, the result can be an l-value or an r-value, depending on which
`a` is a
[durable reference expression](/docs/design/values.md#durable-reference-expressions),
the result of subscripting is also a durable reference expression, but when `a`
is a [value expression](/docs/design/values.md#value-expressions), the result
can be a durable reference expression or a value expression, depending on which
interface the type implements:

- If subscripting an r-value produces an r-value result, as with an array, the
type should implement `IndexWith`.
- If subscripting an r-value produces an l-value result, as with C++'s
`std::span`, the type should implement `IndirectIndexWith`.
- If subscripting a value expression produces a value expression, as with an
array, the type should implement `IndexWith`.
- If subscripting a value expression produces a durable reference expression,
as with C++'s `std::span`, the type should implement `IndirectIndexWith`.

`IndirectIndexWith` is a subtype of `IndexWith`, and subscript expressions are
rewritten to method calls on `IndirectIndexWith` if the type is known to
Expand All @@ -39,6 +42,19 @@ implement that interface, or to method calls on `IndexWith` otherwise.
`IndirectIndexWith` provides a final blanket `impl` of `IndexWith`, so a type
can implement at most one of those two interfaces.

The `Addr` methods of these interfaces, which are used to form durable reference
expressions on indexing, must return a pointer and work similarly to the
[pointer dereference customization interface](/docs/design/values.md#dereferencing-customization).
The returned pointer is then dereferenced by the language to form the reference
expression referring to the pointed-to object. These methods must return a raw
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
pointer-like types on their indexing boundary and have them still be
automatically dereferenced.

## Details

A subscript expression has the form "_lhs_ `[` _index_ `]`". As in C++, this
Expand All @@ -61,13 +77,15 @@ interface IndirectIndexWith(SubscriptType:! type) {
```

A subscript expression where _lhs_ has type `T` and _index_ has type `I` is
rewritten based on the value category of _lhs_ and whether `T` is known to
rewritten based on the expression category of _lhs_ and whether `T` is known to
implement `IndirectIndexWith(I)`:

- If `T` implements `IndirectIndexWith(I)`, the expression is rewritten to
"`*((` _lhs_ `).(IndirectIndexWith(I).Addr)(` _index_ `))`".
- Otherwise, if _lhs_ is an l-value, the expression is rewritten to "`*((`
_lhs_ `).(IndexWith(I).Addr)(` _index_ `))`".
- Otherwise, if _lhs_ is a
[_durable reference expression_](/docs/design/values.md#durable-reference-expressions),
the expression is rewritten to "`*((` _lhs_ `).(IndexWith(I).Addr)(` _index_
`))`".
- Otherwise, the expression is rewritten to "`(` _lhs_ `).(IndexWith(I).At)(`
_index_ `)`".

Expand Down Expand Up @@ -136,3 +154,5 @@ Carbon API.

- Proposal
[#2274: Subscript syntax and semantics](https://github.com/carbon-language/carbon-lang/pull/2274)
- Proposal
[#2006: Values, variables, and pointers](https://github.com/carbon-language/carbon-lang/pull/2006)
19 changes: 18 additions & 1 deletion docs/design/expressions/member_access.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
## Overview

A _qualified name_ is a [word](../lexical_conventions/words.md) that is preceded
by a period. The name is found within a contextually determined entity:
by a period or a rightward arrow. The name is found within a contextually
determined entity:

- In a member access expression, this is the entity preceding the period.
- In a pointer member access expression, this is the entity pointed to by the
pointer preceding the rightward arrow.
- For a designator in a struct literal, the name is introduced as a member of
the struct type.

Expand All @@ -43,10 +46,12 @@ A member access expression is either a _simple_ member access expression of the
form:

- _member-access-expression_ ::= _expression_ `.` _word_
- _member-access-expression_ ::= _expression_ `->` _word_

or a _compound_ member access of the form:

- _member-access-expression_ ::= _expression_ `.` `(` _expression_ `)`
- _member-access-expression_ ::= _expression_ `->` `(` _expression_ `)`

Compound member accesses allow specifying a qualified member name.

Expand All @@ -66,14 +71,26 @@ class Cog {
fn GrowSomeCogs() {
var cog1: Cog = Cog.Make(1);
var cog2: Cog = cog1.Make(2);
var cog_pointer: Cog* = &cog2;
let cog1_size: i32 = cog1.size;
cog1.Grow(1.5);
cog2.(Cog.Grow)(cog1_size as f64);
cog1.(Widget.Grow)(1.1);
cog2.(Widgets.Cog.(Widgets.Widget.Grow))(1.9);
cog_pointer->Grow(0.75);
cog_pointer->(Widget.Grow)(1.2);
}
```

Pointer member access expressions are those using a `->` instead of a `.` and
their semantics are exactly what would result from first dereferencing the
expression preceding the `->` and then forming a member access expression using
a `.`. For example, a simple pointer member access expression _expression_ `->`
_word_ becomes `(` `*` _expression_ `)` `.` _word_. More details on this syntax
and semantics can be found in the [pointers](/docs/design/values.md#pointers)
design. The rest of this document describes the semantics using `.` alone for
simplicity.

A member access expression is processed using the following steps:

- First, the word or parenthesized expression to the right of the `.` is
Expand Down
57 changes: 57 additions & 0 deletions docs/design/expressions/pointer_operators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Pointer operators

<!--
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-->

<!-- toc -->

## Table of contents

- [Overview](#overview)
- [Details](#details)
- [Precedence](#precedence)
- [Alternatives considered](#alternatives-considered)
- [References](#references)

<!-- tocstop -->

## Overview

Carbon provides the following operators related to pointers:

- `&` as a prefix unary operator takes the address of an object, forming a
pointer to it.
- `*` as a prefix unary operator dereferences a pointer.

Note that [member access expressions](member_access.md) include an `->` form
that implicitly performs a dereference in the same way as the `*` operator.

## Details

The semantic details of pointer operators are collected in the main
[pointers](/docs/design/values.md#pointers) design. The syntax and precedence
details are covered here.

The syntax tries to remain as similar as possible to C++ pointer types as they
are commonly written in code and are expected to be extremely common and a key
anchor of syntactic similarity between the languages.

### Precedence

These operators have high precedence. Only [member access](member_access.md)
expressions can be used as an unparenthesized operand to them.

The two prefix operators `&` and `*` are generally above the other unary and
binary operators and can appear inside them as unparenthesized operands. For the
full details, see the [precedence graph](README.md#precedence).

## Alternatives considered

- [Alternative pointer syntaxes](/proposals/p2006.md#alternative-pointer-syntaxes)

## References

- [Proposal #2006: Values, variables, and pointers](/proposals/p2006.md)
Loading