@@ -22,12 +22,12 @@ The compiler needs to figure out the length of the array before being able to
22
22
create items that use the type (locals, constants, function arguments, ...).
23
23
24
24
To obtain the (in this case empty) parameter environment, one can call
25
- ` let param_env = tcx.param_env(def_id ); ` . The ` GlobalId ` needed is
25
+ ` let param_env = tcx.param_env(length_def_id ); ` . The ` GlobalId ` needed is
26
26
27
27
``` rust
28
28
let gid = GlobalId {
29
29
promoted : None ,
30
- instance : Instance :: mono (def_id ),
30
+ instance : Instance :: mono (length_def_id ),
31
31
};
32
32
```
33
33
@@ -51,8 +51,8 @@ const Foo::{{initializer}}: usize = {
51
51
}
52
52
```
53
53
54
- Before the evaluation, a virtual memory location is created for storing the
55
- evaluation result, in this case a ` vec![u8; size_of::<usize>()] ` .
54
+ Before the evaluation, a virtual memory location (in this case essentially a
55
+ ` vec![u8; 4] ` or ` vec![u8; 8] ` ) is created for storing the evaluation result .
56
56
57
57
At the start of the evaluation, ` _0 ` and ` _1 ` are
58
58
` Value::ByVal(PrimVal::Undef) ` . When the initialization of ` _1 ` is invoked, the
@@ -67,7 +67,7 @@ The next statement asserts that said boolean is `0`. In case the assertion
67
67
fails, its error message is used for reporting a compile-time error.
68
68
69
69
Since it does not fail, ` Value::ByVal(PrimVal::Bytes(4054)) ` is stored in the
70
- virtual memory was allocated before th evaluation. ` _0 ` always refers to that
70
+ virtual memory was allocated before the evaluation. ` _0 ` always refers to that
71
71
location directly.
72
72
73
73
After the evaluation is done, the virtual memory allocation is interned into the
@@ -82,9 +82,9 @@ executed in order to get at something as simple as a `usize`.
82
82
## Datastructures
83
83
84
84
Miri's core datastructures can be found in
85
- https://github.com/rust-lang/rust/blob/master/src/librustc/mir/interpret . This
86
- is mainly the error enum and the ` Value ` and ` PrimVal ` types. A ` Value ` can be
87
- either ` ByVal ` (a single ` PrimVal ` ), ` ByValPair ` (two ` PrimVal ` s, usually fat
85
+ [ librustc/mir/interpret ] ( https://github.com/rust-lang/rust/blob/master/src/librustc/mir/interpret ) .
86
+ This is mainly the error enum and the ` Value ` and ` PrimVal ` types. A ` Value ` can
87
+ be either ` ByVal ` (a single ` PrimVal ` ), ` ByValPair ` (two ` PrimVal ` s, usually fat
88
88
pointers or two element tuples) or ` ByRef ` , which is used for anything else and
89
89
refers to a virtual allocation. These allocations can be accessed via the
90
90
methods on ` tcx.interpret_interner ` .
@@ -112,7 +112,7 @@ to a pointer to `b`.
112
112
113
113
Although the main entry point to constant evaluation is the ` tcx.const_eval `
114
114
query, there are additional functions in
115
- https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/const_eval
115
+ [ librustc_mir/interpret/const_eval.rs ] ( https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/const_eval.rs )
116
116
that allow accessing the fields of a ` Value ` (` ByRef ` or otherwise). You should
117
117
never have to access an ` Allocation ` directly except for translating it to the
118
118
compilation target (at the moment just LLVM).
@@ -123,7 +123,7 @@ function with no arguments, except that constants do not allow local (named)
123
123
variables at the time of writing this guide.
124
124
125
125
A stack frame is defined by the ` Frame ` type in
126
- https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/eval_context.rs
126
+ [ librustc_mir/interpret/eval_context.rs ] ( https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/eval_context.rs )
127
127
and contains all the local
128
128
variables memory (` None ` at the start of evaluation). Each frame refers to the
129
129
evaluation of either the root constant or subsequent calls to ` const fn ` . The
@@ -135,7 +135,7 @@ The frames are just a `Vec<Frame>`, there's no way to actually refer to a
135
135
memory that can be referred to are ` Allocation ` s.
136
136
137
137
Miri now calls the ` step ` method (in
138
- https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/step.rs
138
+ [ librustc_mir/interpret/step.rs ] ( https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/step.rs )
139
139
) until it either returns an error or has no further statements to execute. Each
140
140
statement will now initialize or modify the locals or the virtual memory
141
141
referred to by a local. This might require evaluating other constants or
0 commit comments