Stream: t-compiler/const-eval

Topic: static access vs reborrow


ecstatic-morse (Nov 27 2019 at 21:34, on Zulip):

Hey @Matthew Jasper. Continuing from this comment, don't I want to check the LocalInfo for the local in &*_2 to see if it is a pointer to a static?

ecstatic-morse (Nov 27 2019 at 21:35, on Zulip):

There's no Constant involved in Rvalue::Ref to call check_static_ptr on

Matthew Jasper (Nov 27 2019 at 21:35, on Zulip):

Please don't do that except to change diagnostic messages (yes, there are cases where I have done that, but please don't add more).

Matthew Jasper (Nov 27 2019 at 21:37, on Zulip):

Is there a reason that this is different to

const X: () = {
    let x = &3;
    &mut *x;
};
ecstatic-morse (Nov 27 2019 at 21:38, on Zulip):

Well I understand that it's a hack, but is there an alternative? I suppose we could try to justify not const-checking references to a static at all. It's good that the static mut case is still getting const-checked, but I'm not actually sure why :smile:.

ecstatic-morse (Nov 27 2019 at 21:41, on Zulip):

If 3 was instead Cell::new(3) it would be different.

Matthew Jasper (Nov 27 2019 at 21:42, on Zulip):

I guess that you could move the is_mutating_use check up in visit_projection_elem in validation.rs

Matthew Jasper (Nov 27 2019 at 21:43, on Zulip):

It results in extras errors in quite a few tests though.

ecstatic-morse (Nov 27 2019 at 21:48, on Zulip):

Is there a reason that the type of the pointer to an AllocId for a static is a reference and not a const pointer?

ecstatic-morse (Nov 27 2019 at 21:49, on Zulip):

That's the reason we still const-check static muts. Accesses to them go through a *mut.

Matthew Jasper (Nov 27 2019 at 21:50, on Zulip):

It's a reference so that it can be safety checked correctly.

Matthew Jasper (Nov 27 2019 at 21:51, on Zulip):

(without special casing)

ecstatic-morse (Nov 27 2019 at 21:51, on Zulip):

I guess because access to a static mut must always be in unsafe, and we do unsafety checking on the MIR

ecstatic-morse (Nov 27 2019 at 21:54, on Zulip):

I think we need to replicate the code you added that checks for LocalInfo::StaticRef in visit_projection_elem in visit_rvalue since we discard the Deref projection for things that look like reborrows.

ecstatic-morse (Nov 27 2019 at 21:54, on Zulip):

To avoid changing behavior

Matthew Jasper (Nov 27 2019 at 21:54, on Zulip):

OK

ecstatic-morse (Nov 27 2019 at 21:55, on Zulip):

Once again, I understand you want this to go away in the long term, but not having it changes behavior now that we don't rely on HasInteriorMut.

ecstatic-morse (Nov 27 2019 at 21:56, on Zulip):

I'll have a talk with @WG-const-eval about whether we need to const-check accesses to statics at all, in which case we may be able to remove it.

Last update: Dec 12 2019 at 00:45UTC