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: promotion.md
+32-35
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Const promotion
2
2
3
-
"Promotion" is the act of guaranteeing that code *not* written in an (explicit)
4
-
const context will be run at compile-time. Explicit const contexts include the
5
-
initializer of a `const` or `static`, or an array length expression.
3
+
"Promotion" is the act of splicing a part of a MIR computation out into a
4
+
separate self-contained MIR body which is evaluated at compile-time like a
5
+
constant.
6
6
7
7
## Promotion contexts
8
8
@@ -44,41 +44,41 @@ attribute, introduced in
44
44
specify these parameters and (aggressively, see below) try to promote the
45
45
corresponding arguments.
46
46
47
-
###Implicit and explicit contexts
47
+
## Implicit and explicit promotion
48
48
49
49
On top of what applies to [consts](const.md), promoteds suffer from the additional issue that *the user did not ask for them to be evaluated at compile-time*.
50
50
Thus, if CTFE fails but the code would have worked fine at run-time, we broke the user's code for no good reason.
51
51
Even if we are sure we found an error in the user's code, we are only allowed to [emit a warning, not a hard error][warn-rfc].
52
-
That's why we have to be very conservative with what can and cannot be promoted.
52
+
We call this *implicit* promotion, and we have to be very conservative with what can and cannot be implicitly promoted.
53
53
54
-
For example, users might be surprised to learn that whenever they take a
55
-
reference to a temporary, that temporary may be promoted away and never
56
-
actually put on the stack. In this way, lifetime extension is an "implicit
57
-
promotion context": the user did not ask for the value to be promoted.
54
+
CTFE of implicitly promoted code must never fail to evaluate except if the
55
+
run-time code also would have failed. This means we cannot permit calling
0 commit comments