Uh oh!
There was an error while loading. Please reload this page.
Allow constants to refer statics - #66302
Conversation
Uh oh!
There was an error while loading. Please reload this page.
rust-highfive
commented
Nov 11, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Centril
commented
Nov 12, 2019
I'm not sure why we are doing this change. If we are to do so, I think an RFC would be in order. For the time being, we have an RFC that explicitly states that this should not be allowed. Also, do we have any test which forbids the following? extern{staticFOO:u8;}constX:u8 = unsafe{FOO}; |
723630e to
774445dComparespastorino
commented
Nov 12, 2019
@Centril I've just added the test you mentioned, good point ;). |
Centril
commented
Nov 12, 2019
Thanks! Since the main purpose of this work is to simplify compiler internals rather than as a new language feature, I would suggest moving the existing check to HIR. That shouldn't be too difficult I think -- could be its own pass or we could do it in typeck maybe. |
oli-obk
commented
Nov 12, 2019
We have? I was under the assumption this is just a restriction left over from the old const evaluator. The miri-based const eval can handle this without any problems. Which RFC are you referring to? |
oli-obk
commented
Nov 12, 2019
@Centril and I discussed this a bit via chat. Here's the summary:
cc @RalfJung |
bors
commented
Nov 14, 2019
☔ The latest upstream changes (presumably #66314) made this pull request unmergeable. Please resolve the merge conflicts. |
The crucial thing to make sure is that CTFE does not read from (let alone write do) mutable statics. We should make sure to have a few miri-unleash tests that cover this. Cnetril mentioned one, @oli-obk mentioned this one: constFOO:usize{staticFOO:AtomicUsize = AtomicUsize::new(0);FOO.fetch_add(1,Ordering::Relaxed)};and then there also is constFOO:usize{staticFOO:AtomicUsize = AtomicUsize::new(0);*(&FOOas*const_as*constusize)};and staticmutMUTABLE:u32 = 0;constBAD:u32 = unsafe{MUTABLE};All of these should fail even with miri-unleashed, to make sure that our dynamic checks are covering all possibilities. What remains then is the question of whether we want to have static checks on top of the dynamic ones, and what those are good for. Doing only dynamic checks leads to monomorphization-time errors. But from how I understood @oli-obk, we either already have those or ruling those out also rules out way too many useful things, and hence monomorphization-time errors are the better option? I do not have a strong stanza on this, if @oli-obk and @Centril agree on that that's good enough for me. I just want to see the Miri engine do enough checks to rule out all these examples. :) (And I think so far it does not do enough checks, actually.) |
JohnCSimon
commented
Nov 24, 2019
Ping from triage |
spastorino
commented
Nov 24, 2019
@JohnCSimon, I don't think it makes sense to rebase this until we don't figure out a way to make this idea work. |
Centril
commented
Dec 16, 2019
My stance is that should not be adding post-monomorphization errors and that |
oli-obk
commented
Dec 16, 2019
I'm currently unable to come up with a non-postmonomorphization plan that would not end up making const qualif more complex or require new marker traits Let's close until we have a plan for working this out |
RalfJung
commented
Dec 16, 2019
CTFE already causes post-monomorphization errors because some parts of CTFE can only happen after monomorphization and sometimes that can error (causing a panic during CTFE is the most obvious case). Not sure if I would consider "you read from a static" a * new* post-monomorphization error. |
oli-obk
commented
Dec 16, 2019
writing to mutable statics by first taking a reference and then writing through that reference is also only detected post monomorphization |
…t, r=RalfJung Ensure that evaluating or validating a constant never reads from a static r? @RalfJung as per rust-lang#66302 (comment) This does not yet address the fact that evaluation of a constant can read from a static (under unleash-miri)
r? @oli-obk, now @eddyb will be happy ❤️