Description
With rust-lang/rust#56123, we can bypass const qualification, so we can e.g. write constants that read from interior mutable statics, and probably other things I forgot to think about.
Could we
- implement all these restrictions as dynamic checks (during the miri execution, similar to CTFE: dynamically make sure we do not call non-const-fn rust#56007)
- and collect in this repo what these constraints are?
Ideally, these restrictions would be sufficient, so the soundness criterion for the static checks could be fully described as "statically check for the absence of the following miri errors" -- and such that @oli-obk's feature would actually be sound!
For example, I could imagine tweaking the CTFE instance of miri such that reading from a static is disallowed (and not just disallowing writing to a static like now), implementing a dynamic check that would reject code like what I described above.
For the UnsafeCell and Drop checks, we'd need some value-based analysis, which @oli-obk wanted in the long run anyway.
Checklist:
- Add test for checking that we reject
drop
calls during initializer evaluation. - Guard against accessing statics when evaluating const initializer (+ test). (fixed by Ensure that evaluating or validating a constant never reads from a static rust#67337)
- No new mutable state via consts (fixed by Ensure that evaluating or validating a constant never reads from a static rust#67337)
- miri-unleash test for: accessing a thread-local static
- miri-unleash test for: evaluating inline assembly
- Something for
Sync
? See Constants can contain references that are not Sync rust#49206.
The problem with promotion is tracked separately at #53.
Cc @eddyb