-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic checks for all const soundness concerns? #17
Comments
Recently @eddyb said something like "turns out Miri catches errors in const qualif, that's good news" -- basically referring to this issue. I take this as confirmation that this is a goal worth pursuing. With rust-lang/rust#58351, a bunch of "holes" in these checks are fixed. But I think I need help to figure out what is left. Here is an incomplete list, with examples that we could add as
Also, is this list complete? This mostly reflects what we have documented as required constraints in this repo. We already check that only |
Also Cc @ecstatic-morse |
Not really, a frozen
We used to track whether a value refers to a
We could maybe promote any |
Yeah, and with more and more CTFE capabilities this will really not scale. |
Count me in for finding out a solution for |
@vertexclique awesome! This first needs a bunch of research I think, as right now I do not even have a good idea for what the (dynamic) property is that we want to ensure. It's something about " |
test the unleashed Miri In particular, test what happens when we try to drop something. Cc rust-lang/const-eval#17 r? @oli-obk
I thought a bit more about promoteds here and I don't think it makes much sense to have a dynamic version of "promotion analysis". Or rather, we would have to actually run that code both in Miri and through LLVM codegen and compare results, or so -- that would require a considerable amount of infrastructure, much more than the dynamic checks we otherwise added. This document otherwise describes the key concerns here pretty well. |
I just learned about another restriction that const-checking enforces that I had no idea about: accesses to thread-local statics are rejected. This makes a lot of sense (Cc rust-lang/rust#70685), but I am slightly worried that this was never added to the docs here, nor is there (I think) an unleash-miri test for this. Is there anything else we missed? Cc @ecstatic-morse I noticed the |
Oh looks like |
The reason is that @ecstatic-morse ported my |
There are some operations like inline assembly that will never be supported by MIRI. I suppose you might want Side note: we don't actually check for inline assembly since it wasn't in the old pass. It currently results in post-monomorphization errors. I fixed this in the PR that removed |
Ah and the new code is much easier to audit so now such issues are much more obvious. That's great. :)
Fully agreed.
Indeed I do. I think that everything check_const does should be just a static approximation for checks that Miri already does dynamically, and make sure we get errors pre-monomorphization (plus gating features that we still consider unstable). That gives them a clear specification, and -- if we work on making them more and more precise through better analysis (like dataflow) or using types more or so -- a clear "limit" to reach for.
Nice catch! So what is the list of such things that const_prop rejects that we do not yet have miri-unleash tests for? So far, I counted
|
Current status: two uses of that constant got removed in rust-lang/rust#71276 and rust-lang/rust#71149. The last remaining use is for TLS, and either rust-lang/rust#71192 or a follow-up PR should remove that. |
With rust-lang/rust#72893, the constant goes away. |
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
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:
drop
calls during initializer evaluation.Sync
? See Constants can contain references that are not Sync rust#49206.The problem with promotion is tracked separately at #53.
Cc @eddyb
The text was updated successfully, but these errors were encountered: