Skip to content

Commit

Permalink
fixup! Update docs related to const-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Apr 17, 2020
1 parent 4386a2c commit a8623d1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/const-eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ Constant evaluation can be done by calling the `const_eval_*` queries of `TyCtxt

The `const_eval_*` queries use a [`ParamEnv`](./param_env.html) of environment
in which the constant is evaluated (e.g. the function within which the constant is used)
and a `GlobalId`. The `GlobalId` is made up of an `Instance` referring to a constant
and a [`GlobalId`]. The `GlobalId` is made up of an `Instance` referring to a constant
or static or of an `Instance` of a function and an index into the function's `Promoted` table.

Constant evaluation returns a [`ConstEvalResult`] with either the error, or the simplest
representation of the constant. "simplest" meaning if it is representable as an
integer or fat pointer, it will directly yield the value (via `ConstValue::Scalar` or
`ConstValue::Slice`), instead of referring to the [`miri`](./miri.html) virtual
memory allocation (via `ConstValue::ByRef`). This means that the `const_eval_*`
integer or fat pointer, it will directly yield the value (via [`ConstValue::Scalar`]
or [`ConstValue::Slice`]), instead of referring to the [`miri`](./miri.html) virtual
memory allocation (via [`ConstValue::ByRef`]). This means that the `const_eval_*`
functions cannot be used to create miri-pointers to the evaluated constant or
static. If you need that, you need to directly work with the functions in
[`src/librustc_mir/const_eval.rs`].

[`GlobalId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/struct.GlobalId.html
[`ConstValue::Scalar`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Scalar
[`ConstValue::Slice`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Slice
[`ConstValue::ByRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.ByRef
[`ConstEvalResult`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/error/type.ConstEvalResult.html
[`src/librustc_mir/const_eval.rs`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/const_eval/index.html

0 comments on commit a8623d1

Please sign in to comment.