|
1 |
| -Some terms, defined by me. Please debate on them, or correct them, as you see fit :) |
| 1 | +My version of the OP |
2 | 2 |
|
3 |
| -* Object - Contiguous block of memory with a certain size and a certain alignment. |
| 3 | +## Statics |
| 4 | + |
| 5 | +### Type |
| 6 | + |
| 7 | +A rustc `Ty` - You should know what this is :-). Not to be confused with an LLVM type or anything else. |
| 8 | + |
| 9 | +### Concrete Type |
| 10 | + |
| 11 | +A *type* without type parameters. |
| 12 | + |
| 13 | +### Location Expression (lexpr) |
| 14 | + |
| 15 | + |
| 16 | +A typed expression that evaluates to an *object*, as opposed to a *vexpr*. The LHS of an assignment and the scrutinee of a pattern are examples of *lexpr*s. |
| 17 | + |
| 18 | +If a *vexpr* is used where an *lexpr* is expected (other than the LHS of an assignment, where |
| 19 | +using a *vexpr* is illegal), it is wrapped in an implicit *temporary lexpr*. |
| 20 | + |
| 21 | +### Value Expression (vexpr) |
| 22 | + |
| 23 | +A typed expression that evaluates to an *value*, as opposed to a *lexpr*. The RHS of an |
| 24 | +assignment and the arguments of a function are examples of *vexpr*s. |
| 25 | + |
| 26 | +If a *lexpr* is used where an *vexpr* is expected, it is wrapped in an implicit |
| 27 | +*use vexpr*. |
| 28 | + |
| 29 | +### Temporary Lexpr |
| 30 | + |
| 31 | +```Rust |
| 32 | + LExprKind::Temp(P<VExpr>) |
| 33 | +``` |
| 34 | + |
| 35 | +A kind of implicit *lexpr* that wraps a *vexpr* when a *lexpr* is needed. When |
| 36 | + evaluated, it: |
| 37 | + |
| 38 | + * creates a temporary slot, scheduled for destruction at the end of the current *temporary scope*. |
| 39 | + * evaluates the *vexpr* and stores it within the slot. |
| 40 | + * evaluates into the temporary slot object. |
| 41 | + |
| 42 | +A common example occurs when the result of `format!` is borrowed - it is wrapped by |
| 43 | +an implicit temporary lexpr. |
| 44 | + |
| 45 | +```Rust |
| 46 | +fn send(message: &str) { |
| 47 | + /* .. */ |
| 48 | +} |
| 49 | + |
| 50 | +fn main() { |
| 51 | + let message = &format!("1+1={}", 1+1); |
| 52 | + send(message); |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Use Vexpr |
| 57 | + |
| 58 | +```Rust |
| 59 | + LExprKind::Use(P<LExpr>) |
| 60 | +``` |
| 61 | + |
| 62 | +A kind of implicit *vexpr* that wraps a *lexpr* when a *vexpr* is needed. When |
| 63 | +evaluated, it evaluates the *lexpr* and reads the *value* from the evaluated-to |
| 64 | +*object*. |
| 65 | + |
| 66 | +If the expression's type does not implement `Copy`, the value is moved out of the |
| 67 | +read-from *object*, preventing further accesses. |
| 68 | + |
| 69 | +The read-from *object* must be aligned to `align_of::<T>()` or behavior is undefined. |
| 70 | + |
| 71 | +As usual, all `size_of::<T>()` bytes of the *object* must be accessible and |
| 72 | +remain stable for the duration required by the aliasing rules. |
| 73 | + |
8000
| 74 | +### Lvalue, Rvalue |
| 75 | + |
| 76 | +These terms are banned because they are used in conflicting ways in various places. |
| 77 | + |
| 78 | +## Dynamics |
| 79 | + |
| 80 | +### Object - Contiguous block of memory with a certain size and a certain alignment. |
4 | 81 |
|
5 | 82 | Each object has the capability to read the memory.
|
6 | 83 |
|
@@ -28,26 +105,12 @@ let x: Box<i32> = Box::new(0i32); // a stack, read-only object pointing to a hea
|
28 | 105 | // read-write object of size >= 4, alignment >= 4
|
29 | 106 | ```
|
30 | 107 |
|
31 |
| -* `lexpr` or `locator expression` - A typed expression which refers to a specific memory location, an object, as opposed to just a value - i.e., if you try to move it, and it's not Copy, there's a compiler error |
32 |
| - |
33 |
| -If you read a lexpr of type T, the object referred to by the lexpr must have `align_of::<T>()`, and `size_of::<T>()`. The bytes of the object gets read as the type of the lexpr, if they are valid; otherwise, undefined behavior. |
34 |
| - |
35 |
| -```rust |
36 |
| -let x: Box<i32> = Box::new(0i32); |
37 |
| --> x |
38 |
| --> *x |
39 |
| -``` |
40 |
| - |
41 |
| -Both examples of expressions that refer to specific objects. |
| 108 | +A note: |
42 | 109 |
|
43 |
| -* `value` - A typed expression which refers only to a value - i.e., if you take the address, it must create a temporary. |
| 110 | +Objects aren't typed. No, not even effective types ^-^ |
44 | 111 |
|
45 |
| -```rust |
46 |
| --> 0i32 |
47 |
| -let x: i32 = 0i32; |
48 |
| --> &x |
49 |
| -``` |
| 112 | +### Value - inhabitant of a type |
50 | 113 |
|
51 |
| -A note: |
| 114 | +A *value* is the inhabitant of a type. *Value*s are purely mathematical objects and neither live in memory not form part of a program statement. However, datums may be partially `undef` (do we want that?). |
52 | 115 |
|
53 |
| -Objects aren't typed. No, not even effective types ^-^ |
| 116 | +Example values are `true: bool`, `[0, 0, 0, 0]: [u32; 4]`, `0xcccccccc: *const u32`, `the address of the local "foo": &u32`. `Some((4, 2)): Option<(u32, usize)>`. |
0 commit comments