From 72177e644c9b658196b02738a874d79417ee4135 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 19 Jul 2018 19:09:50 +0200 Subject: [PATCH 1/1] notation --- ralf/_posts/2018-07-19-const.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ralf/_posts/2018-07-19-const.md b/ralf/_posts/2018-07-19-const.md index d523935..d93a6cd 100644 --- a/ralf/_posts/2018-07-19-const.md +++ b/ralf/_posts/2018-07-19-const.md @@ -13,7 +13,7 @@ Expect something like a structured brain dump, so there are some unanswered ques ## Some Background -CTFE is the mechanism used by the compiler, primarily, to evaluate items like `const x : T = ...;`. +CTFE is the mechanism used by the compiler, primarily, to evaluate items like `const x: T = ...;`. The `...` here is going to be Rust code that must be "run" at compile-time, because it can be used as a constant in the code -- for example, it can be used for array lengths. Notice that CTFE is *not* the same as constant propagation: Constant propagation is an optimization pass done by LLVM that will opportunistically change code like `3 + 4` into `7` to avoid run-time work. @@ -23,8 +23,8 @@ You can statically see, just from the syntax of the code, whether CTFE applies t CTFE is only used in places like the value of a `const` or the length of an array. {% highlight rust %} fn demo() { - const X : u32 = 3 + 4; // CTFE - let x : u32 = 4 + 3; // no CTFE (but maybe constant propagation) + const X: u32 = 3 + 4; // CTFE + let x: u32 = 4 + 3; // no CTFE (but maybe constant propagation) } {% endhighlight %} We say that the `3 + 4` above is in *const context* and hence subject to CTFE, but the `4 + 3` is not. -- 2.30.2