Skip to content

Commit 56d6726

Browse files
authored
update status of dynamic checks (#34)
update status of dynamic checks
2 parents e9c3add + f57d84f commit 56d6726

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

const.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ is actually accepted by the compiler because we know that there is no
5757
`UnsafeCell` here that would permit interior mutability.
5858

5959
*Dynamic check.* The Miri engine enforces this dynamically by ensuring that the
60-
new data that is interned for a constant is all marked as immutable. However,
61-
note the FIXME added [by this PR](https://github.com/rust-lang/rust/pull/63955):
62-
for untyped data in a constant, we currently just *make* it immutable, instead
63-
of checking properly.
60+
new data that is interned for a constant is all marked as immutable.
6461

6562
Note that a constant *referring to* some already existing mutable memory is
6663
fine: inlining that reference everywhere has the same behavior as computing a
@@ -113,5 +110,5 @@ was about first computing a `&Cell<i32>` and then using it at run-time (and
113110
observing the fact that it has been "deduplicated"), this here is about using
114111
such a value at compile-time even though it might be changed at run-time.
115112

116-
*Dynamic check.* The Miri engine could check this dynamically by refusing to
117-
access mutable global memory when computing a const.
113+
*Dynamic check.* The Miri engine checks this dynamically by refusing to access
114+
global memory when computing a const.

promotion.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ restrictions described there are needed because we want `const` to behave the
120120
same as copying the `const` initializer everywhere the constant is used; we need
121121
the same property when promoting expressions. But we need more.
122122

123+
Note that there is no point in doing additional dynamic checks here. The entire point of
124+
the promotion restrictions is to avoid failing compilation for code that would
125+
have been fine without promotion. The best a dynamic check could do is tell us
126+
after the fact that we should not have promoted something, but then it is
127+
already too late -- and the dynamic checks for that are exactly the ones we are
128+
already doing for constants and statics.
129+
123130
### Panics
124131

125132
Promotion is not allowed to throw away side effects. This includes panicking.
@@ -153,9 +160,6 @@ earlier version of miri used to panic on arithmetic overflow even in release
153160
mode. This breaks promotion, because now promoting code that would work (and
154161
could not panic!) at run-time leads to a compile-time CTFE error.
155162

156-
*Dynamic check.* The Miri engine already dynamically detects panics, but the
157-
main point of promoteds is ruling them out statically.
158-
159163
### Const safety
160164

161165
We have explained what happens when evaluating a promoted panics, but what about
@@ -202,9 +206,6 @@ way when working with const-safe arguments.
202206
For this reason, only `const fn` that were explicitly marked with the
203207
`#[rustc_promotable]` attribute are subject to promotion.
204208

205-
*Dynamic check.* The Miri engine already dynamically detects const safety
206-
violations, but the main point of promoteds is ruling them out statically.
207-
208209
### Drop
209210

210211
Expressions returning "needs drop" types can never be promoted. If such an

0 commit comments

Comments
 (0)