You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specification/terms.md
+39-34Lines changed: 39 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -77,22 +77,25 @@ If a vexpr is used where an lexpr is expected (other than the LHS of an assignme
77
77
A typed expression that evaluates to an value, as opposed to an object. The RHS of an assignment and the arguments of a function are examples of vexprs.
78
78
79
79
NOTE: Because of evaluation order concerns, after being potentially wrapped to a
80
-
vexpr, subexpressions are often wrapped in a `VExpr::Use(LExpr::Temp(vexpr))`. The
80
+
vexpr, subexpressions are often wrapped in a `Use(Temp(vexpr))`. The
81
81
exact rules here should be documented.
82
82
83
83
If a lexpr is used where an vexpr is expected, it is wrapped in an implicit use
84
84
vexpr, the rules of which are given in §2.3.
85
85
86
86
### §2.3 Temporary lexpr
87
87
88
-
```Rust
89
-
LExpr::Temp(VExpr)
88
+
```
89
+
Temp:
90
+
Γ ⊢ vexp VExpr
91
+
--------------
92
+
Γ ⊢ Temp(vexp) LExpr
90
93
```
91
94
92
95
An implicit lexpr that wraps a vexpr when an lexpr is expected.
93
96
When evaluated, it:
94
97
95
-
* creates a temporary object, scheduled for destruction at the end of the current temporary scope.
98
+
* creates a temporary object within the arena selected by the arena specification.
96
99
* evaluates the vexpr and stores it within the object.
97
100
* evaluates to the temporary object.
98
101
@@ -111,8 +114,11 @@ fn main() {
111
114
112
115
### §2.4 Use vexpr
113
116
114
-
```Rust
115
-
VExpr::Use(LExpr)
117
+
```
118
+
Use:
119
+
Γ ⊢ vexp VExpr
120
+
--------------
121
+
Γ ⊢ Use(vexp) LExpr
116
122
```
117
123
118
124
An implicit vexpr that wraps a lexpr when a vexpr is expected.
@@ -126,31 +132,12 @@ If the value read is an `undef`, behavior is undefined unless the expression's
126
132
type is an integer, in which case behavior is unspecified (FIXME: this is intended
127
133
to allow reads from padding - what can we say here?).
128
134
129
-
The read-from object must be aligned to `align_of::<T>()` or behavior is undefined.
135
+
The read-from object must be aligned to `AlignOf(T)` or behavior is undefined.
130
136
131
137
If the expression's type does not implement `Copy`, the value is moved out of the
132
138
object, preventing further accesses.
133
139
134
-
### §2.5 Destruction scopes
135
-
136
-
A Rust function always keeps a chain of destruction scopes. Each destruction scope contains a list of objects - temporaries and variables - that are to be destroyed when that scope is exited.
137
-
138
-
The objects in a scope are dropped in the reverse order of their insertion. If such an object is in an uninitialized state (either because it was never initialized or because it was moved out of), it is not destroyed again.
139
-
140
-
If one of the destructors panics, the current scope as well as the remaining scopes
141
-
are exited and the panic continues to unwind.
142
-
143
-
### §2.5.1 Temporary scopes
144
-
145
-
A set of baroque rules assigns a destruction scope, called the *temporary scope*,
146
-
to each expression.
147
-
148
-
FIXME: explain these rules.
149
-
150
-
The temporary created by `LExpr::Temp` is added to that expression's temporary
151
-
scope's destruction list.
152
-
153
-
### §2.6 Note on the terms lvalue and rvalue
140
+
### §2.5 Note on the terms lvalue and rvalue
154
141
155
142
These terms aren't used in this document, because they are used in conflicting ways in various places. However, lvalue is equivalent to lexpr, while rvalue is equivalent to vexpr.
156
143
@@ -162,37 +149,55 @@ An object is an untyped, contiguous block of memory with a certain size and a ce
162
149
163
150
All objects are able to be read, but you may not write to all objects.
164
151
165
-
A lexpr associated with an object, as a vexpr, will evaluate to a value (see §4) that is equivalent to the memory of the object, interpreted as the type of the lexpr.
152
+
A `Use` vexpr, applied to a lexpr that evaluates to an object, will evaluate to a value (see §4) that is equivalent to the memory of the object, interpreted as the type of the vexpr.
166
153
167
-
A write to an object will set the memory of that object equivalent to the value of the write, without the interpretation of typing.
154
+
A write to an object will set the memory of that object equivalent to the value of the write, without the interpretation of typing. (XXX: padding on assignment).
168
155
169
156
### §3.2 Allocation.
170
157
171
-
An object may be allocated in one of three ways:
158
+
Objects may be created in the following ways, which create objects that do not overlap as long as they are valid.
159
+
160
+
There may be other (implementation-defined and/or unspecified) ways to create objects.
161
+
162
+
### §3.2.1 Statics
172
163
173
-
In static memory:
164
+
Statics are valid until the end of the program. For example,
174
165
175
166
```rust
176
167
staticx:i32=0i32; // a static, read-only object of size >= 4, alignment >= 4
177
168
staticmutx:i32=0i32; // a static, read-write object of size >= 4, alignment >= 4
178
169
staticx:AtomicI32=0i32; // a static, read-write object of size >= 4, alignment >= 4
179
170
```
180
171
181
-
on the stack:
172
+
### §3.2.2 Locals
173
+
174
+
Locals include argument buffers, temporaries, and named bindings. They are always allocated into an arena (§3.3) and are valid until destroyed by it.
175
+
176
+
For example:
182
177
183
178
```rust
184
179
letx:i32=0i32; // a stack, read-only object of size >= 4, alignment >= 4
185
180
// you get the point
186
181
```
187
182
188
-
or on the heap:
183
+
### §3.2.3 Heap Allocations
184
+
185
+
Each call to `Box::new` creates a heap allocation, which is valid until it is destroyed when the box is dropped.
186
+
187
+
For example:
189
188
190
189
```rust
191
190
letx:Box<i32> =Box::new(0i32); // a stack, read-only object pointing to a heap,
192
191
// read-write object of size >= 4, alignment >= 4
193
192
```
194
193
195
-
### §3.3 Note on types:
194
+
### §3.3 Arenas
195
+
196
+
A function's stack of arenas is used to manage the orderly destruction of the locals within that function.
197
+
198
+
See [the arena specification](https://github.com/nikomatsakis/rust-memory-model/issues/17) for more details (XXX: write it somewhere more permanent).
199
+
200
+
### §3.4 Note on types:
196
201
197
202
Objects *are not* typed. No, not even effective types ^-^
0 commit comments