Stream: t-compiler/wg-mir-opt

Topic: const prop breaking const rules


oli (Dec 16 2019 at 13:22, on Zulip):

Const prop can end up placing a pointer to a static into an anonymous (ByRef, created on the fly) constant:

oli (Dec 16 2019 at 13:22, on Zulip):
static XXX: &'static Foo = &Foo {
    tup: "hi",
    data: &[
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
        (0, 1), (0, 2), (0, 3),
    ]
};

#[derive(Debug)]
struct Foo {
    tup: &'static str,
    data: &'static [(u32, u32)]
}

fn main() {
    println!("{:?}", XXX);
}
oli (Dec 16 2019 at 13:23, on Zulip):

Should we try to prevent this (the MIR is not "valid" anymore (in some sense))

oli (Dec 16 2019 at 13:23, on Zulip):

or should we do the interning in immutable static mode?

oli (Dec 16 2019 at 13:24, on Zulip):

treating everything that const prop when creating new constants is working by static rules and not by const rules

Wesley Wiser (Dec 16 2019 at 13:39, on Zulip):

What are the static rules and the const rules?

oli (Dec 16 2019 at 13:45, on Zulip):

a const may not have a reference to a static (or even read from it)

oli (Dec 16 2019 at 13:46, on Zulip):

a const may not have references to things with interior mutability

Wesley Wiser (Dec 16 2019 at 15:29, on Zulip):

Seems like it should use the immutable static mode then. Any reason not to do that?

oli (Dec 16 2019 at 15:54, on Zulip):

Not really, I guess it just doesn't feel explicit enough

oli (Dec 16 2019 at 15:54, on Zulip):

Like maybe we should have a new enum for all the modes

oli (Dec 16 2019 at 15:54, on Zulip):

Even if some modes behave the same

Wesley Wiser (Dec 16 2019 at 15:56, on Zulip):

That may be a bit easier for someone who isn't completely familiar with the intern stuff to understand as well.

RalfJ (Dec 22 2019 at 19:50, on Zulip):

A more targeted const check (only disallow reading from mutable statics) would still behave correctly here, right?

oli (Dec 29 2019 at 00:34, on Zulip):

do you mean that even if we add a ConstProp mode to interning we still prevent reading from mutable statics during const prop?

RalfJ (Dec 30 2019 at 20:54, on Zulip):

I'm saying the relevant property is a dynamic one (what does the const code do during initializer computation) and not a static one (what does the final value look like). and the dynamic property is checked fine no matter what ConstProp does. right?

oli (Dec 30 2019 at 21:05, on Zulip):

Oh, yea, const prop's machine errors out on statics

Last update: Apr 05 2020 at 01:45UTC