|
@@ -12,7 +12,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
|
|
|
- [Values, objects, and expressions](#values-objects-and-expressions)
|
|
- [Values, objects, and expressions](#values-objects-and-expressions)
|
|
|
- [Expression categories](#expression-categories)
|
|
- [Expression categories](#expression-categories)
|
|
|
- - [Value binding](#value-binding)
|
|
|
|
|
|
|
+ - [Value acquisition](#value-acquisition)
|
|
|
- [Direct initialization](#direct-initialization)
|
|
- [Direct initialization](#direct-initialization)
|
|
|
- [Copy initialization](#copy-initialization)
|
|
- [Copy initialization](#copy-initialization)
|
|
|
- [Temporary materialization](#temporary-materialization)
|
|
- [Temporary materialization](#temporary-materialization)
|
|
@@ -80,8 +80,8 @@ There are three expression categories in Carbon:
|
|
|
Expressions in one category can be converted to any other category when needed.
|
|
Expressions in one category can be converted to any other category when needed.
|
|
|
The primitive conversion steps used are:
|
|
The primitive conversion steps used are:
|
|
|
|
|
|
|
|
-- [_Value binding_](#value-binding) forms a value expression from the current
|
|
|
|
|
- value of the object referenced by a reference expression.
|
|
|
|
|
|
|
+- [_Value acquisition_](#value-acquisition) forms a value expression from the
|
|
|
|
|
+ current value of the object referenced by a reference expression.
|
|
|
- [_Direct initialization_](#direct-initialization) converts a value
|
|
- [_Direct initialization_](#direct-initialization) converts a value
|
|
|
expression into an initializing expression.
|
|
expression into an initializing expression.
|
|
|
- [_Copy initialization_](#copy-initialization) converts a reference
|
|
- [_Copy initialization_](#copy-initialization) converts a reference
|
|
@@ -91,11 +91,11 @@ The primitive conversion steps used are:
|
|
|
|
|
|
|
|
These conversion steps combine to provide the transitive conversion table:
|
|
These conversion steps combine to provide the transitive conversion table:
|
|
|
|
|
|
|
|
-| From: | value | reference | initializing |
|
|
|
|
|
-| ------------------: | ------------------------- | --------- | ------------------ |
|
|
|
|
|
-| to **value** | == | bind | materialize + bind |
|
|
|
|
|
-| to **reference** | direct init + materialize | == | materialize |
|
|
|
|
|
-| to **initializing** | direct init | copy init | == |
|
|
|
|
|
|
|
+| From: | value | reference | initializing |
|
|
|
|
|
+| ------------------: | ------------------------- | --------- | --------------------- |
|
|
|
|
|
+| to **value** | == | acquire | materialize + acquire |
|
|
|
|
|
+| to **reference** | direct init + materialize | == | materialize |
|
|
|
|
|
+| to **initializing** | direct init | copy init | == |
|
|
|
|
|
|
|
|
Reference expressions formed through temporary materialization are called
|
|
Reference expressions formed through temporary materialization are called
|
|
|
[_ephemeral reference expressions_](#ephemeral-reference-expressions) and have
|
|
[_ephemeral reference expressions_](#ephemeral-reference-expressions) and have
|
|
@@ -105,13 +105,14 @@ to declared storage are called
|
|
|
restrictions on what is valid, there is no distinction in their behavior or
|
|
restrictions on what is valid, there is no distinction in their behavior or
|
|
|
semantics.
|
|
semantics.
|
|
|
|
|
|
|
|
-#### Value binding
|
|
|
|
|
|
|
+#### Value acquisition
|
|
|
|
|
|
|
|
-We call forming a value expression from a reference expression _value binding_.
|
|
|
|
|
-This forms a value expression that will evaluate to the value of the object in
|
|
|
|
|
-the referenced storage of the reference expression. It may do this by eagerly
|
|
|
|
|
-reading that value into a machine register, lazily reading that value on-demand
|
|
|
|
|
-into a machine register, or in some other way modeling that abstract value.
|
|
|
|
|
|
|
+We call forming a value expression from a reference expression _value
|
|
|
|
|
+acquisition_. This forms a value expression that will evaluate to the value of
|
|
|
|
|
+the object in the referenced storage of the reference expression. It may do this
|
|
|
|
|
+by eagerly reading that value into a machine register, lazily reading that value
|
|
|
|
|
+on-demand into a machine register, or in some other way modeling that abstract
|
|
|
|
|
+value.
|
|
|
|
|
|
|
|
See the [value expressions](#value-expressions) section for more details on the
|
|
See the [value expressions](#value-expressions) section for more details on the
|
|
|
semantics of value expressions.
|
|
semantics of value expressions.
|
|
@@ -132,8 +133,8 @@ trivially and where this is implemented as a `memcpy` of their underlying bytes.
|
|
|
#### Temporary materialization
|
|
#### Temporary materialization
|
|
|
|
|
|
|
|
We use temporary materialization when we need to initialize an object by way of
|
|
We use temporary materialization when we need to initialize an object by way of
|
|
|
-storage, but weren't provided dedicate storage and can simply bind the result to
|
|
|
|
|
-a value afterward.
|
|
|
|
|
|
|
+storage, but weren't provided dedicated storage and can simply acquire the
|
|
|
|
|
+result as a value afterward.
|
|
|
|
|
|
|
|
> **Open question:** The lifetimes of temporaries is not yet specified.
|
|
> **Open question:** The lifetimes of temporaries is not yet specified.
|
|
|
|
|
|
|
@@ -235,7 +236,7 @@ occur, which will typically be marked by an open brace (`{`) and close brace
|
|
|
|
|
|
|
|
### Consuming function parameters
|
|
### Consuming function parameters
|
|
|
|
|
|
|
|
-Just as part of a `let` binding can use a `var` prefix to become a variable
|
|
|
|
|
|
|
+Just as part of a `let` declaration can use a `var` prefix to become a variable
|
|
|
pattern and bind names that will form reference expressions to the variable's
|
|
pattern and bind names that will form reference expressions to the variable's
|
|
|
storage, so can function parameters:
|
|
storage, so can function parameters:
|
|
|
|
|
|
|
@@ -338,11 +339,11 @@ enable generic code that needs a single type model that will have consistently
|
|
|
good performance.
|
|
good performance.
|
|
|
|
|
|
|
|
When forming a value expression from a reference expression, Carbon
|
|
When forming a value expression from a reference expression, Carbon
|
|
|
-[binds](#value-binding) the referenced object to that value expression. This
|
|
|
|
|
-allows immediately reading from the object's storage into a machine register or
|
|
|
|
|
-a copy if desired, but does not require that. The read of the underlying object
|
|
|
|
|
-can also be deferred until the value expression itself is used. Once an object
|
|
|
|
|
-is bound to a value expression in this way, any mutation to the object or its
|
|
|
|
|
|
|
+[acquires](#value-acquisition) the value of the referenced object. This allows
|
|
|
|
|
+immediately reading from the object's storage into a machine register or a copy
|
|
|
|
|
+if desired, but does not require that. The read of the underlying object can
|
|
|
|
|
+also be deferred until the value expression itself is used. Once an object is
|
|
|
|
|
+bound to a value expression in this way, any mutation to the object or its
|
|
|
storage ends the lifetime of the value binding, and makes any use of the value
|
|
storage ends the lifetime of the value binding, and makes any use of the value
|
|
|
expression an error.
|
|
expression an error.
|
|
|
|
|
|